Azzera filtri
Azzera filtri

Creating a function that solves the kepler equation

8 visualizzazioni (ultimi 30 giorni)
Sami
Sami il 16 Feb 2014
Modificato: James Tursa il 30 Ago 2017
So the equation: " 0=E-e*sin[E]-M"
For this assignment, I need to create a function called kepler which solves the kepler equation for E given e and M (your function should accept M and e as inputs, and return E). THe actual solution should be performed using the function fzero().
Validate the code works using M= pi/4 and e.25. Put this into the equation and show that the left hand side goes to zero.
So can someone explain how I can do this in really simple terms.
this is how im starting:
function [E, z] = kepler (e,m)
E-e*sin(E)-M
end
I really dont know how to start

Risposte (1)

James Tursa
James Tursa il 30 Ago 2017
Modificato: James Tursa il 30 Ago 2017
Your kepler function should output E given the values of e and M. So it should look like this in a file called kepler.m
function E = kepler (e,M)
% insert code here
end
The "insert code" part is where the fzero stuff goes. According the the instructions, you first have this equation:
0=E-e*sin[E]-M
Given the values of e and M, you are supposed to use fzero to solve for E. So first create a function handle out of that equation that you want to be zero given the values of e and M:
kepler_equation = @(E) E - e * sin(E) - M
You simply pass that function handle to fzero with some initial guess. E.g., you could use M as the initial guess. Just be sure that M is in radians, and note that the output E will be in radians as well. Look at the doc for fzero to see how to call it. It will look like this:
E = fzero( something ); % <-- You need to fill in the something
So there is only two lines needed in your kepler function body, a line that builds the function handle and a line that calls fzero.

Categorie

Scopri di più su Optimization in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by