Help a noob implement MATLAB for a math iteration
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Duke
il 11 Ott 2013
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
il 13 Ott 2013
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.
Risposta accettata
sixwwwwww
il 10 Ott 2013
Modificato: sixwwwwww
il 10 Ott 2013
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 Commenti
Jan
il 10 Ott 2013
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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements 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!