Practice with MATLAB Functions - Computer Assignment 2 | MATH 435, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Material Type: Assignment; Professor: Datta; Class: Numerical Analysis; Subject: MATHEMATICAL SCIENCES; University: Northern Illinois University; Term: Spring 2009;

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-jrm
koofers-user-jrm 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
MATH 435 Computer Homework #2
Spring 2009 Prof. Biswa Nath Datta
DUE : MARCH 16, 2009
1. Using the built-in MATLAB functions conv and poly, write a MATLAB function
lgrnintp in the following format:
function [P, Z ] = lgrnintp (X , Y ),
where Xand Yare vectors containing respectively x- and y-values, Pis the vector
containing the coefficients of the Lagrangian interpolating polynomial and Zis the
vector containing values of the interpolating polynomial at the nontabulated points
x=z.
Data for Problem 1
1. f(x) = cos x
x y
0 1
1 0.5403
2 -0.4161
3 -0.9900
4 -0.6536
5 0.2837
2. f(x) = ex
x y
0 1
1 .3679
2 0.1353
3 0.0498
4 0.0183
5 0.0067
Presentation of Results
The results should be presented in the following format:
TABLE 1: Results for Lagrangian Interpolation
pf2

Partial preview of the text

Download Practice with MATLAB Functions - Computer Assignment 2 | MATH 435 and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

MATH 435 Computer Homework

Spring 2009 Prof. Biswa Nath Datta

DUE : MARCH 16, 2009

  1. Using the built-in MATLAB functions conv and poly, write a MATLAB function lgrnintp in the following format:

function [P, Z] = lgrnintp (X, Y ),

where X and Y are vectors containing respectively x- and y-values, P is the vector containing the coefficients of the Lagrangian interpolating polynomial and Z is the vector containing values of the interpolating polynomial at the nontabulated points x = z.

Data for Problem 1

  1. f (x) = cos x x y 0 1 1 0. 2 -0. 3 -0. 4 -0. 5 0.
  2. f (x) = e−x x y 0 1 1. 2 0. 3 0. 4 0. 5 0.

Presentation of Results The results should be presented in the following format:

TABLE 1: Results for Lagrangian Interpolation

P : The coefficient of the in- terpolation polynomial

z P (z) f (z) Error = f (z) − P (z)

Practice with MATLAB Functions

  1. MATLAB function interp1 in the form

Y I = interp1(X, Y, Z, ‘method’ )

interpolates to find Y I at the values contained in the vector Z from a table of values of X and Y (X and Y are vectors containing the x- and y-values). The available methods are: nearest - nearest neighbor interpolation linear - linear interpolation spline - cubic spline interpolation cubic - cubic interpolation.

Using this function and each of the available methods, find the approximate values of both the functions cos x and e−x^ at the points contained in the vector Z of TABLE 1.

Compare the results with those obtained by Lagrangian method and write your observations.

  1. Write the output of the following program:

x = 0 : 20; y = ex; xi = 0 : .50 : 10; yi = interp1 (x, y, xi); plot (x, y, ‘o’, xi, yi).