diff
Differentiate symbolic expression
求符號表達式的微分
Syntax
diff(expr)
diff(expr, v)
diff(expr, sym('v'))
diff(expr, n)
diff(expr, v, n)
diff(expr, n, v)
Description
diff(expr) differentiates a symbolic expression
expr with respect to its free variable as determined by
symvar.
diff(expr, v) and
diff(expr, sym('v')) differentiate
expr with respect to
v.
diff(expr, n) differentiates
expr
n times.
n is a positive integer.
diff(expr, v, n) and
diff(expr, n, v) differentiate
expr with respect to
v
n times.
diff(expr) 求一個符號表達式
expr相對於由symvar肯定的自由變量的微分。
Examples
Differentiate the following single-variable expression one time:
The result is
ans =
2*x*cos(x^2)
Differentiate the following single-variable expression six times:
The result is
ans =
720
Differentiate the following expression with respect to
t:
syms x t;
diff(sin(x*t^2), t)
The result is
ans =
2*t*x*cos(t^2*x)
綜合應用
給定函數f(x)=cosx/(x
3+7x+2)的一階導數,並將每一個點上的值與原函數的值經過matlab函數繪製出來.
-
一階導數
syms x;
f=cos(x)/(x^3+7*x+2);
f1d=diff(f,x)
pretty(f1d)
-
繪製原函數以及求導後函數曲線
x1=0:0.001:5;
y=subs(f,x,x1);
y1d=subs(f1d,x,x1);
plot(x1,y,x1,y1d,':')