error with my symbolic objects and fprintf

1 view (last 30 days)
doliph
doliph on 10 Sep 2013
Commented: Qutyba Shteyat on 31 May 2021
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

Answers (1)

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

Categories

Find more on Function Creation 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!