1
第二章 MATLAB 求导 当求导的函数比较复杂,或者是求高阶导数时,计算量是很大的。此时可以 MATLAB diff 命令来求导数。 2.5.1 sin x y x = 的导数。 syms x diff(x^sin(x)) ans= x^sin(x)*(cos(x)*log(x)+sin(x)/x) 可以用 pretty 命令来整理一下显示结果,使之更符合一般的书写格式 pretty(ans) sin sin [cos( )log( ) ] x x x x x x + 2.5.2 ax y e = 的高阶导数。 syms a x diff(exp(a*x),x,3) ans= a^3*exp(a*x) diff(exp(a*x),x,30) ans= a^30*exp(a*x) 3 (30) 30 , ax ax y ae y ae ′′′ = = 例 2.5.3 函数 y 由参数方程 2 1 arctan x t y t = + = ,确定,求 dy dx syms t x=sqrt(1+t 2); y=atan(t) pretty(diffy)/deff(x)) 2 1/2 1 (1 ) t t + 即得 dy dx 2 1 1 t t +

02.第二章用Matlab求导

Embed Size (px)

Citation preview

Page 1: 02.第二章用Matlab求导

第二章 用 MATLAB 求导当求导的函数比较复杂,或者是求高阶导数时,计算量是很大的。此时可以

用 MATLAB 的 diff 命令来求导数。

例 2.5.1 求sin xy x= 的导数。

解 syms x ↙diff(x^sin(x)) ↙

ans= x^sin(x)*(cos(x)*log(x)+sin(x)/x)可以用 pretty 命令来整理一下显示结果,使之更符合一般的书写格式

pretty(ans) ↙

sin sin[cos( ) log( ) ]x x

x x xx

+

例 2.5.2 求axy e= 的高阶导数。

解 syms a x ↙ diff(exp(a*x),x,3) ↙ ans=

a^3*exp(a*x)

diff(exp(a*x),x,30) ↙ ans= a^30*exp(a*x)

即3 (30) 30,ax axy a e y a e′′′ = = 。

例2.5.3函数y由参数方程21

arctan

x t

y t

= +

=,确定,求

dy

dx。

解 syms t ↙

x=sqrt(1+t ∧ 2); ↙

y=atan(t) ↙

pretty(diffy)/deff(x)) ↙

2 1/ 2

1

(1 )t t+

即得dy

dx= 2

1

1t t+