1: "stop" the program and the loop

return---- stop the whole program;
break------ exit the current loop:

"Save the commands in the file and run it to see the difference for the value of y:"

a)
clear all;
for i = 1:10;
if (i > 1)
break;
else
x(i) = i;
end
end
y = 2*x;

b)
clear all;
for i = 1:10;
if (i > 1)
return;
else
x(i) = i;
end
end
y = 2*x;


2: "Bisection Method to solve Example 2 (page 84)"

"func4_1.m":

function f = func4_1(x)
f = x.^3+4*x.^2-10;

"practise4_1.m":

clear all;
close all;
                                                                                                 
x = linspace(1,2,100);
y = func4_1(x);
plot(x,y);
zero = fzero(@func4_1,1)

M = 1000;
TOL = 1.0e-4;
a = 1;
b = 2;
N = 1;

                                                                                                 
while (N < M)
                                                                                                 
p = (b+a)/2.0;
FP = func4_1(p);
                                                                                                 
if (abs(FP) < TOL | (b-a)/2 < TOL)
display(p);
return;
end

FA = func4_1(a);
FB = func4_1(b);
                                                                                                 
if (FA*FP < 0)
b = p;
elseif (FB*FP < 0)
a = p;
end

N = N+1;
                                                                                                 
end
                                                                                                 
display('Method failed after 100 steps');


Remarks:

Please implement bisection method to solve No. 9 (Sec 2.1 page 51) before next class.



