1.1 diff求导
1.1.1 单变量函数求导
MATLAB代码:
clc;clear;
syms x
f(x) =sin(x^2);
df = diff(f,x)
运行结果:
df(x) =
2*x*cos(x^2)
1.1.2 多变量函数指定变量求导
MATLAB代码:
clc;clear;
syms x t
diff(sin(x*t^2),t)
运行结果:
ans =
2*t*x*cos(t^2*x)
1.1.3 单变量函数高阶求导
MATLAB代码:
clc;clear;
syms t
d4 = diff(t^6,4)
运行结果:
d4 =
360*t^2
1.1.4 多变量函数指定变量高阶求导
MATLAB代码:
clc;clear;
syms x y
diff(x*cos(x*y), y, 2)
运行结果:
ans =
-x^3*cos(x*y)
1.1.5 多变量函数指定多变量依次求导
案例一:
MATLAB代码:
clc;clear;
syms x y
diff(x*sin(x*y), x, y)
运行结果:
ans =
2*x*cos(x*y) - x^2*y*sin(x*y)
案例二:
MATLAB代码:
clc;clear;
syms x y
diff(x*sin(x*y), x,x,x, y)
运行结果:
ans =
x^2*y^3*sin(x*y) - 6*x*y^2*cos(x*y) - 6*y*sin(x*y)
1.2 泛函数求导
MATLAB代码:
clc;clear;
syms y(x)
f =y*sin(y);
D= functionalDerivative(f,y)
运行结果:
D(x) =
sin(y(x)) + cos(y(x))*y(x)
1.3 微分形式
微分通过字符串拼接与求导结合实现。
MATLAB代码:
clc;clear;
syms x
y1=sin(3*x+2);
y2=log(exp(3*x)+2);
y3=exp(3*x)*cos(x);
dy1=[char(diff(y1,x)),\'dx\']
dy2=[char(diff(y2,x)),\'dx\']
dy3=[char(diff(y3,x)),\'dx\']
运行结果:
dy1 =
3*cos(3*x + 2)dx
dy2 =
(3*exp(3*x))/(exp(3*x) + 2)dx
dy3 =
3*exp(3*x)*cos(x) - exp(3*x)*sin(x)dx
1.4 补充:泰勒taylor级数
MATLAB代码:
clc;clear;
syms x
taylor(exp(x))
taylor(sin(x))
taylor(cos(x))
运行结果:
ans =
x^5/120 + x^4/24 + x^3/6 + x^2/2 + x + 1
ans =
x^5/120 - x^3/6 + x
ans =
x^4/24 - x^2/2 + 1