필터 지우기
필터 지우기

Creating a function that solves the kepler equation

조회 수: 8 (최근 30일)
Sami
Sami 2014년 2월 16일
편집: James Tursa 2017년 8월 30일
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

답변 (1개)

James Tursa
James Tursa 2017년 8월 30일
편집: James Tursa 2017년 8월 30일
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.

카테고리

Help CenterFile Exchange에서 Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by