How do I solve Kepler's equation for E using fzero?
10 views (last 30 days)
Show older comments
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 Comments
James Tursa
on 30 Aug 2017
Edited: James Tursa
on 30 Aug 2017
@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
Accepted Answer
James Tursa
on 30 Aug 2017
Edited: James Tursa
on 30 Aug 2017
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 Comments
More Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!