How to evaluate a derivative of a function at a point?
141 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mike M
el 16 de Abr. de 2015
Editada: Mohammad Abouali
el 16 de Abr. de 2015
I was wondering if anyone can help. I am taking the derivative of cos(x)-x, and then using subs to evaluate it at a point, but instead of getting an answer it returns me this:
syms x
func = @(x) cos(x) - x
newfunc = (subs(diff(func,x,1),x,1))
newfunc =
- sin(1) - 1
I found an answer online of putting vpa() before subs, which makes it work, but I was wondering why subs isn't able to evaluate it. Thanks!
0 comentarios
Respuesta aceptada
Mohammad Abouali
el 16 de Abr. de 2015
Editada: Mohammad Abouali
el 16 de Abr. de 2015
because subs replaces x with one. Doesn't evaluate. So diff( cos(x) -x ) returns -sin(x) -1 and then you replace x with one and returns -sin(1) -1
syms x
func = @(x) cos(x) - x
newfunc = eval( (subs(diff(func,x,1),x,1)) )
newfunc =
-1.8414709848079
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!