Why are the computation times for a single iteration and n iterations in a while loop almost the same?
1 view (last 30 days)
Show older comments
I am solving a system of non-linear equations using Newton Raphson method. The cputime required to solve the problem with (maximum number of iterations) maxiter = 1 or 5 is almost the same. Why are the computation times for a single iteration and n iterations in a while loop almost the same?
clc;
clear all;
format long g;
R = 0.083144621;
tc = 469.7;
pc = 33.69;
w = 0.249;
b = ((0.07780*R*tc)/pc);
p = (1+(2^0.5));
q = (1-(2^0.5));
s = (1/(2^1.5));
Tinit = 200 ;
Tfinal = tc;
h = 2;
x1 = 1/7417;
x2 = 1/0.1004;
x1d=x1*b;
x2d=x2*b;
tol = 0.000000001;
i= 0 ;
maxiter = 5;
for Tinit= Tinit:h:Tfinal
error1 = 100;
error2 = 100;
iter = 0;
tic
t=cputime;
while abs(error1)>tol && abs(error2)>tol && iter<maxiter
Pl = ...;
Pv = ...;
mul = ...;
muv = ...;
A = ....;
C = ....;
E = ....;
G = ....;
F = [Pv-Pl;
muv-mul];
J = [-C G
-A E];
dx = linsolve(J,(-F));
x1d = x1d+dx(1);
x2d = x2d+dx(2);
error1 = dx(1);
error2 = dx(2);
iter = iter+1;
end
qq = cputime-t
toc
end
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!