星期一, 11月 27, 2006

MATLAB課堂作業: 作業八

1. Find the multiplication result of two polynorminals, in which p=133x^5+122x^3+1, q=2x^4+100x^2+1.
ANS:
>> p=[133 0 122 0 0 1];
>> q=[2 0 100 0 1];
>> M=conv(p,q)

M =

266 0 13544 0 12333 2 122 100 0 1
故兩多項式乘積M= 266x9+13544x7+12333x5+2x4+122x3+100x2+1

2. A polynorminal is defined as f=100x^3+23x^2+x+45. Find the value f(x) if x is a magic matrix in the order of 5.
ANS:
>> x=magic(5);
>> f=[100 23 1 45];
>> v=polyval(f,x)

v =

498009 1395717 169 52725 342735
1228935 13125 35479 278967 415549
6817 22479 223645 809265 1075999
102355 176169 694267 936309 2955
135939 590715 1576945 939 74817

3. Using p and q defined in the item 1, find the quotient(商數) and residue(餘數) of p/q.
ANS:
>> p=[133 0 122 0 0 1];
>> q=[2 0 100 0 1];
>> [s,r]=deconv(p,q) % s代表商數,r代表餘數
s =

66.5000 0


r =

1.0e+003 *

0 0 -6.5280 0 -0.0665 0.0010

商數為66.5x,餘數為-6528x3-66.5x+1

4. Find the roots of p=0 and q=0, in which both p & q are defined in item 1.
ANS:
>> p=[133 0 122 0 0 1];
>> q=[2 0 100 0 1];
>> roots(p)
ans =

-0.0045 + 0.9578i
-0.0045 - 0.9578i
0.1039 + 0.1744i
0.1039 - 0.1744i
-0.1988

>> roots(q)
ans =

0 + 7.0704i
0 - 7.0704i
0 + 0.1000i
0 - 0.1000i

p共有5個根,q共有4個根

5. Fit a polynorminal curve to following data to an order of 3. x=[1:10]; y=[1210, 1866, 2301, 2564, 2724, 2881, 2879, 2915, 3010].
ANS:
>> x=[1:10];y=[1210, 1866, 2301, 2564, 2724, 2881, 2879, 2915, 3010];
>> polyfit(x,y,3)
??? Error using ==> polyfit
X and Y vectors must be the same size.

原本題目中y陣列中的元素值只有9個,與x陣列元素個數不符,因此執行指令時polyfit會有錯誤指令出現
若再加入一個自訂數值3178,則可算出最符合的多項式:
>> x=[1:10];y=[1210,1866,2301,2564,2724,2881,2879,2915,3010,3178];
>> polyfit(x,y,3)

ans =

1.0e+003 *

0.0065 -0.1372 1.0049 0.3410

多項式為6.5x3-137.2x2+100.49x+341

沒有留言: