Lecture 7 Polynomials DR Nahid Sanzida
Lecture 7 Polynomials DR Nahid Sanzida
we type,
>> y=polyval(c,5)
y=
303.5500
Plotting with Polynomial Equations
>> dc=polyder(c)
dc =
9.0000 -4.4600 -5.1000
Fitting Polynomial/Nonlinear Equations
x = [1 2 3 4 5];
y = [5.5 43.1 128 290.7 498.4];
>> p = polyfit(x,y,3)
p = -0.1917 31.5821 -60.3262 35.3400
-0.1917x3 +31.5821x2-60.3262x+35.3400
Fitting Polynomial/Nonlinear Equations
Brainstorming session!!
x2 = 1:0.1:5;
y2 = polyval(p,x2);
plot(x,y,'o',x2,y2)
grid on
Adding and Subtracting Polynomials
Polynomials can be added or subtracted
Ex: f1(x) + f2(x)
f1(x) = 3x6 + 15x 5 - 10x3 - 3x2 +15x - 40
f2(x) = 3x3 - 2x - 6
---------------------------------------------
= 3x6 + 15x 5 - 7x3 -3x2 +13x - 46
by just adding or subtracting the coefficient vectors
Both vectors must be of the same size
the shorter vector must be padded with zeros
We write,
p1 = [3 15 0 -10 -3 15 -40];
p2 = [0 0 0 3 0 -2 -6];
p = p1+p2
p = 3 15 0 -7 -3 13 -46
%f(x) = 3x6 + 15x5 -7x3 -3x2 +13x -46
Multiplying Polynomials
We type
a = [2 1 -3];
b = [1 1];
c = conv(a, b)
c = 2 3 -2 -3
% 2x3+ 3x2-2x -3
Dividing Polynomials
== Equal to
~= Not equal to
< Strictly smaller
> Strictly greater
<= Smaller than or equal to
>= Greater than equal to
& And operator
| Or operator
Operators (relational, logical)
X = 5;
Example X >= [1 2 3; 4 5 6; 7 8 10]
ans =
1 1 1
1 1 0
X = 5*ones(3,3); 0 0 0
X >= [1 2 3; 4 5 6; 7 8 10]
ans =
1 1 1
1 1 0
0 0 0
Truth Table
and or
Inputs A and B
A&B A|B
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1