How to set up the condition if the accuracy for e should be of 10^-14?

I have one for loop and want to calculate until the difference between reaches upto 10^-14. So should i set up the loop for that .
e = sqrt(1-(1-f^2));
e_bar = e/(sqrt(1-e^2)) ;
I need set such that it should be less.
Can any one help me to set up the condition for iterative way?
thank you

7 Comments

difference between what and what? Where is iteration?
I dont have any particular number of iteration but keep iterate until we will get no changing vaule of e for first 14 digits of e.
difference of e with in itself.
same for e_bar
a=6378137; %semi-major axis of reference ellipsoid(units are in meter)
J2 = 108263e-8; %non-normalised zonal spherical coecient(unit less)
GM =3986005e8; %gravity constant G times Mass M (m^3/s^2)
omega = 7292115e-11; %angular velocity (rad/sec)
f= 1/298 ; % approx flattening
%% first and second numeric eccentricity e and e0 with an accuracy of 10^-14
n=100000;
for i=1:n
e = sqrt(1-(1-f^2));
e_bar = e/(sqrt(1-e^2)) ; %eq 3
i=i+1
end
What is the use of iterator here? The same calculation gets done for n times....there is no changed in e and e_bar value.
it makes no sense to give an accuracy between different things. 10^-14 should be the difference between e(i+1) and e(i) and e‘(i+1) and e‘(i) between 2 iterations. You should reach that after 10 iterations.
I got above response from my coordinator, so hope you understood . What they want from me?
No I didn't get.....what exactly is your problem? What you are trying to achieve? It lookslike you are trying for Newton Rphson method....but the problem is not clear ot me.
I want to iterate nearly 10 to 20 times until the accuray reach to 10e-14. so the value for the e should be differ. We have 2 e values.
e and e_bar. The results after iteration will be in attache pic.

Sign in to comment.

Answers (1)

Assuming you want to loop until the accuracy e is of the order 10^-14 you can do the same for e_bar also:
a=6378137; %semi-major axis of reference ellipsoid(units are in meter)
J2 = 108263e-8; %non-normalised zonal spherical coecient(unit less)
GM =3986005e8; %gravity constant G times Mass M (m^3/s^2)
omega = 7292115e-11; %angular velocity (rad/sec)
f= 1/298 ; % approx flattening
%% first and second numeric eccentricity e and e0 with an accuracy of 10^-14
n=100000;
% keep a variable prev_e
prev_e=0;
for i=1:n
e = sqrt(1-(1-f^2));
e_bar = e/(sqrt(1-e^2)) ; %eq 3
if i==1
i=i+1;
continue;
end
i=i+1
if abs(e-prev_e)<=10^-14
break;
end
prev_e=e
end

1 Comment

It is not working as the value for e should be e=0.0818191910431508
e_new = 0.082094438152352.
I dont know to work on it.

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 19 Jun 2020

Community Treasure Hunt

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

Start Hunting!