I'm unsure as to why MATLAB is returning an infinite root no matter the initial guess. Can someone help with this?
Show older comments
%% False-position root finder
function FP_iteration_root_finder
clear
clc
close all
Bi = 4.8; %initial guess for root
ea = 0.0001; %maximum percent (%) difference btw iterations
error = 100; %initialize error as something large
while error > ea
Bi_plus_1 = the_function(Bi)+Bi; %eval y2 and set equal to y1
error = abs((Bi_plus_1-Bi)/Bi_plus_1)*100; %compare difference
Bi = Bi_plus_1; %update xi
B=linspace(0,10);
y=the_function(B);
plot(B,y)
xlabel('B')
ylabel('y')
legend('Function','FontSize',12)
end
root = Bi %report root
end
%% function for which root is to be found
function [y] = the_function(B)
y = (cos(B).*cosh(B))+ 1;
end
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!