This document contains 4 programs (P1, P2, P3, P4) that use the bisection method to find the root of different functions f(x). Each program defines variables a, b, c to represent the lower bound, upper bound, and midpoint for iterative bisection. They input n and iterate calculating c and updating a or b until the difference between a and b is less than a tolerance e, converging on the root of f(x) between the bounds.
This document contains 4 programs (P1, P2, P3, P4) that use the bisection method to find the root of different functions f(x). Each program defines variables a, b, c to represent the lower bound, upper bound, and midpoint for iterative bisection. They input n and iterate calculating c and updating a or b until the difference between a and b is less than a tolerance e, converging on the root of f(x) between the bounds.
This document contains 4 programs (P1, P2, P3, P4) that use the bisection method to find the root of different functions f(x). Each program defines variables a, b, c to represent the lower bound, upper bound, and midpoint for iterative bisection. They input n and iterate calculating c and updating a or b until the difference between a and b is less than a tolerance e, converging on the root of f(x) between the bounds.
var a,b,c: real; var a,b,c: real; i,n:integer; i,n:integer; function f(x:real):real; function f(x:real):real; begin f:=exp(x)- sqr(x); begin f:=x*sqr(x)-x-1; end; end; begin begin a:=-1; a:=1; b:=-0.5; b:=2; writeln ('introducem numarul n='); writeln ('introducem numarul n='); readln(n); readln(n); for i:=1 to n do for i:=1 to n do begin c:=(b+a)/2; begin c:=(b+a)/2; writeln('c=',c); writeln('c=',c); if f(c)=0 then break if f(c)=0 then break else if f(c)*f(a)>0 then a:=c else if f(c)*f(a)>0 then a:=c else b:=c; else b:=c; end; end; end. end Program P3; Program P4; var a,b,c: real; var a,b,c: real; i,n:integer; function f(x:real):real; i,n:integer; function f(x:real):real; begin f:=x*sqr(x)+3*sqr(x)-3; begin f:=x*sqr(x)*sqr(x)-x-2; end; end; begin begin a:=-3; a:=1; b:=-2; b:=2; writeln ('introducem numarul n='); writeln ('introducem numarul n='); readln(n); readln(n); for i:=1 to n do for i:=1 to n do begin c:=(b+a)/2; begin c:=(b+a)/2; writeln('c=',c); writeln('c=',c); if f(c)=0 then break if f(c)=0 then break else if f(c)*f(a)>0 then a:=c else if f(c)*f(a)>0 then a:=c else b:=c; else b:=c; end; end; end end. 1 Ex.3(b) pag.26
Program P1; Program P2;
var a,b,c,e: real; var a,b,c,e: real; function f(x:real):real; function f(x:real):real; begin f:=exp(x)-sqr(x); begin f:=x*sqr(x)-x-1; end; end; begin e:=0.001; begin e:=0.00001; a:=-1; a:=1; b:=-0.5; b:=2; repeat c:=(b+a)/2 repeat c:=(b+a)/2; writeln('c=',c); writeln('c=',c); if f(c)=0 then break if f(c)=0 then break else if f(c)*f(a)>0 then a:=c else if f(c)*f(a)>0 then a:=c else b:=c; else b:=c; until (abs(b-a)<e); until (abs(b-a)<e); end. end. Program P3; Program P4; var a,b,c,e: real; var a,b,c,e: real; function f(x:real):real; function f(x:real):real; begin f:=x*sqr(x)+3*sqr(x)-3; begin f:=x*sqr(x)*sqr(x)-x-2; end end; begin e:=0.0001; begin e:=0.001; a:=-3; a:=1; b:=-2; b:=2; repeat c:=(b+a)/2; repeat c:=(b+a)/2; writeln('c=',c); writeln('c=',c); if f(c)=0 then break if f(c)=0 then break else if f(c)*f(a)>0 then a:=c else if f(c)*f(a)>0 then a:=c else b:=c; else b:=c; until (abs(b-a)<e); until (abs(b-a)<e); end end.