error with my symbolic objects and fprintf

3 次查看(过去 30 天)
I am quite inexperienced with matlab, I am getting this error when I run:
Error using fprintf
Function is not defined for 'sym' inputs.
Error in colebrook (line 22)
fprintf('%3i %12.8s %12.8s %12.8s\n',count, x, dx, f)
function colebrook (f,Re,e)
syms e Re x;
df = diff(1/sqrt(x)+2*log(e/3.7+2.51/(Re*sqrt(x))),x);
Tol = .001;
x=.02;
count = 0;
dx = 1;
fprintf('step x dx f(x)\n')
fprintf('---- ----------- --------- ----------\n')
fprintf('%3i %12.8f %12.8f %12.8f\n',count, x, dx, f)
xVec=x;fVec=f;%eVec=e;ReVec=Re;
while (dx > Tol || abs(f)>Tol)
count = count + 1;
xnew = x - (f/df);
dx=abs(x-xnew);
x = xnew;
f = (1/sqrt(x)+2*log(e/3.7+2.51/(Re*sqrt(x))));
fprintf('here');
e = char (e);
Re = char (Re);
x = char (x);
fprintf('%3i %12.8s %12.8s %12.8s\n',count, x, dx, f)
end

回答(1 个)

Walter Roberson
Walter Roberson 2013-9-10
xnew = x - double(f(x)/df(x));

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by