'Please Enter The Value of N: ' 'Please Enter Your Equation (Function) : ' 'S'
'Please Enter The Value of N: ' 'Please Enter Your Equation (Function) : ' 'S'
'Please Enter The Value of N: ' 'Please Enter Your Equation (Function) : ' 'S'
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 ;
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
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
hermite = 0;
for i =1: n +1
end