That defines a as being a symbolic function
That attempts to define the value of the function evaluated at b, but MATLAB does not permit you to define a general function and then assign values to the function at specific locations.
Below is the code rewritten in a way that is acceptable to MATLAB:
syms f(x) a(x)
f(x)=(cos(x)-(2*x)+3);
a(x)=(1/2)*(cos(x)+3);
da=diff(a,x);
b=pi/2.5;
s='a f(x)';
disp(s);
for i=(1:100)
if abs(vpa(da(b)))<1
if vpa(f(a(b)))~=0
a(x) = piecewise(x==b, vpa(a(b)), a(x));
f(x) = piecewise(x == b, vpa(f(b)), f(x));
A=[num2str(double(a(b))),' ',num2str(double(f(b)))];
disp(A);
a(x)= piecewise(x==b, vpa(a(a(b))), a(x));
i=i+1;
elseif vpa(f(b))==0
a(x)= piecewise(x==b, vpa(a(b)), a(x));
f(x) = piecewise(x == b, vpa(f(b)), f(x));
A=[num2str(doubble(a(b))),' ',num2str(double(f(b)))];
disp(A);
end
else
a(x) = piecewise(x==b, vpa(a(a(b))), a(x));
i=i+1;
end
end
I made no attempt at all to correct the algorithm: I just corrected the syntax to make it do exactly what you coded.
Best Answer