Docsity

Polynomials Practice Problems - Engineering Computation | MET 4903, Assignments of Mechanical Engineering

Toggle sidebar
bg1
Polynomials Practice Problems Engineering Computation, Dr Simin Nasseri
1. Perform the following operations and check your answers in Matlab:
5
3
5 3
( ) 5 7
( ) 2
_____________________________
( ) ( ) 5 9
>> p=[1 0 0 0 5 7]
>> h=[0 0 1 0 0 2]
>> p+h = [1 0 1 0 5 9]
______________________________
( )* ( )
>> mult=conv(p,h)
mu
p x x x
h x x
P x h x x x x
P x h x
8 5 4 3
2
lt= 2 5 7 10 14
Works if you omit the first two zeros of h.
_________________________________
( ) / ( )
>> p=[1 0 0 0 5 7]
>> h=[1 0 0 2]
>> [quo, rem]=deconv(p,h)
[1 0 0]
[ 0 0 0 -2 5 7
x x x x x
P x h x x
2
2
]
Quotient
Remainder = 2 5 7
__________________________
( 1)
>> polyval(p,-1)
1
__________________________
(2)
>> polyval(h,2)
10
x
x x
P
h
2. Find all the roots of
5
( ) 5 7p x x x
>> % polynomial = array of coefficients in matlab:
>> p = [1 0 0 0 5 7]; % p(x) = x^5 + 5*x + 7
>> format long; % print double-precision
>> roots(p) % print out the roots of p(x)
pf3
pf4

Partial preview of the text

Download Polynomials Practice Problems - Engineering Computation | MET 4903 and more Assignments Mechanical Engineering in PDF only on Docsity!

Polynomials Practice Problems Engineering Computation, Dr Simin Nasseri

  1. Perform the following operations and check your answers in Matlab:

5

3

5 3

_____________________________

p=[1 0 0 0 5 7]

h=[0 0 1 0 0 2]

p+h = [1 0 1 0 5 9]

______________________________

mult=conv(p,h)

mu

p x x x

h x x

P x h x x x x

P x h x

8 5 4 3

2

lt= 2 5 7 10 14

Works if you omit the first two zeros of h.

_________________________________

p=[1 0 0 0 5 7]

h=[1 0 0 2]

[quo, rem]=deconv(p,h)

[1 0 0]

[ 0 0 0 -2 5 7

x x x x x

P x h x x

2

2

]

Quotient

Remainder = 2 5 7

__________________________

polyval(p,-1)

__________________________

polyval(h,2)

x

x x

P

h

  1. Find all the roots of

5

p x ( )  x  5 x  7

% polynomial = array of coefficients in matlab:

p = [1 0 0 0 5 7]; % p(x) = x^5 + 5*x + 7

format long; % print double-precision

roots(p) % print out the roots of p(x)

2- Consider the following sets of x and y vectors. Plot the graphs and find the best polynomial

which can fit each set (write the equation in front of it). Write down the type of fit (degree of

polynomials and its coefficients), resides and normresids values.

[ 3, 2, 1, 0,1, 2,3, 4]

[ 28, 9, 2, 1, 0, 7, 26, 63]

x

y

^  ^ ^ 

Cubic fit:

3

yx  1 (p 1 = 1, p 2 = p 3 = 0, p 4 = -1)

[0,1, 2,3, 4,5]

[0, 20, 60, 68, 77,110]

x

y

^ 

Forth degree polynomial:

function [a , b] = PhillipChris

% This function reads two input files and fits a curve to each data set

% It also interpolates the values given for much finer data values.

% Written by S. Nasseri

clc

close all

clear all

% Loading the data and allocating them as x and y vectors:

load Phillip.txt

load Chris.txt

x1 = Phillip(:,1);

y1 = Phillip(:,2);

x2 = Chris(:,1);

y2 = Chris(:,2);

% generating much finer data points based on the original x values:

x1new = x1(1): 0.1: x1(end);

x2new = x2(1): 0.1: x2(end);

%___________________________________________________________________

% Interpolation, generating new y values based on initial finer data points

y1new = interp1(x1, y1, x1new, 'spline');

y2new = interp1(x2, y2, x2new, 'spline');

figure (1)

plot(x1,y1,'r*', x1new,y1new)

hold on

plot(x2,y2,'g*', x2new,y2new, 'k')

text (.5,200,'Interpolation')

%___________________________________________________________________

% Curve Fitting:

% finding the coefficients of the two cubic polynomials:

% We should use the original set of data:

format long

a = polyfit(x1, y1, 3);

b = polyfit(x2, y2, 3);

% Generating the corresponding y values based on the polynomials we found:

% Here we use the finer data:

y_fit1 = polyval(a, x1new);

y_fit2 = polyval(b, x2new);

figure (2)

plot(x1,y1,'r*', x1new,y_fit1)

fprintf('Phillip''s data were fitted with y= %3.2f x^3+ %3.2f x^2+%3.2f x+

%3.2f\n',a);

hold on

plot(x2,y2,'g*', x2new,y_fit2, 'k')

fprintf('Chris''s data were fitted with y= %3.2f x^3+ %3.2f x^2+%3.2f x+ %3.2f\

n',b);

text (.5,200,'Curve Fitting')