PDA

View Full Version : الگوریتم درونیابی برام اجرای کنید



LALA90
یک شنبه 21 خرداد 1385, 12:03 عصر
program divdif(input,output);
(*
this program uses the divided differences to get the
interpollating polynomial that goes through a given set of data points
PROCEDURE ddcoef finds the coefficents of the interpolating polynomial
FUNCTION ddvalue uses the coefficients of the previous
PROCEDURE to evaluate the polynomial at a give value:xhat.
*)
type
vector=arry[i....i.]ofreal;
var
x,y,dd :vector; (*x.y:thegiven data points.*)
i,j.n :integer (*dd:the vecter of coefficients for p(x)*)
(*
***ddcoef***
*)
procedure ddcoef(x,y:vector;uar dd:vector;n:integer);
(*
input:x,y_the givendata points
n-the number of data points
output:dd-the coefficients of p(x),i,e,f[(,,)]
*)
var
i,j,k :integer
tenp1 ,temp2:real:
begin(*ddcoef*)
for i:1to n do dd[i]:=y[j];
for j:2 to n do begin
temp1:=dd[j-1];writeln;
for k:=j to n do begin
temp2:=dd[k];
dd[k]:=(dd[k]-temp1)(x[k]-x[k-j+1]);
temp1=temp2 end(*for*)
end(*for j loop*)
end;(*ddcoef*)
(*
***ddvalue***
*)
function ddvalue (u:real):real;
input:xhat
output:ddvalue_the corresponding
y_value,i,e,p(xhat)
*)
var
sum:real;
i =integer
begin(*divdif*)
sum:0,0;
(*compute value by nested multiplication from hhighest term*)
for i:n down to 2 do sum:=(sum+dd[i])*(u-x[i-1]);
sum:sum+dd[1];
ddvalue:=sum
end;(function ddvalue*)
(*
*)
begin(*mainprogram*)
(*
set up four data points
*)
n:=4;x[1]:=8.0;x[2]:=9.0;x[3]:=9.5; x[4]:=11.0;
y[1]:2.07,442;y[2]:=2.1,7225;y[3]:=2.25,1292;y[4]:=2.3978,5;
(*
generate the coefficients for the poly nomial
*)
ddcoef(x,y,dd,n); (*compute coefficients*)
writeln(,,);
writeln('the coeficients for the polynomial are:');
for i=1 to n do write(dd[i]:8:6,'');
writeln(''); writeln('');
writeln('':15, '**********'); writeln('');
writeln('x':17,'p(x)':10);
writeln('');
(*
*)
xhat:=9.2;
writeln(xhat:18:1,ddvalue(xhat):10:6);
writel('');
writeln('':15,'**********');
writeln('');
end.

mohandese_hiclass
دوشنبه 22 خرداد 1385, 19:17 عصر
fبا تریس خط به خط بری زودتز به جواب می رسی تا کسی کدتو بخونه سر در بیاره و راهنماییت کنه