[Content_Types].xml
_rels/.rels
documentation/doc.xml
matlab/document.xml
matlab/output.xml
metadata/coreProperties.xml
metadata/mwcoreProperties.xml
metadata/mwcorePropertiesExtension.xml
metadata/mwcorePropertiesReleaseInfo.xml
bisection_example bisection_example is a live function
function bisection_example%(xlg,xug)
prompt = {‘Enter lower bound:’,’Enter upper bound:’};
dlgtitle = ‘Input’;
dims = [1 35];
definput = {”,”};
answer = inputdlg(prompt,dlgtitle,dims,definput);
func = @(x) x.^3-x;%str2func(answer{3});
%promptl = ‘Enter a lower bound: ‘;
xl = [str2double(answer{1})];
%promptu = ‘Enter an upper bound: ‘;
xu = [str2double(answer{2})];
fl = func(xl(1));
fu = func(xu(1));
%figure(1);
figure(‘Visible’,”on”)
x = linspace(-1.5,1.5,200);
f = func(x);
plot(x,f);
hold on
xlower = [xl(1) xl(1)];
flower = [0 fl];
xupper = [xu(1) xu(1)];
fupper = [0 fu];
interval = [xl(1) xu(1)];
plot(xlower, flower,’r.-‘);
plot(xupper,fupper,’r.-‘);
str = {sprintf(‘x_{l}=%4.3f’,xlower(1)),sprintf(‘x_{u}=%4.3f’,xupper(1))};
text([xl(1)+0.05,xu(1)+0.05],[-0.15,-0.15],str);
plot([xl(1)-1 xu(1)+1],[0 0],’k-‘);
plot(interval,[0 0],’r-‘,’LineWidth’,2);
%linkdata(fig,’on’)
text(-1.2,1.8,{‘Choose whether to move x_{l} or x_{u} to x_{r}’})
xlim([-1.43,1.43]);
ylim([1.2*min(f),1.2*max(f)]);
if fu*fl>0
% linkdata(fig,’off’)
text(-1,-1.25,’Your interval does not enclose the root’)
return
%elseif max([abs(fu), abs(fl)])
c(i) = (xl(i)+xu(i))/2;
fc = func(c(i));
xcenter = [c(i) c(i)];
fcenter = [0 fc];
plot(xcenter,fcenter,’g.-‘);
str2 = {sprintf(‘x_{r}=%4.3f’,c(i))};
text([c(i)+0.05],[-0.15],str2);
hold off
% linkdata(fig,’on’)
if abs(fc)<10^-10
%linkdata(fig,'off')
out = 4;
break
end
% prompt3 = 'Choose whether to move xl to xr or xu to xr by typing "Lower" ar "Upper": ';
% choice = input(prompt3,'s');
axh = gca;
axh.Toolbar = matlab.ui.controls.AxesToolbar();
[xinput, yinput] = ginput(1)
if xinput
xl(i+1) = xl(i);
xu(i+1) = c(i);
else
%linkdata(fig,’off’)
out = 1;
break
end
i = i+1;
fu = func(xu(i));
fl = func(xl(i));
xlower = [xl(i) xl(i)];
flower = [0 fl];
xupper = [xu(i) xu(i)];
fupper = [0 fu];
interval = [xl(i) xu(i)];
f = func(x);
plot(x,f);
hold on
for j=1:length(xl)-1
plot([xl(j) xl(j)],[0 func(xl(j))],’Color’,[0 0 0]+0.5);
plot([xu(j) xu(j)],[0 func(xu(j))],’Color’,[0 0 0]+0.5);
end
plot(xlower, flower,’r.-‘);
plot(xupper,fupper,’r.-‘);
plot([-1.43,1.43],[0 0],’k-‘);
plot(interval,[0 0],’r-‘,’LineWidth’,2);
str3 = {sprintf(‘x_{l}=%4.3f’,xlower(1)),sprintf(‘x_{u}=%4.3f’,xupper(1))};
text([xl(i)-0.3,xu(i)+0.05],[-0.15,0.15],str3);
text(-1.2,1.8,{‘Choose whether to move x_{l} or x_{u} to x_{r}’})
xlim([-1.43,1.43]);
ylim([1.2*min(f),1.2*max(f)]);
if fl*fu>0
%linkdata(fig,’off’)
out=2;
break
end
out=0;
end
if out==1
text(-1,-1.25,’Please choose a point within the figure’)
elseif out==2
text(-1,-1.25,’Notice that f(x_{l})f(x_{r})>0′)
elseif out==4
text(-1,-1.25,sprintf(‘The root lies at %4.3f’,c(end)))
text(-1,-1.6,sprintf(‘This was computed in %d iterations\n’,i-1))
else
text(-1,-1.25,sprintf(‘The root lies in the interval [%4.3f %4.3f]’,xl(i),xu(i)))
text(-1,-1.6,sprintf(‘This was computed in %d iterations\n’,i-1))
end
end
manual code ready
2020-03-08T11:51:58Z 2020-08-07T01:43:09Z
application/vnd.mathworks.matlab.code MATLAB Code R2020a
9.8.0.1298242 90a4d63e-3dd1-4eec-a3b9-d1c377537da3
9.8.0.1417392
R2020a
Update 4
Jun 24 2020
1882048