why isn't my newton rhapson method giving me a quadratic conversion rate?
1 view (last 30 days)
Show older comments
The code is running just fine, but the value konv(end)/(konv(end-1)^2) intended to show (e(i+1)/(e(i)^2)) gives an answer of 9.9952e+07, which seems to indicate that the conversion rate isn't quadratic. Is there something obviously wrong with the code? Help appreciated.
%constants
d=0.007;
dI=1.219;
Rfi=1.76*(10^(-4));
Rf0=Rfi;
hs=356;
ht=hs;
kw=60;
dTm=29.6;
Q=801368;
Aex=64.15;
a=((1/ht)+Rfi)/dI;
b=log(d/dI)/(2*kw);
c=d*(a+b)+Rf0+(1/hs);
A=((1/ht)+Rfi)/dI;
B=(log(d/dI)+1)/2*kw;
f=c*(Q/dTm)-Aex;
df=(Q/dTm)*(A+B);
%d1-do ska va mindre än tol
%i slutet av iterationen
%så man kan sätta while
d=0.007;
d0=d;
d1=10;
abs(d1-d0);
iteration=0;
konv=[0]
while abs(d1-d0)>10^(-8);
a=((1/ht)+Rfi)/dI;
b=log(d/dI)/(2*kw);
c=d*(a+b)+Rf0+(1/hs);
f=c*(Q/dTm)-Aex;
A=((1/ht)+Rfi)/dI;
B=(log(d/dI)+1)/2*kw;
df=(Q/dTm)*(A+B);
d0=d;
d1=d-f/df;
d=d1;
iteration=iteration+1;
konv=[konv, abs(d1-d0)];
end
konv(end)/(konv(end-1)^2)
iteration
d
0 Comments
Answers (1)
Torsten
on 19 Nov 2023
Edited: Torsten
on 19 Nov 2023
If
b=log(d/dI)/(2*kw);
instead of
b=log(d/dI)/2*kw;
as was first written in your previous code, then B must also be
B=(log(d/dI)+1)/(2*kw);
instead of
B=(log(d/dI)+1)/2*kw;
In other words: df is wrong because B is wrong.
6 Comments
Torsten
on 21 Nov 2023
Edited: Torsten
on 23 Nov 2023
Replace
%B=(log(d/dI)+1)/2*kw;
by
%B=(log(d/dI)+1)/(2*kw);
in the above code you posted. Nothing else is necessary.
%constants
d=0.007;
dI=1.219;
Rfi=1.76*(10^(-4));
Rf0=Rfi;
hs=356;
ht=hs;
kw=60;
dTm=29.6;
Q=801368;
Aex=64.15;
a=((1/ht)+Rfi)/dI;
b=log(d/dI)/(2*kw);
c=d*(a+b)+Rf0+(1/hs);
A=((1/ht)+Rfi)/dI;
B=(log(d/dI)+1)/2*kw;
f=c*(Q/dTm)-Aex;
df=(Q/dTm)*(A+B);
%d1-do ska va mindre än tol
%i slutet av iterationen
%så man kan sätta while
d=0.007;
d0=d;
d1=10;
abs(d1-d0);
iteration=0;
konv=[];
while abs(d1-d0)>10^(-10);
a=((1/ht)+Rfi)/dI;
b=log(d/dI)/(2*kw);
c=d*(a+b)+Rf0+(1/hs);
f=c*(Q/dTm)-Aex;
A=((1/ht)+Rfi)/dI;
B=(log(d/dI)+1)/(2*kw);
df=(Q/dTm)*(A+B);
d0=d;
d1=d-f/df;
d=d1;
iteration=iteration+1;
konv=[konv, abs(d1-d0)];
end
for i = 2:numel(konv)
konv(i)/konv(i-1)^2
end
iteration
d
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!