>> 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