matlab教程--matlab快速入门-文字版, matlab电子书, 和matlab 有关的电子书:

4.3.1 代数方程

4.3.1 代数方程

求方程f(x)=q(x)的根可以用MATLAB命令:

>> x=solve('方程f(x)=q(x)',’待求符号变量x’)

求方程组fi(x1,…,xn)=qi(x1,…,xn)  (i=1,2,…,n)的根可以用MATLAB命令:

>>E1=sym('方程f1(x1,…,xn)=q1(x1,…,xn)');

…………………………………………………….

En=sym('方程f1n(x1,…,xn)=qn(x1,…,xn)');

[x1,x2,…,xn]=solve(E1,E2,…,En, x1,…,xn)

 

[例1]  解方程.

解  在MATLAB命令窗口输入命令:

 >> x=solve('8*x^9+17*x^3-3*x=-1')

则运行后输出此方程的根为

x=

[    -.95778266908844934303923445046258-.59070709534579563538068568150441*i]

[    -.95778266908844934303923445046258+.59070709534579563538068568150441*i]

[                                        -.53275697173102083274354955617700]

[ -.62165529622636773563391338820961e-2-1.1576656136411973167991239807601*i]

[ -.62165529622636773563391338820961e-2+1.1576656136411973167991239807601*i]

[     .26762926822201693804563287259316-.19580612317589362415618068133297*i]

[     .26762926822201693804563287259316+.19580612317589362415618068133297*i]

[     .96274843969420649872171548984002-.57475793354361098651731421962321*i]

[     .96274843969420649872171548984002+.57475793354361098651731421962321*i]

 

[例2]  解下列方程,并且求根的近似值,要求精度为.

(1);  (2)

(3).

解  只需在MATLAB工作窗口输入命令:

>> x1=solve('sin(cos(2*x^3))=0','x')

a1=solve('sin(cos(4))*a+tan(a+3)*5=0','a')

x2=solve('sin(cos(x))*a+tan(a)*b=0','x')

则运行后输出三个方程的根如下:

x1 =

[                                 1/2*2^(1/3)*pi^(1/3)]

[ -1/4*2^(1/3)*pi^(1/3)+1/4*i*3^(1/2)*2^(1/3)*pi^(1/3)]

[ -1/4*2^(1/3)*pi^(1/3)-1/4*i*3^(1/2)*2^(1/3)*pi^(1/3)]

a1 =

-3.3911693397183601737264718371364

x2 =

pi-acos(asin(tan(a)*b/a))

若想求精度为的根的近似值,首先需要选中MATLAB工作窗口中的下拉菜单File的子菜单Preferences,单击鼠标左键,在General对话框的Double Formal中选long;然后,在MATLAB工作窗口依次输入程序:

>>x1= 1/2*2^(1/3)*pi^(1/3),

x2=-1/4*2^(1/3)*pi^(1/3)+1/4*i*3^(1/2)*2^(1/3)*pi^(1/3)

x3= -1/4*2^(1/3)*pi^(1/3)-1/4*i*3^(1/2)*2^(1/3)*pi^(1/3)

运行后即可得到近似值:

x1 =

0.92263507432201

x2 =

-0.46131753716101 + 0.79902541278541i

x3 =

-0.46131753716101 - 0.79902541278541i

MATLAB系统本来只能做数值计算,并没有符号运算的功能,符号运算工具箱(Symbolic Math Toolbox)则扩充了MATLAB这方面的功能,它是由Maple软件的核心来完成的.用solve命令求方程的根的方法有一个缺点,它不能求出周期函数对应的方程的全部根(如,用命令 x=solve('sin(x)=0'),运行后输出一个根 x = 0).

[例3]  解超越方程组

解  在MATLAB命令窗口输入命令:

>> E1=sym('x^x-4=0'); E2=sym('2*x*y+x=1');

[x,y]=solve(E1,E2)

x1= double (x),y1= double (y)

则运行后输出超越方程组精确解x,y 和近似解x1,y1 如下:

x =

log(4)/lambertw(log(4))

y =

-1/2*(log(4)-lambertw(log(4)))/log(4)

x1 = 

2

y1 = 

-0.2500.

[例4]  解非线性方程组

解  在MATLAB命令窗口输入命令:

>> E1=sym('x+y+z=u'); E2=sym('2*x*z-y*u=-1'); E3=sym('(x+y)^2-z=u');

E4=sym('x*u+y*z =4'); [x,y,z,u]=solve(E1,E2,E3,E4), x1= double (x)

y1= double (y), z1= double (z), u1= double (u)

则运行后输出方程组精确解x,y,z,u(略)和近似解x1,y1,z1,u1 如下:

 

y1 =

  1.00000000000000                    

 23.60367144267526                   

  0.25371983421793 - 0.42474610911316i

  0.25371983421793 + 0.42474610911316i

 
x1 =

  3.00000000000000                   

  0.09943200266874                   

 -1.77193822355659 + 0.46109615509798i

 -1.77193822355659 - 0.46109615509798i

u1 =

  1.00000000000000                   

 -0.07054113510432                   

 -1.02028498800340 + 2.29336409349498i

 -1.02028498800340 - 2.29336409349498i。

 
 


z1 =

  1.00000000000000                   

-23.43369830490221                   

 -1.00537306977112 - 1.40752182928383i

 -1.00537306977112 + 1.40752182928383i

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/2/2040301.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1