Help a noob implement MATLAB for a math iteration

Alright guys I'm new to Matlab and have no idea how to use it. I've read the manual but I still don't understand. I need to implement Kepler's problem iteration.
equation 1: 0.69=E-0.82sinE where E is in radians. A random E will be plugged in by the user, and the MATLAB program has to iterate until 0.69 is achieved.
There's a formula for the E iteration values.
equation 2: E(i+1)=Ei+(0.69-Mi)/(1-0.82cosEi) This reads the E subscript i+1 value equals the E subscript i value ......etc. The Mi is equivalent to equation 1, where M=0.69. So Mi would just be what Ei plugged during the iteration.
Example: I choose Ei=0.5 and plug it into my iterative MATLAB function. Then equation 1 becomes M=0.5-0.82sin0.5. Hence Mi=0.10687. Then solve equation 2 for E(i+1). Get E(i+1)=2.5796. Then this becomes the next E value, and the process repeats itself UNTIL 0.69-Mi goes near to 0. I need a convergence tolerance of 10^-7, whatever that means.
I apologize for my poor explanation of the math problem. Fortunately the textbook is online: http://www.fgg.uni-lj.si/~/mkuhar/Zalozba/Fundamentals_of_Astrodynamics-Bate_Mueller&White-1971.pdf
Go to pages 220-222 (the book pages) section 4.6.4. Equation 1 is 4.2-6, and equation 2 is 4.6-40.
Do I use a if function?
Thanks.

3 个评论

I've read the manual but I still don't understand.
Really? Not one word of it?
One of the big things that’s wrong with this forum is being think they are above everyone else because they know a broken tool better than other people (The amount of down time MatLab caused me when it crashed is astronomical). I found Matt reply as him being a jerk and belittling the poster. There are a few other people that are sarcastic all the time as well. I have no idea what the poster said, but after the comment Matt left I'd be upset as well.
Sorry, Duke. I've removed by contributions to this discussion, because I assume, it is not of public interest. Unfortunately this steals the context of your comment.
I suggest not to take the messages of others personally in a forum.

请先登录,再进行评论。

 采纳的回答

Dear James here is the code according to your problem description:
Ei = input('Enter initial value E[rad]: ');
diff = 1;
iteration_count = 0;
while diff >= 1e-7
Mi = Ei - 0.82 * sin(Ei);
diff = abs(0.69 - Mi);
E_next = Ei + (0.69 - Mi) / (1 - 0.82 * cos (Ei));
Ei = E_next;
iteration_count = iteration_count + 1;
end
disp(strcat('Number of iterations: ', num2str(iteration_count)))
disp(strcat('Final value of Mi:', num2str(Mi)))
disp(strcat('Final value of Ei:', num2str(Ei)))

3 个评论

Or slightly simplified:
Ei = input('Enter initial value E[rad]: ');
iteration_count = 0;
Mi = Inf;
while abs(0.69 - Mi) >= 1e-7
Mi = Ei - 0.82 * sin(Ei);
Ei = Ei + (0.69 - Mi) / (1 - 0.82 * cos (Ei));
iteration_count = iteration_count + 1;
end
fprintf('Number of iterations: %d\n', iteration_count)
fprintf('Final value of Mi: %g\n', Mi)
fprintf('Final value of Ei: %g\n', Ei)
I did not check the algorithm.
Thanks for improvement Jan Simon. Cheers

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by