教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 综合文档 >

MATLAB编程练习(含答案很好的)(4)

来源:网络收集 时间:2026-03-07
导读: >> b=polyfit(p,w,4) Warning: Polynomial is not unique; degree >= number of data points. > In polyfit at 74 b = -0.6704 9.2037 -32.2593 0 98.1333 >> r=roots(p) r = -1.2119 + 1.0652i -1.2119 - 1.0652i

>> b=polyfit(p,w,4)

Warning: Polynomial is not unique; degree >= number of data points. > In polyfit at 74 b =

-0.6704 9.2037 -32.2593 0 98.1333

>> r=roots(p) r =

-1.2119 + 1.0652i -1.2119 - 1.0652i -0.5761

018求多项式的商和余 p=conv([1 0 2],conv([1 4],[1 1]))

p =

1 5 6 10

>> q=[1 0 1 1]

q =

1 0 1 1

>> [w,m]=deconv(p,q) w =

1 5 m =

0 0 5 4

>> cq=w;cr=m;

>> disp([cr,poly2str(m,'x')])

8 3 16

?????? 5 x^2 + 4 x + 3 >> disp([cq,poly2str(w,'x')]) ???? x + 5

019将分式分解 a=[1 5 6];b=[1]; >> [r,p,k]=residue(b,a) r =

-1.0000 1.0000 p =

-3.0000 -2.0000 k =

[]

020计算多项式: a=[1 2 3;4 5 6;7 8 9]; >> p=[3 0 2 3]; >> q=[2 3]; >> x=2;

>> r=roots(p) r =

0.3911 + 1.0609i 0.3911 - 1.0609i -0.7822

>> p1=conv(p,q)

p1 =

6 9 4 12 9

17

>> p2=poly(a) p2 =

1.0000 -15.0000 -18.0000 -0.0000

>> p3=polyder(p) p3 =

9 0 2

>> p4=polyval(p,x) p4 =

31

021求除式和余项:

[q,r]=deconv(conv([1 0 2],[1 4]),[1 1 1])

022字符串的书写格式: s='student' s = student

>> name='mary'; >> s1=[name s] s1 =

marystudent

>> s3=[name blanks(3);s] s3 =

mary

18

student

>>

023交换两个数: clear clc

a=[1 2 3 4 5]; b=[6 7 8 9 10]; c=a; a=b; b=c; a

b

24 If语句

n=input('enter a number,n='); if n<10 n end

025 if 双分支结构

a=input('enter a number ,a='); b=input('enter a number ,b='); if a>b max=a; else

max=b; end max

026三个数按照由大到小的顺序排列:A=15;B=24;C=45; if A

T=A;A=B;B=T; elseif A

T=A;A=C;C=T; elseif B

T=B;B=C;C=T; end A

19

B

C

027建立一个收费优惠系统:

price=input('please jinput the price : price=') switch fix(price/100) case[0,1] rate =0; case[2,3,4]

rate =3/100; case num2cell(5:9) rate=5/100; case num2cell(10:24) rate=8/100; case num2cell(25:49) rate=10/100; otherwise rate=14/100; end

price=price*(1-rate)

028:while循环语句 i=0;s=0;

while i<=1212 s=s+i; i=i+1; end

s

029,用for循环体语句: sum=0;

for i=1:1.5:100; sum=sum+i; end

sum

030循环的嵌套 s=0;

for i=1:1:6;

for j=1:1:8; s=s+i^j;

20

MATLAB编程练习(含答案很好的)(4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/403235.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)