How do I solve Kepler's equation for E using fzero?

I am required to do an assignment in which I need to do just that and I can't figure it out. Equation is:
M=E-e*sin(E)
M, e, and E are all variables.
I need to use fzero to create a script that will solve it for E when I input M and e. It should look something like Kepler(1,2) in the command window for example. Any help would be great thanks alot

5 个评论

Is abs(e) greater than Pi/2 or less than Pi/2 ?
For e >= Pi/2, there are multiple solutions for E. For any given positive integer N, if P > (N+1/2)*Pi then there are at least N real-valued solutions for some values of E (there may be 1 or 2 fewer solutions for other values of E; the number of solutions will be periodic with E -- a larger E will just push the solutions further positive but they will still exist.)
@Walter: 0 <= e < 1
We don't know that, James. We are only told that e is a variable.
@Walter: It is true that OP did not tell you that, but I know that Kepler's equation is used for elliptical orbits. So I was just filling in a detail that OP did not mention.
https://en.wikipedia.org/wiki/Kepler%27s_equation

请先登录,再进行评论。

 采纳的回答

To use fzero, you first need to form an equation with 0 on one side. So this equation:
M = E - e * sin(E)
becomes this equation:
0 = E - e * sin(E) - M
Then set up your known values:
e = something
M = something
Then form a function handle for the equation that you want to be 0 as a function of what you want to solve for, which is E in this case:
kepler_equation = @(E) E - e * sin(E) - M
Then it is just a matter of calling fzero with this function handle and an initial guess. E.g., you could use M as the initial guess. I will leave that part for you to figure out. Look at the doc for fzero to see how to call it.
If you are creating a function that outputs E given e and M, then the outline of that function would be this in a file called Kepler.m:
% E = Kepler(e,M) solves Kepler's equation, E and M are in radians
function E = Kepler(e,M)
% form the function handle here <-- you insert this code
% call fzero here <-- you insert this code
return
end
The code you insert above will be based on the advice I gave you above.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by