Unrecognized function or variable 'FalsePosition'.
Afficher commentaires plus anciens
V=40;
rho=1.23;
D=0.005;
mu=1.79E-5;
epsilon=0.0015E-3;
Re=rho*V*D/mu;
f=@(x)(1./sqrt(x)+2*log10(epsilon./(3.7*D)+2.51./(Re*sqrt(x))));
xplot=0.008:0.001:0.08;
plot(xplot,f(xplot))
xlabel("f")
ylabel('y(f)')
grid on
a=0.008;
b=0.08;
tol=0.0001;
disp('iterNo lowerB upperB f(a) f(b) approxRoot f(r) error ')
fstats=FalsePosition(f,a,b,tol);
disp(fstats)
norows=size(fstats,1);
nocols=size(fstats,2);
froot=fstats(norows,nocols-2);
fprintf("Root by false position method =%f\n",froot);
function stats=FalsePosition(f,a,b,tol);
i=1;
iterNo=[i];
lowerB=[a];
upperB=[b];
functValueL=[f(a)];
functValueU=[f(b)];
approxRoot=[];
functValueR=[];
error=[];
if f(a)*f(b)>0
disp('The value of f(a)*f(b)<0,choose other values of a and b')
else
xn=f(b);
xn_1=f(a);
r=b-(xn*(b-a))/(xn-xn_1);
err=abs(f(r));
approxRoot(i)=r;
functValueR(i)=f(r);
error(i)=err;
while err >tol
i=i+1;
iterNo(i)=i;
if xn_1*f(r)<0
b=r;
else
a=r;
end
r=b-(xn*(b-a))/(xn-xn_1);
err=abs(f(r));
upperB(i)=b;
lowerB(i)=a;
functValueU(i)=f(b);
functValueL(i)=f(a);
approxRoot(i)=r;
functValueR(i)=f(r);
error(i)=err;
end
end
stats=[iterNo;lowerB;upperB;functValueL;functValueU;approxRoot;functValueR]
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Electrical Block Libraries dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
