Reputation: 67
At University we use Matlab for numerical analysis and we studied some methods to find root, in newton's method we calculate derivative of a function but i wanted Matlab to do it for me, but when i take derivative, the function turns into (sym) and when i then pass values to it it says that it's dangerous to pass floating values, is there any way to convert it back to normal anonymous function? because that solves my problem :D
syms x
f=@(x) x^2
df=diff(f(x),x)
f(1.2) #this is ok
df(1.2) #not allowed
I googled this alot but i only found how to convert the other way
Upvotes: 1
Views: 631
Reputation: 3677
Simple, use 'matlabFunction':
syms x
f=@(x) x^2
df_=diff(f(x),x);
df=matlabFunction(df_);
df(1.2)
Upvotes: 3