how get second derivative of a function with one variable? I keep getting not enough input arguments?
4 次查看(过去 30 天)
显示 更早的评论

Can someone help with this error? it seems I did everything according to tutorials
I was asked to use MATLAB function to calculate second derivative. I created the function but I cannot export the secnd derivative from it. i also tried to give it some value and it works fine. Just diff() does not work
0 个评论
回答(1 个)
Stephen23
2023-2-23
编辑:Stephen23
2023-2-23
"it seems I did everything according to tutorials"
Sort of: you defined a function that works on numeric data, but then you have attempted to use this with symbolic differentiation (i.e. DIFF from the symbolic toolbox). That will not work. If you want to perform symbolic differentiation, then you will need to define a symbolic formula. See the examples here:
syms t
f = exp(5*t) + t^2
d = diff(f,t) % default = 1st derivative
d = diff(f,t,2) % 2nd derivative
6 个评论
Walter Roberson
2023-2-23
syms t
d2f = diff(f, t, t)
function [y] = f(t)
y= exp(5*t) + t^2
end
Walter Roberson
2023-2-23
What those tell you is that you cannot use diff to find the derivative of a MATLAB function -- not unless you pass a symbolic variable into the function so that diff() is operating on a symbolic expression.
You can use diff() to find the derivative of an anonymous function or of a symbolic function
syms t
f1 = @(t) exp(5*t) + t^2
diff(f1, t, t)
f2(t) = exp(5*t) + t^2
diff(f2, t, t)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!