Using a while loop/iterative process to derive a function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to use Kepler's equation to derive a f where f is a function of E. Here is the problem statement. ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/209522/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/209522/image.png)
My code does not seem to spit out the right answer. I don't believe I'm really deriving the function. Here is my code:
clc;
close all;
clear;
format long e
% Problem 1
nt = 1.047197551 %equal to pi/3 in radians
ep = 0.3
Ei = 0;
iteration_count = 0;
Mi = inf;
while abs(1.047197551-Mi) >= 1e-7
Mi = Ei-0.3*sin(Ei);
Ei = Ei+(1.047197551-Mi)/(1-0.3*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)
0 commentaires
Réponses (1)
Krishna Kumar
le 21 Mar 2019
The code yields final value of Ei, and you are essentially using Newton's method to solve the eqn. Do you want the code to print del_E rather? or do you find an error in final value of Ei. Probably you can double check the answer with nonlinear solvers like fsolve in matlab.
0 commentaires
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!