Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numerical Methods.  If (n+1) number of points are given, (n+1) number of equations can be formed using a (n+1) order polynomial  The equations can be.

Similar presentations


Presentation on theme: "Numerical Methods.  If (n+1) number of points are given, (n+1) number of equations can be formed using a (n+1) order polynomial  The equations can be."— Presentation transcript:

1 Numerical Methods

2  If (n+1) number of points are given, (n+1) number of equations can be formed using a (n+1) order polynomial  The equations can be arranged in matrix form [Y]=[C][A]  [Y] is a column matrix consisting of ‘y’ values of the given points  [C] is (n+1) X (n+1) sized square matrix having different terms consisting of power of ‘x’ values of the given points  [A] is the co-efficient matrix which is consisting of the unknown to be determined to find the polynomial  [A] is obtained from [A]=[C] -1 [Y] 2

3 % Direct Polynomial n = 3; x = [6,8,10,12]; y = [80,120,160,240]; xu = 9; % formation of [C] matrix of the equation [Y]=[C][A] for i = 1:(n+1) for j = 1:(n+1) c(i,j) = x(i)^(j-1); end Prof. S. M. Lutful Kabir, BRAC University3

4 % determination of inverse of [C] matrix, [CI] ci = inv(c); % determination of the coefficient matrix [A] by [CI][Y] for i = 1:(n+1) a(i) = 0.0; for j=1 : (n+1) a(i) = a(i) + ci(i,j)*y(j); end % determination of interpolated value of Y for the value, Xu fxu = 0.0; for i=1:(n+1) fxu=fxu + a(i) * xu^(i-1); end 4

5  The Lagrangian interpolating polynomial is given by where n in f n (x) stands for the nth order polynomial that approximates the function y=f(x) given at n+1 data points as (x 0,y 0 ), (x 1,y 1 ), (x 2,y 2 ),……. (x n-1,y n-1 ), (x n, y n ) and L i (x) is a weighting function that includes a product of n-1 terms with terms of j = i omitted. 5Prof. S. M. Lutful Kabir, BRAC University

6 % Lagrangian Polynomial n = 3; x = [6,8,10,12]; y = [80,120,160,240]; xu = 9; % Determination of Lagrangian Polynomial values for x=x u for i = 1:n+1 L(i) = 1.0; for j = 1:n+1 if j ~= i L(i) = L(i) * (xu - x(j)) / (x(i) - x(j)); end 6

7 % determination of value of the function at x=x u fxu = 0.0; for i = 1:n+1 fxu = fxu + L(i) * y(i); end Prof. S. M. Lutful Kabir, BRAC University7

8  For an example of a third order polynomial, given ( x 0, y 0 ), ( x 1, y 1 ) and ( x 2, y 2 ) 8 x0x0 x1x1 x2x2 x3x3 f (x 0 ) f (x 1 ) f (x 2 ) f (x 3 ) f [x 1,x 0 ] f [x 2,x 1 ] f [x 3,x 2 ] f [x 2,x 1, x 0 ] f [x 3,x 2, x 1 ] f [x 3,x 2,x 1, x 0 ] b0b0 b1b1 b2b2 b3b3 Prof. S. M. Lutful Kabir, BRAC University

9 % Newton Divided Difference Polynomial n = 3; x = [6,8,10,12]; y = [80,120,160,240]; xu = 9; % formation first column of bracketed ‘f’ table j = 1; for i = 1:(n+1) f(i,j) = y(i); end 9

10 Prof. S. M. Lutful Kabir, BRAC University10 % formation other columns of bracketed ‘f’ table for j = 2:(n+1) for i = 1:(n-j+2) f(i,j) = (f(i+1,j-1) - f(i,j-1)) / (x(i+j-1)-x(i)); end % formation of b 1, b 2, b 3, b 4 ……..b n+1 for j = 1:(n+1) b(j) = f(1,j); end

11 Prof. S. M. Lutful Kabir, BRAC University11 % determination of y value for the unknown x=x u fxu = b(1); for i = 2:(n+1) prod = 1.0; for j = 1:(i-1) prod = prod*(xu-x(j)); end fxu = fxu + b(i) * prod; end

12 Thanks Prof. S. M. Lutful Kabir, BRAC University12


Download ppt "Numerical Methods.  If (n+1) number of points are given, (n+1) number of equations can be formed using a (n+1) order polynomial  The equations can be."

Similar presentations


Ads by Google