# Question:How to transfer code to matlab?

## Question:How to transfer code to matlab?

Maple

restart: with(plots):
bisect:=proc(f, intbeg::numeric, intend::numeric, ss::float, del::float)
local Num_points,limit1,approx,i,x1,x2,a,b,flag1,pet,A,B,NewApprox,CheckIt,newDelta,
interval_begin,interval_end,step_size,delta, y_approx, y_A, y_New;

interval_begin:=intbeg:
interval_end:=intend:
step_size:=ss:
delta:=del:
Num_points:=0:
print([x,y]);
limit1:=200:

for i from interval_begin by step_size to interval_end do
x1:=i:
x2:=i+step_size:
if x1=0 then x1:=-10^(-5)fi:
if x2=0 then x2:=-10^(-5)fi:
a := evalf( f(x1) ):
b := evalf( f(x2) ):
if a=0 then a:=-10^(-5)fi:
if b=0 then b:=-10^(-5)fi:
flag1:=0:

if evalf(a*b) <= 0 then
approx := (x1+x2)/2:
y_approx := evalf( f(approx) ):
if abs(y_approx) < delta then
print([approx, y_approx]):
Num_points:=Num_points+1:
else
pet:=0:
A:=x1:
B:=x2:
while pet=0 do
NewApprox:=(A+B)/2:
y_A := evalf( f(A) );
y_New := evalf( f(NewApprox) );
CheckIt := y_A * y_New:
newDelta:=abs( y_A - y_New ):
flag1:=flag1+1:

if newDelta <= delta then
print([NewApprox, y_New]):
pet:=1:
Num_points:=Num_points+1:
elif CheckIt > 0 then
A:=NewApprox;
else
B:=NewApprox;
fi:

if flag1 > limit1 then
pet:=1:
print(`*** Exceeds limits****`);
fi:
od:
fi:
fi:

od:

print(`Number of Roots Found = `,Num_points):
plot(f(x), x=interval_begin..interval_end, color=red, thickness=1);

end:

﻿