Newton-Raphson Method
이전 댓글 표시
I have the following Newton-Raphson method code.
Code.
I am attempting to call it using the following
Input.
I am receiving the following error
Error.
Can someone please help me with this? I know the number of iterations and friction factor, but I am expected to turn the loop I did into a function like this and it should work but there is something a little wrong.
댓글 수: 3
Tony Rankin
2021년 3월 15일
편집: Tony Rankin
2021년 3월 15일
Cris LaPierre
2021년 3월 15일
@Tony Rankin, removing the substance of your question once it has been answered is not the point of the forum. The questions and answers are preserved to provide help to others down the road who have a similar question. Could you be kind enough to restore the details of your question?
Cris LaPierre
2021년 3월 16일
Original context restored below from the cache.
I have the following Newton-Raphson method code.
function [R] = newton(f,df,x0,tol)
% R is an estimation of the root of f using the Newton-Raphson method
% f is colebrook equation for turbulent flow
% df is the first derivative of the colebrook equation
% x0 is the initial estimate for the root
% tol is the accepted tolerance
if abs(f(x0)) < tol
R = x0; % end loop, takes x0 as root of f
else
R = newton(f,df,x0-(f(x0)/df(x0)),tol); % make a recursive call
end
error = abs(f(x0)) % calculate the absolute error
end
I am attempting to call it using the following
error = 1;
p = 0.9*1000;
mu = 8*0.001;
e = 0;
D = 4*0.0254;
Q = (2000*42*3.785*10^-3)/(24*60*60);
A = (pi*(D.^2))/4;
Re = (p*D*Q)/(A*mu);
f = @(x) -1/sqrt(x)-2.*log10(((e./D)./3.7)+2.51/(Re*sqrt(x)));
df = @(x) -1/2*(x).^3/2*(1+((2*2.51)/log10(e./D)./3.7)+(2.51/(Re*sqrt(x)*Re)));
R = newton(f,df,0.01,1e-9)
I am receiving the following error
Out of memory. The likely cause is an infinite recursion within the program.
Error in newton (line 27)
if abs(f(x0)) < tol
Can someone please help me with this? I know the number of iterations and friction factor, but I am expected to turn the loop I did into a function like this and it should work but there is something a little wrong.
Colebrook equation

This is meant to be the derivative of the Colebrook equation. I hope I had input it correctly.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!