1 view (last 30 days)

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

Ajit Kasturi
on 19 Jun 2020

Edited: Ajit Kasturi
on 19 Jun 2020

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

Opportunities for recent engineering grads.

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

Start Hunting!
## 7 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905140

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905140

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905149

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905149

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905155

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905155

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905164

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905164

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905170

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905170

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905182

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_905182

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_910057

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/551257-how-to-set-up-the-condition-if-the-accuracy-for-e-should-be-of-10-14#comment_910057

Sign in to comment.