0% found this document useful (0 votes)
39 views2 pages

'Please Enter The Value of N: ' 'Please Enter Your Equation (Function) : ' 'S'

This document appears to be MATLAB code for generating a Hermite-Lagrange interpolation polynomial. It takes in user input for the number of points (n) and an equation, then calculates function and derivative values at the input points. It generates Lagrange basis polynomials and uses them to create a Hermite interpolation polynomial that approximates the original function.

Uploaded by

Abdul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

'Please Enter The Value of N: ' 'Please Enter Your Equation (Function) : ' 'S'

This document appears to be MATLAB code for generating a Hermite-Lagrange interpolation polynomial. It takes in user input for the number of points (n) and an equation, then calculates function and derivative values at the input points. It generates Lagrange basis polynomials and uses them to create a Hermite interpolation polynomial that approximates the original function.

Uploaded by

Abdul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

% h e r m i t e _ l a g r a n g e .

clc

clear
n = input ( 'Please enter the value of n: ') ;
s t r i n g _ e q u a t i o n = input ( 'Please enter your equation ( function ): ' , 's') ;
v a r i a b l e _ e q u a t i o n = sym ( s t r i n g _ e q u a t i o n ) ;
syms x ;

L = sym ( 'x' ,[1 n +1]) ;

P = zeros (1 , n ) ;

FUN = m a t l a b F u n c t i o n ( v a r i a b l e _ e q u a t i o n ) ;

f = zeros (1 , n +1) ;

df = zeros (1 , n +1) ;

for i =1: n +1

P ( i ) = input ( 'Enter point : ') ;

f ( i ) = subs ( variable_equation ,x , P ( i ) ) ;

df ( i ) = subs ( diff ( v a r i a b l e _ e q u a t i o n ) ,x , P ( i ) ) ;

end

p o l y n o m i a l _ x =0;

for j =1: n +1

num =1;

den =1;

for i =1: n +1
if ( i ~= j )

num = num *( x - P ( i ) ) ;

den = den *( P ( j ) -P ( i ) ) ;

end

end

L ( j ) = num / den ;

y = feval ( FUN , P ( j ) ) ;

polynomial_x=polynomial_x+y*L(j);

end

%%% g e n e r a t i n g hermite ploynomial

hermite = 0;

for i =1: n +1

h ( i ) = (1 - 2*( x - P ( i ) ) * subs ( diff ( L ( i ) ) ,x , P ( i ) ) ) * L ( i ) .^2; hhat ( i ) = (x - P (


i ) ) * L ( i ) .^2;

hermite = hermite + f ( i ) * h ( i ) + df ( i ) * hhat ( i ) ;

end

You might also like