fed up of doing calculations by hand to find the roots of an equation by "BISECTION METHOD" (one of the bracketing techniques to solve an equation) the solution is simple and reliable write a piece of MATLAB code.Cant do this???? thats what i am here for !! here is the required code !! this code will
1.find the mean value at each iteration
2.plot the graph of true error
3.plot graph of approximate error
change the function and initial bracket according to your requirements!!
here is the code
clc
clear all
close all
xl=0;
xu=1;
xr=0;
ethresh=2;
xt=0.5671;
et=[];
ea=[];
for i=1:10
f_xl = exp(-xl)-xl;
f_xu = exp(-xu)-xu;
bracket = [xl xu];
xrold=xr;
xr=(xl+xu)/2
ea(i)=abs((xr-xrold)*100/xr);
et(i)=(xr-xt)/xr;
f_xr=exp(-xr)-xr;
if(f_xl*f_xr<0)
xu=xr;
else if(f_xu*f_xr<0)
xl=xr;
else
ea=0;
end
next_bracket=[xl xu]
end
end
plot(1:length(et),et,'r')
grid on
hold on
plot(1:length(ea),ea,'b')
1.find the mean value at each iteration
2.plot the graph of true error
3.plot graph of approximate error
change the function and initial bracket according to your requirements!!
here is the code
clc
clear all
close all
xl=0;
xu=1;
xr=0;
ethresh=2;
xt=0.5671;
et=[];
ea=[];
for i=1:10
f_xl = exp(-xl)-xl;
f_xu = exp(-xu)-xu;
bracket = [xl xu];
xrold=xr;
xr=(xl+xu)/2
ea(i)=abs((xr-xrold)*100/xr);
et(i)=(xr-xt)/xr;
f_xr=exp(-xr)-xr;
if(f_xl*f_xr<0)
xu=xr;
else if(f_xu*f_xr<0)
xl=xr;
else
ea=0;
end
next_bracket=[xl xu]
end
end
plot(1:length(et),et,'r')
grid on
hold on
plot(1:length(ea),ea,'b')
Hello there! Do you use Twitter? I'd like to follow you if that would be ok. I'm undoubtedly enjoying your blog and look forward to new updates.
ReplyDeleteFeel free to surf to my web site - bmi calculator
Appreciate this post. Let me try it out.
ReplyDeleteAlso visit my weblog: free minecraft account
e cig reviews, electronic cigarettes, buy electronic cigarette, smokeless cigarettes, e cigarettes, ecig
ReplyDeleteCasino site, bonus, promotions and much more!
ReplyDeleteThis bonus is one of the best casinos to get started with. You can sign up and start playing, earn luckyclub.live money or play at a casino site!