Skip to content

Instantly share code, notes, and snippets.

@kuzemkon
Created October 4, 2014 20:43
Show Gist options
  • Save kuzemkon/ba917968365199e665e6 to your computer and use it in GitHub Desktop.
Save kuzemkon/ba917968365199e665e6 to your computer and use it in GitHub Desktop.
program project1;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, crt
{ you can add units after this };
var E,a,b,c,Fa,Fb,Fc,x: Real;
function f(x: Real):Real;
begin
f:=(sin(x)/cos(x))-((((sin(x)/cos(x))*(sin(x)/cos(x))*(sin(x)/cos(x)))+1)/3)+(0.2*((sin(x)/cos(x))*(sin(x)/cos(x))*(sin(x)/cos(x))*(sin(x)/cos(x))*(sin(x)/cos(x))));
end;
Begin
Writeln('Enter limit a, b and accuracy E');
Readln(a,b,E);
Fa:=f(a);
Fb:=f(b);
Fc:=f(c);
Repeat
Begin
If (Abs(Fa)<E)
then writeln('x=',a)
else
If (Abs(Fb)<E)
then writeln('x=',b)
End;
Begin
c:=(a+b)/2;
End;
Begin
If (Fa*Fc<0)
then c:=b
else
If (Fc*Fb<0)
then c:=a
End;
until (b-a<E);
Begin
Writeln('x=',c:5:3);
End;
Readkey;
End.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment