ФЭА / Информатика / Турбо паскаль программа Золотое сечение
(автор - student, добавлено - 26-05-2014, 20:33)
program zol; uses crt; function f(x:real):real; begin f:=(exp(x+3)*ln(1/3))-2; end; var tau:real; a,b,eps:real; x1,x2,f1,f2,gi,xr,yr:real; begin tau:=(sqrt(5)-1)/2; clrscr; writeln(''); writeln; write(' A= '); readln(a); write(' B= '); readln(b); write(' E= '); readln(eps); writeln; x1:=a+(1-tau)*(b-a); x2:=a+tau*(b-a); f1:=f(x1); f2:=f(x2); gi:=(b-a)/2; while gi>eps do begin if f1<=f2 then begin b:=x2; x2:=x1; f2:=f1; x1:=a+b-x2; f1:=f(x1); end else begin a:=x1; x1:=x2; f1:=f2; x2:=a+b-x1; f2:=f(x2); end; gi:=gi*tau; end; xr:=(a+b)/2; yr:=f(xr); writeln('X= ',xr:5:5,' Y= ',yr:5:5); readkey; end. Program Zolotoe_sechenie; uses crt; var a,b,e,t,x,x1,x2,y1,y2,yr:real; i:integer; function f(y:real):real; begin f:=exp(x)-x*x+3; end; begin clrscr; writeln('Vvedite znachenie a'); readln(a); writeln('Vvedite znacheniya b'); readln(b); writeln('Vvedite tochnost '); readln(e); begin i:=0; t:=(sqrt(5)-1)/2; x1:=b-(b-a)*t; x2:=a+(b-a)*t; y1:=f(x1); y2:=f(x2); while abs(b-a)>=e do begin i:=i+1; if y1>y2 then begin a:=x1; x1:=x2; y1:=y2; x2:=a+(b-a)*t; y2:=f(x2); end else begin b:=x2; x2:=x1; x1:=b-(b-a)*t; y1:=f(x1); end; end; x:=(a+b)/2; yr:=f(x); writeln(' Znacheniya minimuma x=', x:7:5,' Y= ', yr:7:5 ); end; readkey; end.
Program Zol; uses crt; var a,b,e,t,x,x1,x2,y1,y2,fr:real; var i:integer; function f(y:real):real; begin f:=exp((x-1)*ln(5))-2; end; begin writeln('Vvedite znachenie nignei granizi otrezka localizacii a'); readln(a); writeln('Vvedite znacheniya verkhnei granizi otrezka localizacii b'); readln(b); writeln('Vvedite tochnost vichizlenii e'); readln(e); begin i:=0; t:=(sqrt(5)-1)/2; x1:=b-(b-a)*t; x2:=a+(b-a)*t; y1:=f(x1); y2:=f(x2); while abs(b-a)>=e do begin i:=i+1; if y1>y2 then begin a:=x1; x1:=x2; y1:=y2; x2:=a+(b-a)*t; y2:=f(x2); end else begin b:=x2; x2:=x1; x1:=b-(b-a)*t; y1:=f(x1); end; end; x:=(a+b)/2; fr:=f(x); writeln(' Znacheniya tochki minimuma x=', x:7:5,' Y= ', fr:7:5 ); end; readkey; end.
program zol; uses crt; function f(x:real):real; begin f:=4*x*x*x*x*x*x*x*x+3*x*x*x*x*x*x*x+5*x*x*x*x*x*x-9; end; var tau:real; a,b,eps:real; x1,x2,f1,f2,gi,xr,yr:real; begin tau:=(sqrt(5)-1)/2; clrscr; writeln(''); writeln; write(' A= '); readln(a); write(' B= '); readln(b); write(' E= '); readln(eps); writeln; x1:=a+(1-tau)*(b-a); x2:=a+tau*(b-a); f1:=f(x1); f2:=f(x2); gi:=(b-a)/2; while gi>eps do begin if f1<=f2 then begin b:=x2; x2:=x1; f2:=f1; x1:=a+b-x2; f1:=f(x1); end else begin a:=x1; x1:=x2; f1:=f2; x2:=a+b-x1; f2:=f(x2); end; gi:=gi*tau; end; xr:=(a+b)/2; yr:=f(xr); writeln('X= ',xr:5:5,' Y= ',yr:5:5); readkey; end.
Похожие статьи:
|
|