I'm having a problem with a user defined function I am constructing here. What I'm trying to do is to substitute a value into a symbolic function and then use that numerical answer for various purposes. Specifically here:
x = xo;
subst = subs(f,x);
while((n>i) && (subst > eps))
Running my program, I get the following error:
>> sym_newtonRaphson(f,fdiff,1,1e-8,10)
Conversion to logical from sym is not possible.
Error in sym_newtonRaphson (line 8)
I've tried using double(subs(f,x))
to no avail. I seem to be getting a totally different error relating to MuPAD (DOUBLE cannot convert the input expression into a double array.
)
The following is the whole program:
function [output] = sym_newtonRaphson(f,fdiff,xo,eps,n)
i = 0;
%initial iteration
x = xo;
subst = subs(f,x);
while((n>i) && (subst > eps))
x = x - (subs(f,x))/fdiff;
i = i+1;
subst = subs(f,x);
%fprintf('%f\t%f\t%f\t%f\t%f\t%f',i,alpha,f(
end
output = x;
end
I'd appreciate some pointers as to what I'm doing wrong; all the best.