Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
199.000000 52.000000
251.000000
The final value of yg:70.375000>>
PROGRAM FOR NEWTON BACKWARD DIFFERENCE METHOD
n=input('enter the no. of elements n');
for i=1:n
x(i)=input('enter the value of x:');
y(i,1)=input('enter the value of y:');
end
xg=input('enter the value of xg:');
h=x(2)-x(1);
c=1;
for j=2:n
c=c+1;
for i=n:-1:c
y(i,j)=y(i,j-1)-y(i-1,j-1);
end
end
c=1;
for i=2:n
fprintf('\n\n');
c=c+1;
for j=2:c
fprintf ('\t%f',y(i,j));
end
end
u=(x(n)-xg)/h;
ans=y(n,1)-u*y(n,2);
yg=0;
m=2;
u1=u;
for k=3:n
if(m<k)
u=u*(u1-(m-1));
end
fact=1;
for i=1:k-1
fact=fact*i;
end
if (mod (k,3)==0)
yg=yg+((u/fact)*y(n,k));
else
yg=yg-((u/fact)*y(n,k));
end
m=m+1;
end
yg=ans+yg;
fprintf('\nThe final value of yg:%f',yg);
0.200000 0.040000
14.875000 5.250000
20.125000
The value dydx=4.750000>>
PROGRAM FOR NEWTON BACKWARD DIFFERENCE (DIFFERENTIATION) METHOD
n=input('enter the no. of elements n');
for i=1:n
x(i)=input('enter the value of x:');
y(i,1)=input('enter the value of y:');
end
xg=input('enter the value of xg:');
h=x(2)-x(1);
c=1;
for j=2:n
c=c+1;
for i=n:-1:c
y(i,j)=y(i,j-1)-y(i-1,j-1);
end
end
c=1;
for i=2:n
fprintf('\n\n');
c=c+1;
for j=2:c
fprintf ('\t%f',y(i,j));
end
end
for i=n:-1:1
if (xg==x(i))
m=i;
end
end
ans=y(m,2);
dydx=0;
for k=3:n
dydx=dydx+((y(m,k))/(k-1));
end
dydx=ans+dydx;
dydx=dydx/h;
fprintf('\nThe value dydx=%f',dydx);
enter the no. of elements n5
enter the value of x:0
enter the value of y:1
enter the value of x:10
enter the value of y:0.984
enter the value of x:20
enter the value of y:.939
enter the value of x:30
enter the value of y:0.866
enter the value of x:40
enter the value of y:0.766
enter the value of xg:40
-0.016000
-0.045000 -0.029000
L1.000000=-0.657143
L2.000000=1.597222
L3.000000=0.060847
L4.000000=-0.000926
The final value of xg:1.716138>>