Help a noob implement MATLAB for a math iteration

조회 수: 9 (최근 30일)
James
James 2013년 10월 8일
댓글: Jan 2013년 10월 13일
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
Duke
Duke 2013년 10월 11일
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.
Jan
Jan 2013년 10월 13일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

sixwwwwww
sixwwwwww 2013년 10월 10일
편집: sixwwwwww 2013년 10월 10일
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
Jan
Jan 2013년 10월 10일
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.
sixwwwwww
sixwwwwww 2013년 10월 10일
Thanks for improvement Jan Simon. Cheers

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile 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