Borrar filtros
Borrar filtros

Creating a function that solves the kepler equation

8 visualizaciones (últimos 30 días)
Sami
Sami el 16 de Feb. de 2014
Editada: James Tursa el 30 de Ag. de 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

Respuestas (1)

James Tursa
James Tursa el 30 de Ag. de 2017
Editada: James Tursa el 30 de Ag. de 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.

Categorías

Más información sobre Optimization en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by