Copy and paste this code into MatLab to try these simple programs!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This is a little program to say “Hello.”
%%%%%%%%%%%%%%%%%%%%%%%%%%%
name=input('What is your name? ', 's');
fprintf('Hello %s! \n', name)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% This program will find the root of a function using the bisection % method.
%%%%%%%%%%%%%%%%%%%%%%%%%%%
%select the left and right limits
l=0;
r=2;
for i=0:10
c=(l+r)/2; %define midpoint
if (l^3-2)*(c^3-2)>0 %for f(a)*f(c)>0, set right endpoint as b
l=c;
else
if (r^3-2)*(c^3-2)>0 %for f(a)*f(c)>0, set left endpoint as a
r=c;
end
end
fprintf ('c=%d.\n',c);
end
Downloaded from http://www.wikihow.com