function calling in a script

3 ビュー (過去 30 日間)
Zivile Dailidonyte
Zivile Dailidonyte 2018 年 11 月 11 日
コメント済み: madhan ravi 2018 年 11 月 11 日
To solve for friction factor I have a function file to solve colebrook equation, function file to solve derivative of colebrook equation, function file to solve newton raphson using colebrook and its derivative and finally I have a script file where I need to calculate friction factors when the flow is laminar (this part is easy) and when the flow is turbulent where I need to call the newton raphson function and display its answer. This is the part where I'm confused and can't work out. Help please.
function [fd,no]=newton(Cfd,CfD,x,tol,mit) %mit-maximum iterations, tol-tolerance
for no=1:mit
fd=x-Cfd(x)/CfD(x);
err=abs(fd-x);
x=fd;
y=Cfd(x);
if (err<tol)|(relerr<tol)
break
end
end
D=1;
U=1;
rho=1000;
mu=0.0010518;
e=0.003;
Re=rho*U*D/mu;
if Re<2040
fd=64/Re;
else
%how to call the newton raphson function and display its answer???
end

回答 (1 件)

madhan ravi
madhan ravi 2018 年 11 月 11 日
[fd,no]=newton(Cfd,CfD,x,tol,mit) %function call
  2 件のコメント
Zivile Dailidonyte
Zivile Dailidonyte 2018 年 11 月 11 日
Thank you for your reply. When I do that I get an error that 'fd' is undefined. See my function file for newton raphson below
function [fd,no]=newton(Cfd,CfD,x,tol,mit) %mit-maximum iterations, tol-tolerance
m=0;
fd=x;
xold=x;
while fd==xold
m=m+1;
Cfd=colebrook(fd,Re,e,D);
CfD=colebrook_deriv(fd,Re,e,D);
fd=xold-Cfd/CfD;
error=abs(fd-xold);
fprintf('%m \t %.3f \t %.3f \t 5.3f \t\t %.3f \n', m-1, Cfd, CfD, fd, xold, error);
xold=x;
if error<tol
break
end
end
disp(['Root = ' num2str(fd) ' found in ' num2str(m) ' iterations'])
disp(['with tolerance of ' num2str(tol)])

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNewton-Raphson Method についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by