SlideShare a Scribd company logo
1
Polynomials in Matlab
Polynomials
• f(x) = anxn
+ an-1xn-1
+ ... + a1x + a0
• n is the degree of the polynomial
• Examples:
f(x) = 2x2
- 4x + 10 degree 2
f(x) = 6 degree 0
Polynomials in
Matlab
• Represented by a row vector in which the
elements are the coefficients.
• Must include all coefficients, even if 0
• Examples
8x + 5 p = [8 5]
6x2
- 150 h = [6 0 -150]
2
Value of a
Polynomial
• Recall that we can compute the value of a
polynomial for any value of x directly.
• Ex: f(x) = 5x3
+ 6x2
- 7x + 3
x = 2;
y = (5 * x ^ 3) + (6 * x ^ 2) - (7 * x) + 3
y =
53
Value of a
Polynomial
• Matlab can also compute the value of a
polynomial at point x using a function,
which is sometimes more convenient
• polyval (p, x)
– p is a vector with the coefficients of the
polynomial
– x is a number, variable or expression
Value of a
polynomial
• Ex: f(x) = 5x3
+ 6x2
- 7x + 3
p = [5 6 -7 3];
x = 2;
y = polyval(p, x)
y =
53
3
Roots of a
Polynomial
• Recall that the roots of a polynomial are
the values of the argument for which the
polynomial is equal to zero
• Ex: f(x) = x2
- 2x -3
0 = x2
- 2x -3
0 = (x + 1)(x - 3)
0 = x + 1 OR 0 = x - 3
x = -1 x = 3
Roots of a
Polynomial
• Matlab can compute the roots of a function
• r = roots(p)
– p is a row vector with the coefficients of the
polynomial
– r is a column vector with the roots of the
polynomial
Roots of a
Polynomial
• Ex: f(x) = x2
- 2x -3
p = [1 -2 -3];
r = roots(p)
r =
3.0000
-1.0000
4
Polynomial
Coefficients
• Given the roots of a polynomial, the
polynomial itself can be calculated
• Ex: roots = -3, +2
x = -3 OR x = 2
0 = x + 3 0 = x - 2
0 = (x + 3)(x - 2)
f(x) = x2
+ x - 6
Polynomial
Coefficients
• Given the roots of a polynomial, Matlab
can compute the 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
Polynomial
Coefficients
• Ex: roots = -3, +2
r = [-3 +2];
p = poly(r)
p =
1 1 -6
% f(x) = x2
+ x -6
5
Adding and Subtracting
Polynomials
• Polynomials can be added or subtracted
• Ex: f1(x) + f2(x)
f1(x) = 3x6
+ 15x5
- 10x3
- 3x2
+15x - 40
f2(x) = 3x3
- 2x - 6
3x6
+ 15x5
- 7x3
-3x2
+13x - 46
Adding and Subtracting
Polynomials
• Can do this in Matlab by just adding or
subtracting the coefficient vectors
– Both vectors must be of the same size, so the
shorter vector must be padded with zeros
Adding and Subtracting
Polynomials
Ex:
f1(x) = 3x6 + 15x5 - 10x3 - 3x2 +15x - 40
f2(x) = 3x3 - 2x - 6
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
6
Multiplying Polynomials
• Polynomials can be multiplied:
• Ex: (2x2
+ x -3) * (x + 1) =
2x3
+ x2
- 3x
+ 2x2
+ x -3
2x3
+3x2
-2x -3
Multiplying Polynomials
• Matlab can also multiply polynomials
• c = conv(a, b)
– a and b are the vectors of the coefficients of
the functions being multiplied
– c is the vector of the coefficients of the
product
Multiplying Polynomials
• Ex: (2x2
+ x -3) * (x + 1)
a = [2 1 -3];
b = [1 1];
c = conv(a, b)
c =
2 3 -2 -3
% 2x3
+ 3x2
-2x -3
7
Dividing Polynomials
• Recall that polynomials can also be
divided
x -10
x + 1 x2
- 9x - 10
-x2
- x
-10x -10
-10x -10
0
Dividing Polynomials
• Matlab can also divide polynomials
• [q,r] = deconv(u, v)
– u is the coefficient vector of the numerator
– v is the coefficient vector of the denominator
– q is the coefficient vector of the quotient
– r is the coefficient vector of the remainder
Dividing Polynomials
• Ex: (x2
- 9x -10) ÷ (x + 1)
u = [1 -9 -10];
v = [1 1];
[q, r] = deconv(u, v)
q =
1 -10 % quotient is (x - 10)
r =
0 0 0 % remainder is 0
8
Example 1
• Write a program to calculate when an object
thrown straight up will hit the ground. The
equation is
s(t) = -½gt2 +v0t + h0
s is the position at time t (a position of zero
means that the object has hit the ground)
g is the acceleration of gravity: 9.8m/s2
v0 is the initial velocity in m/s
h0is the initial height in meters (ground level is 0,
a positive height means that the object was
thrown from a raised platform)
Example 1
Prompt for and read in initial velocity
Prompt for and read in initial height
Find the roots of the equation
Solution is the positive root
Display solution
Example 1
v = input('Please enter initial velocity: ');
h = input('Please enter initial height: ');
x = [-4.9 v h];
y = roots(x);
if y(1) >= 0
fprintf('The object will hit the ground in %.2f secondsn',
y(1))
else
fprintf('The object will hit the ground in %.2f secondsn',
y(2))
end
9
Example 1
Please enter initial velocity: 19.6
Please enter initial height: 58.8
The object will hit the ground in 6.00
seconds
Derivatives of
Polynomials
• We can take the derivative of polynomials
f(x) = 3x2
-2x + 4
dy = 6x - 2
dx
Derivatives of
Polynomials
• Matlab can also calculate the derivatives
of polynomials
• k = polyder(p)
p is the coefficient vector of the polynomial
k is the coefficient vector of the derivative
10
Derivatives of
Polynomials
• Ex: f(x) = 3x2
- 2x + 4
p = [3 -2 4];
k = polyder(p)
k =
6 -2
% dy/dx = 6x - 2
Integrals of Polynomials
• ?6x2
dx = 6 ?x2
dx
= 6 * ? x3
= 2 x3
Integrals of
Polynomials
• Matlab can also calculate the integral of a
polynomial
g = polyint(h, k)
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
11
Integration of
Polynomials
• ?6x2
dx
h = [6 0 0];
g = polyint(h)
g =
2 0 0 0
% g(x) = 2x3
Polynomial Curve Fitting
• Curve fitting is fitting a function to a set of
data points
• That function can then be used for various
mathematical analyses
• Curve fitting can be tricky, as there are
many possible functions and coefficients
Curve Fitting
• Polynomial curve fitting uses the method
of least squares
– Determine the difference between each data
point and the point on the curve being fitted,
called the residual
– Minimize the sum of the squares of all of the
residuals to determine the best fit
12
Curve Fitting
• A best-fit curve may not pass through any
actual data points
• A high-order polynomial may pass through
all the points, but the line may deviate
from the trend of the data
13
Matlab Curve Fitting
• Matlab provides an excellent polynomial
curve fitting interface
• First, plot the data that you want to fit
t = [0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0];
w = [6.00 4.83 3.70 3.15 2.41 1.83 1.49 1.21 0.96 0.73
0.64];
plot(t, w)
• Choose Tools/Basic Fitting from the menu
on the top of the plot
14
Matlab Curve Fitting
• Choose a fit
– it will be displayed on the plot
– the numerical results will show the equation
and the coefficients
– the norm of residuals is a measure of the
quality of the fit. A smaller residual is a better
fit.
• Repeat until you find the curve with the
best fit
Linear Fit
Linear Fit
15
8th Degree Polynomial
8th Degree Polynomial
Example 2
• Find the parabola that best fits the data
points (-1, 10) (0, 6) (1, 2) (2, 1) (3, 0)
(4, 2) (5, 4) and (6, 7)
• The equation for a parabola is
f(x) = ax2
+ bx + a
16
Example 2
X = [-1, 0, 1, 2, 3, 4, 5, 6];
Y= [10, 6, 2, 1, 0, 2, 4, 7];
plot (X, Y)
17
Other curves
• All previous examples use polynomial
curves. However, the best fit curve may
also be power, exponential, logarithmic or
reciprocal
• See your textbook for information on fitting
data to these types of curves
Interpolation
• Interpolation is estimating values between
data points
• Simplest way is to assume a line between
each pair of points
• Can also assume a quadratic or cubic
polynomial curve connects each pair of
points
Interpolation
• yi = interp1(x, y, xi, 'method')
interp1 - last character is one
x is vector with x points
y is a vector with y points
xi is the x coordinate of the point to be
interpolated
yi is the y coordinate of the point being
interpolated
18
Interpolation
• method is optional:
'nearest' - returns y value of the data point that
is nearest to the interpolated x point
'linear' - assume linear curve between each two
points (default)
'spline' - assumes a cubic curve between each
two points
Interpolation
• Example:
x = [0 1 2 3 4 5];
y = [1.0 -0.6 -1.4 3.2 -0.7 -6.4];
yi = interp1(x, y, 1.5, 'linear')
yi =
-1
yj = interp1(x, y, 1.5, 'spline')
yj =
-1.7817

More Related Content

What's hot

Harmonic Analysis and Deep Learning
Harmonic Analysis and Deep LearningHarmonic Analysis and Deep Learning
Harmonic Analysis and Deep Learning
Sungbin Lim
 
Matrix calculus
Matrix calculusMatrix calculus
Matrix calculus
Sungbin Lim
 
Numerical differentiation integration
Numerical differentiation integrationNumerical differentiation integration
Numerical differentiation integration
Tarun Gehlot
 
Predicates and Quantifiers
Predicates and Quantifiers Predicates and Quantifiers
Predicates and Quantifiers
Istiak Ahmed
 
Expectation propagation
Expectation propagationExpectation propagation
Expectation propagation
Dong Guo
 
Chapter 3 ds
Chapter 3 dsChapter 3 ds
Chapter 3 ds
Hanif Durad
 
Numerical Methods 3
Numerical Methods 3Numerical Methods 3
Numerical Methods 3
Dr. Nirav Vyas
 
Math 4 graphing rational functions
Math 4 graphing rational functionsMath 4 graphing rational functions
Math 4 graphing rational functionsLeo Crisologo
 
Indefinite Integral
Indefinite IntegralIndefinite Integral
Indefinite IntegralJelaiAujero
 
Naville's Interpolation
Naville's InterpolationNaville's Interpolation
Naville's Interpolation
VARUN KUMAR
 
Numerical Method
Numerical MethodNumerical Method
Numerical Method
Ankita Khadatkar
 
Exponential functions (1)
Exponential functions (1)Exponential functions (1)
Exponential functions (1)
nellealexasioquim
 
Newton divided difference interpolation
Newton divided difference interpolationNewton divided difference interpolation
Newton divided difference interpolation
VISHAL DONGA
 
Polynomial functions
Polynomial functionsPolynomial functions
Polynomial functionsLeo Crisologo
 
Predicate & quantifier
Predicate & quantifierPredicate & quantifier
Predicate & quantifier
University of Potsdam
 
Applications of maxima and minima
Applications of maxima and minimaApplications of maxima and minima
Applications of maxima and minimarouwejan
 
Integration+using+u-substitutions
Integration+using+u-substitutionsIntegration+using+u-substitutions
Integration+using+u-substitutionstutorcircle1
 
Formal methods 4 - Z notation
Formal methods   4 - Z notationFormal methods   4 - Z notation
Formal methods 4 - Z notation
Vlad Patryshev
 

What's hot (19)

Harmonic Analysis and Deep Learning
Harmonic Analysis and Deep LearningHarmonic Analysis and Deep Learning
Harmonic Analysis and Deep Learning
 
Matrix calculus
Matrix calculusMatrix calculus
Matrix calculus
 
Numerical differentiation integration
Numerical differentiation integrationNumerical differentiation integration
Numerical differentiation integration
 
Predicates and Quantifiers
Predicates and Quantifiers Predicates and Quantifiers
Predicates and Quantifiers
 
Expectation propagation
Expectation propagationExpectation propagation
Expectation propagation
 
Chapter 3 ds
Chapter 3 dsChapter 3 ds
Chapter 3 ds
 
Numerical Methods 3
Numerical Methods 3Numerical Methods 3
Numerical Methods 3
 
The integral
The integralThe integral
The integral
 
Math 4 graphing rational functions
Math 4 graphing rational functionsMath 4 graphing rational functions
Math 4 graphing rational functions
 
Indefinite Integral
Indefinite IntegralIndefinite Integral
Indefinite Integral
 
Naville's Interpolation
Naville's InterpolationNaville's Interpolation
Naville's Interpolation
 
Numerical Method
Numerical MethodNumerical Method
Numerical Method
 
Exponential functions (1)
Exponential functions (1)Exponential functions (1)
Exponential functions (1)
 
Newton divided difference interpolation
Newton divided difference interpolationNewton divided difference interpolation
Newton divided difference interpolation
 
Polynomial functions
Polynomial functionsPolynomial functions
Polynomial functions
 
Predicate & quantifier
Predicate & quantifierPredicate & quantifier
Predicate & quantifier
 
Applications of maxima and minima
Applications of maxima and minimaApplications of maxima and minima
Applications of maxima and minima
 
Integration+using+u-substitutions
Integration+using+u-substitutionsIntegration+using+u-substitutions
Integration+using+u-substitutions
 
Formal methods 4 - Z notation
Formal methods   4 - Z notationFormal methods   4 - Z notation
Formal methods 4 - Z notation
 

Viewers also liked

Códigos Matemáticos
Códigos MatemáticosCódigos Matemáticos
Códigos Matemáticos
Evangelina Donnet
 
EJERCICIOS MATEMATICOS PARA 2° GRADO
EJERCICIOS MATEMATICOS PARA 2° GRADOEJERCICIOS MATEMATICOS PARA 2° GRADO
EJERCICIOS MATEMATICOS PARA 2° GRADOariecita
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...
Brian Solis
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
maditabalnco
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
Barry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
Helge Tennø
 

Viewers also liked (6)

Códigos Matemáticos
Códigos MatemáticosCódigos Matemáticos
Códigos Matemáticos
 
EJERCICIOS MATEMATICOS PARA 2° GRADO
EJERCICIOS MATEMATICOS PARA 2° GRADOEJERCICIOS MATEMATICOS PARA 2° GRADO
EJERCICIOS MATEMATICOS PARA 2° GRADO
 
The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...The impact of innovation on travel and tourism industries (World Travel Marke...
The impact of innovation on travel and tourism industries (World Travel Marke...
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 

Similar to Advanced matlab codigos matematicos

Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fitting
Ameen San
 
Polynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLABPolynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLAB
Shameer Ahmed Koya
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
Devaraj Chilakala
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Damian T. Gordon
 
3.1 Characteristics of Polynomial Functions.pptx
3.1 Characteristics of Polynomial Functions.pptx3.1 Characteristics of Polynomial Functions.pptx
3.1 Characteristics of Polynomial Functions.pptx
Alaa480924
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptx
imman gwu
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
Mohd Esa
 
Introduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdfIntroduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdf
JifarRaya
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Khulna University
 
5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions
smiller5
 
Module 3 polynomial functions
Module 3   polynomial functionsModule 3   polynomial functions
Module 3 polynomial functions
dionesioable
 
matlab lecture 4 solving mathematical problems.ppt
matlab lecture 4 solving mathematical problems.pptmatlab lecture 4 solving mathematical problems.ppt
matlab lecture 4 solving mathematical problems.ppt
aaaaboud1
 
1519 differentiation-integration-02
1519 differentiation-integration-021519 differentiation-integration-02
1519 differentiation-integration-02
Dr Fereidoun Dejahang
 
01 FUNCTIONS.pptx
01 FUNCTIONS.pptx01 FUNCTIONS.pptx
01 FUNCTIONS.pptx
JonathanBeltranJr
 
Algebra and functions review
Algebra and functions reviewAlgebra and functions review
Algebra and functions review
Institute of Applied Technology
 

Similar to Advanced matlab codigos matematicos (20)

Lec3
Lec3Lec3
Lec3
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fitting
 
Polynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLABPolynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLAB
 
Mit6 094 iap10_lec03
Mit6 094 iap10_lec03Mit6 094 iap10_lec03
Mit6 094 iap10_lec03
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
3.1 Characteristics of Polynomial Functions.pptx
3.1 Characteristics of Polynomial Functions.pptx3.1 Characteristics of Polynomial Functions.pptx
3.1 Characteristics of Polynomial Functions.pptx
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptx
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
Introduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdfIntroduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdf
 
Lesson 8
Lesson 8Lesson 8
Lesson 8
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions5.5 Zeros of Polynomial Functions
5.5 Zeros of Polynomial Functions
 
Module 3 polynomial functions
Module 3   polynomial functionsModule 3   polynomial functions
Module 3 polynomial functions
 
matlab lecture 4 solving mathematical problems.ppt
matlab lecture 4 solving mathematical problems.pptmatlab lecture 4 solving mathematical problems.ppt
matlab lecture 4 solving mathematical problems.ppt
 
Fst ch3 notes
Fst ch3 notesFst ch3 notes
Fst ch3 notes
 
1519 differentiation-integration-02
1519 differentiation-integration-021519 differentiation-integration-02
1519 differentiation-integration-02
 
01 FUNCTIONS.pptx
01 FUNCTIONS.pptx01 FUNCTIONS.pptx
01 FUNCTIONS.pptx
 
Algebra and functions review
Algebra and functions reviewAlgebra and functions review
Algebra and functions review
 
Algebra and functions review
Algebra and functions reviewAlgebra and functions review
Algebra and functions review
 

Recently uploaded

NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
ssuser7dcef0
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
ChristineTorrepenida1
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Soumen Santra
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
manasideore6
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 

Recently uploaded (20)

NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
Unbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptxUnbalanced Three Phase Systems and circuits.pptx
Unbalanced Three Phase Systems and circuits.pptx
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTSHeap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
Heap Sort (SS).ppt FOR ENGINEERING GRADUATES, BCA, MCA, MTECH, BSC STUDENTS
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Fundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptxFundamentals of Induction Motor Drives.pptx
Fundamentals of Induction Motor Drives.pptx
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 

Advanced matlab codigos matematicos

  • 1. 1 Polynomials in Matlab Polynomials • f(x) = anxn + an-1xn-1 + ... + a1x + a0 • n is the degree of the polynomial • Examples: f(x) = 2x2 - 4x + 10 degree 2 f(x) = 6 degree 0 Polynomials in Matlab • Represented by a row vector in which the elements are the coefficients. • Must include all coefficients, even if 0 • Examples 8x + 5 p = [8 5] 6x2 - 150 h = [6 0 -150]
  • 2. 2 Value of a Polynomial • Recall that we can compute the value of a polynomial for any value of x directly. • Ex: f(x) = 5x3 + 6x2 - 7x + 3 x = 2; y = (5 * x ^ 3) + (6 * x ^ 2) - (7 * x) + 3 y = 53 Value of a Polynomial • Matlab can also compute the value of a polynomial at point x using a function, which is sometimes more convenient • polyval (p, x) – p is a vector with the coefficients of the polynomial – x is a number, variable or expression Value of a polynomial • Ex: f(x) = 5x3 + 6x2 - 7x + 3 p = [5 6 -7 3]; x = 2; y = polyval(p, x) y = 53
  • 3. 3 Roots of a Polynomial • Recall that the roots of a polynomial are the values of the argument for which the polynomial is equal to zero • Ex: f(x) = x2 - 2x -3 0 = x2 - 2x -3 0 = (x + 1)(x - 3) 0 = x + 1 OR 0 = x - 3 x = -1 x = 3 Roots of a Polynomial • Matlab can compute the roots of a function • r = roots(p) – p is a row vector with the coefficients of the polynomial – r is a column vector with the roots of the polynomial Roots of a Polynomial • Ex: f(x) = x2 - 2x -3 p = [1 -2 -3]; r = roots(p) r = 3.0000 -1.0000
  • 4. 4 Polynomial Coefficients • Given the roots of a polynomial, the polynomial itself can be calculated • Ex: roots = -3, +2 x = -3 OR x = 2 0 = x + 3 0 = x - 2 0 = (x + 3)(x - 2) f(x) = x2 + x - 6 Polynomial Coefficients • Given the roots of a polynomial, Matlab can compute the 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 Polynomial Coefficients • Ex: roots = -3, +2 r = [-3 +2]; p = poly(r) p = 1 1 -6 % f(x) = x2 + x -6
  • 5. 5 Adding and Subtracting Polynomials • Polynomials can be added or subtracted • Ex: f1(x) + f2(x) f1(x) = 3x6 + 15x5 - 10x3 - 3x2 +15x - 40 f2(x) = 3x3 - 2x - 6 3x6 + 15x5 - 7x3 -3x2 +13x - 46 Adding and Subtracting Polynomials • Can do this in Matlab by just adding or subtracting the coefficient vectors – Both vectors must be of the same size, so the shorter vector must be padded with zeros Adding and Subtracting Polynomials Ex: f1(x) = 3x6 + 15x5 - 10x3 - 3x2 +15x - 40 f2(x) = 3x3 - 2x - 6 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
  • 6. 6 Multiplying Polynomials • Polynomials can be multiplied: • Ex: (2x2 + x -3) * (x + 1) = 2x3 + x2 - 3x + 2x2 + x -3 2x3 +3x2 -2x -3 Multiplying Polynomials • Matlab can also multiply polynomials • c = conv(a, b) – a and b are the vectors of the coefficients of the functions being multiplied – c is the vector of the coefficients of the product Multiplying Polynomials • Ex: (2x2 + x -3) * (x + 1) a = [2 1 -3]; b = [1 1]; c = conv(a, b) c = 2 3 -2 -3 % 2x3 + 3x2 -2x -3
  • 7. 7 Dividing Polynomials • Recall that polynomials can also be divided x -10 x + 1 x2 - 9x - 10 -x2 - x -10x -10 -10x -10 0 Dividing Polynomials • Matlab can also divide polynomials • [q,r] = deconv(u, v) – u is the coefficient vector of the numerator – v is the coefficient vector of the denominator – q is the coefficient vector of the quotient – r is the coefficient vector of the remainder Dividing Polynomials • Ex: (x2 - 9x -10) ÷ (x + 1) u = [1 -9 -10]; v = [1 1]; [q, r] = deconv(u, v) q = 1 -10 % quotient is (x - 10) r = 0 0 0 % remainder is 0
  • 8. 8 Example 1 • Write a program to calculate when an object thrown straight up will hit the ground. The equation is s(t) = -½gt2 +v0t + h0 s is the position at time t (a position of zero means that the object has hit the ground) g is the acceleration of gravity: 9.8m/s2 v0 is the initial velocity in m/s h0is the initial height in meters (ground level is 0, a positive height means that the object was thrown from a raised platform) Example 1 Prompt for and read in initial velocity Prompt for and read in initial height Find the roots of the equation Solution is the positive root Display solution Example 1 v = input('Please enter initial velocity: '); h = input('Please enter initial height: '); x = [-4.9 v h]; y = roots(x); if y(1) >= 0 fprintf('The object will hit the ground in %.2f secondsn', y(1)) else fprintf('The object will hit the ground in %.2f secondsn', y(2)) end
  • 9. 9 Example 1 Please enter initial velocity: 19.6 Please enter initial height: 58.8 The object will hit the ground in 6.00 seconds Derivatives of Polynomials • We can take the derivative of polynomials f(x) = 3x2 -2x + 4 dy = 6x - 2 dx Derivatives of Polynomials • Matlab can also calculate the derivatives of polynomials • k = polyder(p) p is the coefficient vector of the polynomial k is the coefficient vector of the derivative
  • 10. 10 Derivatives of Polynomials • Ex: f(x) = 3x2 - 2x + 4 p = [3 -2 4]; k = polyder(p) k = 6 -2 % dy/dx = 6x - 2 Integrals of Polynomials • ?6x2 dx = 6 ?x2 dx = 6 * ? x3 = 2 x3 Integrals of Polynomials • Matlab can also calculate the integral of a polynomial g = polyint(h, k) 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
  • 11. 11 Integration of Polynomials • ?6x2 dx h = [6 0 0]; g = polyint(h) g = 2 0 0 0 % g(x) = 2x3 Polynomial Curve Fitting • Curve fitting is fitting a function to a set of data points • That function can then be used for various mathematical analyses • Curve fitting can be tricky, as there are many possible functions and coefficients Curve Fitting • Polynomial curve fitting uses the method of least squares – Determine the difference between each data point and the point on the curve being fitted, called the residual – Minimize the sum of the squares of all of the residuals to determine the best fit
  • 12. 12 Curve Fitting • A best-fit curve may not pass through any actual data points • A high-order polynomial may pass through all the points, but the line may deviate from the trend of the data
  • 13. 13 Matlab Curve Fitting • Matlab provides an excellent polynomial curve fitting interface • First, plot the data that you want to fit t = [0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0]; w = [6.00 4.83 3.70 3.15 2.41 1.83 1.49 1.21 0.96 0.73 0.64]; plot(t, w) • Choose Tools/Basic Fitting from the menu on the top of the plot
  • 14. 14 Matlab Curve Fitting • Choose a fit – it will be displayed on the plot – the numerical results will show the equation and the coefficients – the norm of residuals is a measure of the quality of the fit. A smaller residual is a better fit. • Repeat until you find the curve with the best fit Linear Fit Linear Fit
  • 15. 15 8th Degree Polynomial 8th Degree Polynomial Example 2 • Find the parabola that best fits the data points (-1, 10) (0, 6) (1, 2) (2, 1) (3, 0) (4, 2) (5, 4) and (6, 7) • The equation for a parabola is f(x) = ax2 + bx + a
  • 16. 16 Example 2 X = [-1, 0, 1, 2, 3, 4, 5, 6]; Y= [10, 6, 2, 1, 0, 2, 4, 7]; plot (X, Y)
  • 17. 17 Other curves • All previous examples use polynomial curves. However, the best fit curve may also be power, exponential, logarithmic or reciprocal • See your textbook for information on fitting data to these types of curves Interpolation • Interpolation is estimating values between data points • Simplest way is to assume a line between each pair of points • Can also assume a quadratic or cubic polynomial curve connects each pair of points Interpolation • yi = interp1(x, y, xi, 'method') interp1 - last character is one x is vector with x points y is a vector with y points xi is the x coordinate of the point to be interpolated yi is the y coordinate of the point being interpolated
  • 18. 18 Interpolation • method is optional: 'nearest' - returns y value of the data point that is nearest to the interpolated x point 'linear' - assume linear curve between each two points (default) 'spline' - assumes a cubic curve between each two points Interpolation • Example: x = [0 1 2 3 4 5]; y = [1.0 -0.6 -1.4 3.2 -0.7 -6.4]; yi = interp1(x, y, 1.5, 'linear') yi = -1 yj = interp1(x, y, 1.5, 'spline') yj = -1.7817