Q=20;
g=9.81;
B=@(y)3+y;
Ac=@(y)3*y+y.^2/2;
func=@(y)(1-Q^2*B(y)./(g*Ac(y).^3));
xu=2.5;
xl=0.5;
es=0.01;
n_iter=10;
x=0.5:0.1:2.5;
plot(x,func(x),'r',x,0.*x,'b--');
[root1, f_1, e_1, n_1] = bisect(func,xl,xu,es,n_iter);
[root_2,f_2,e_2,n_2]=false_position(func,xl,xu,es,n_iter);
fprintf('Bisection method: \n');
fprintf('\t root:%g\n',root_1);
fprintf('\t function value at root:%g\n',f_1);
fprintf('\t approximate relative error:%g\n',e_1);
fprintf('\t number of iterations:%d\n\n',n_1);
fprintf('Bisection method: \n');
fprintf('\t root:%g\n',root_2);
fprintf('\t function value at root:%g\n',f_2);
fprintf('\t approximate relative error:%g\n',e_2);
5 Comments
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/664843-why-the-bisect-in-my-coding-is-undefined#comment_1165163
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/664843-why-the-bisect-in-my-coding-is-undefined#comment_1165163
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/664843-why-the-bisect-in-my-coding-is-undefined#comment_1165173
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/664843-why-the-bisect-in-my-coding-is-undefined#comment_1165173
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/664843-why-the-bisect-in-my-coding-is-undefined#comment_1165178
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/664843-why-the-bisect-in-my-coding-is-undefined#comment_1165178
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/664843-why-the-bisect-in-my-coding-is-undefined#comment_1165188
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/664843-why-the-bisect-in-my-coding-is-undefined#comment_1165188
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/664843-why-the-bisect-in-my-coding-is-undefined#comment_1165308
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/664843-why-the-bisect-in-my-coding-is-undefined#comment_1165308
Sign in to comment.