Lecture8
-
Upload
mohamed-awni -
Category
Engineering
-
view
434 -
download
6
Transcript of Lecture8
![Page 1: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/1.jpg)
Lecture 8
Polynomial In Matlab
Eng. Mohamed Awni
Electrical & Computer Engineering
Dept.
![Page 2: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/2.jpg)
Agenda
2
Finding Roots
Finding polynomial coefficients
Value of a Polynomial
Derivatives of Polynomials
Integrals of Polynomials
Symbolic Math Toolbox
Exercise
![Page 3: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/3.jpg)
Finding Roots
roots function Solves polynomial equations of the form
returns the roots of the polynomial represented by p as a column vector.
r = roots(P)
• Polynomial coefficients, specified as a vector.
• Must include all coefficients, even if 0
For example:
• Vector [1 0 1] represents the polynomial 𝑥2+1,
• Vector [3.13 -2.21 5.99] represents the polynomial 3.13𝑥2−2.21𝑥+5.99.
![Page 4: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/4.jpg)
Solve the equation
Solve the equation
Finding Roots
![Page 5: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/5.jpg)
Finding polynomial coefficients
p = poly(r)
• r is a row or column vector with the roots of the polynomial • p is a row vector with the coefficients
Ex: roots = -3, 2
r = [-3 2];
p = poly(r)
p = 1 1 -6
% f(x) = x2 + x -6
Calculate polynomial coefficients
![Page 6: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/6.jpg)
6
Compute the value of a polynomial for any value of x directly
f(x) = 5𝑥3+ 6𝑥2-7𝑥 + 3
Polyval (p, x) • p is a vector with the coefficients of the polynomial • x is a number, variable or expression
Value of a Polynomial
![Page 7: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/7.jpg)
k = polyder(p)
Derivatives of Polynomials
Calculate the derivatives of polynomials
• p is the coefficient vector of the polynomial • k is the coefficient vector of the derivative
>> p = [3 -2 4]; >> k = polyder(p) k = 6 -2 % dy/dx = 6𝑥 - 2
Ex: f(x) = 3𝑥2 - 2𝑥 + 4
![Page 8: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/8.jpg)
Integrals of Polynomials
6𝑥2 d𝑥 = 6 𝑥2 dx
= 6 * 1
3 𝑥3
= 2 𝑥3
• h is the coefficient vector of the polynomial • g is the coefficient vector of the integral • k is the constant of integration – assumed to be 0 if not present
g = polyint(h, k) Calculate the integral of a polynomial
>> h = [6 0 0]; >> g = polyint(h) g = 2 0 0 0 % g(x) = 2x3
6𝑥2dx
![Page 9: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/9.jpg)
Finding roots.
Symbolic Math Toolbox
Performs calculation symbolically in Matlab environment.
>> f=2*x^2 + 4*x -8; >> solve(f,x)
In Matlab command window, we will first need to define x as a symbolic.
ans = -3.2361 1.2361
>> syms x
![Page 10: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/10.jpg)
Derivative.
We wish to take the derivative of function f(x):
In Matlab command window, we will first need to define x as a symbolic.
>> syms x >> f=x^3-cos(x); >> g=diff(f)
Symbolic Math Toolbox
>> syms x y >> f=x^2+(y+5)^3; >> diff(f,y)
Matlab returns: ans = 3*(y+5)^2
equivalent to
Matlab returns: g = 3*x^2+sin(x)
g=diff(f)
![Page 11: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/11.jpg)
Symbolic Math Toolbox
Integral.
>> syms x y >> int(f,x)
Matlab returns: ans = 1/3*x^3+(y+5)^3*x
>> int(f,y,0,10) Matlab returns: ans = 12500+10*x^2
int(f,x)
![Page 12: Lecture8](https://reader033.fdocuments.in/reader033/viewer/2022042820/55d05552bb61ebb37b8b4671/html5/thumbnails/12.jpg)
Exercises
P(x) = 𝑥4 + 7𝑥3 - 5x + 9
• Find the roots of the ploynomial P(x)
• Evaluate the polynomial P(x) for x=4 and x=6
• Calculate the d p(x)/dx
• Calculate the 𝑝(𝑥)