I am solving an equation symbolically:
% Newton's method
syms x;
F(x)=x-cos(x);
FPrime(x)=diff(F(x));
display(FPrime(x));
x0=input('please give first point[x0] = ');
Accuracy=input('Accuracy[xn-xn-1] = ');
for k=0:15;
    x=x0-(F(x0)/FPrime(x0));
    x0=x;
    if(abs(F(x))<=Accuracy);
        display(x);
        break
    end    
end
I need x in as a real number but the answer comes out as (cos(1) - 1)/(sin(1) + 1) + 1. What do I need to do with this if I want a number?
                        
Casting your output to
doublewill produce to result you want:The above was tested on R2016b. If for some reason this doesn't work, there's the fallback of
eval(), which produces the same result asdouble()(in this case).Note that
evalcan have various side effects (see example) and should be used in extremely rare cases.