MATLAB实验第四次上机 下载本文

内容发布更新时间 : 2024/9/17 14:03:04星期一 下面是文章的全部内容请认真阅读。

4.1 (1)

clear x0=1.5; x1=1+1/x0^2;

while abs(x1-x0)>=0.00005 x0=x1; x1=1+1/x0^2; end x1

结果:收敛 x1 =

1.4656 (2)

clear x0=1.5;

x1=(1+x0^2)^(1/3); while abs(x1-x0)>=0.00005 x0=x1;

x1=(1+x0^2)^(1/3); end x1

结果:收敛 x1 =

1.4656 (3)

clear x0=1.5;

x1=(1/(x0-1))^(1/2); while abs(x1-x0)>=0.00005 x0=x1;

x1=(1/(x0-1))^(1/2); end x1

结果:MATLAB始终正忙,不收敛 4.2...

>> x1=roots([1 -2 -4 -7]) x1 =

3.6320 -0.8160 + 1.1232i

-0.8160 - 1.1232i

>> x2=fzero('x^3-2*x^2-4*x-7',3) x2 =

3.6320

>> s='x^3-2*x^2-4*x-7' s =

x^3-2*x^2-4*x-7

>> x=solve(s) x =

1/6*(1108+36*745^(1/2))^(1/3)+32/3/(1108+36*745^(1/2))^(1/3)+2/3

-1/12*(1108+36*745^(1/2))^(1/3)-16/3/(1108+36*745^(1/2))^(1/3)+2/3+1/2*i*3^(1/2)*(1/6*(1108+36*745^(1/2))^(1/3)-32/3/(1108+36*745^(1/2))^(1/3))

-1/12*(1108+36*745^(1/2))^(1/3)-16/3/(1108+36*745^(1/2))^(1/3)+2/3-1/2*i*3^(1/2)*(1/6*(1108+36*745^(1/2))^(1/3)-32/3/(1108+36*745^(1/2))^(1/3))

>> vpa(x) ans =

3.6319808055660635175221064455414 -.81599040278303175876105322277063+1.1231574348390212417188459351214*i -.81599040278303175876105322277063-1.1231574348390212417188459351214*i

4.3............

>> roots([1 2 10 -20])

ans =

-1.6844 + 3.4313i -1.6844 - 3.4313i 1.3688

4.4.....

>> x=solve('1-x-sin(x)') x =

.51097342938856910952001397114508

>> x=fsolve('1-x-sin(x)',0.5)

Optimization terminated: first-order optimality is less than options.TolFun. x =

0.5110

4.5......

>> x=fsolve('x-sin(x)/x',1)

Optimization terminated: first-order optimality is less than options.TolFun. x =

0.8767

4.6.......

>> ezplot('sin(x)+1-x^2/2'),grid,hold Current plot held >> ezplot('x-x')

>> x=fsolve('sin(x)+1-x^2/2',-0.8)

Optimization terminated: first-order optimality is less than options.TolFun. x =

-0.7750

>> x=fsolve('sin(x)+1-x^2/2',2)

Optimization terminated: first-order optimality is less than options.TolFun. x =

1.9619

4.7.。。。。

>> ezplot('cos(x)-0.5-sin(x)'),grid,hold Current plot held >> ezplot('x-x')