A combination of bisection and secant method
Show older comments
Hello! So I have to write a program on Matlab using both the bisection and secant method in one. I'm super new to Matlab and this is the code I managed to figure out. The program tells me that when I call a function, I have to use parentheses. But I don't see where I should put that. I've also attached the required steps for the program. Thank you!
function p = bisection(f, a, b, tol)
w=1;
for i=1:100
p= a +(w*f(a)*(a-b)/f(b)-w*f(a));
fprintf(a,b,p,f(p));
if f(p)*f(b)>0
w=0.5;
else
w=1;
a=b;
end
b=p;
if abs(b-a)<tol || abs(f(p))<tol
break;
end
end
1 Comment
Lavorizia Vaughn
on 28 Sep 2021
I think you just need to out parents around the p in function p
Answers (0)
Categories
Find more on Entering Commands in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!