Matlab - program won't stop calculating
2 次查看(过去 30 天)
显示 更早的评论
My program I created is using a simple bisection method to calculate a root, but it just keeps running. Any thoughts on how to fix my code to stop this?
myFunction = @(x) 9*(x^4) + 18*(x^3) + 38*(x^2) - 57*x +14;
format long
a = 0; % lower limit
b = 1; % upper limit
c = (a + b) / 2;
while abs(myFunction(c)) > 0.01
if (myFunction(a)*myFunction(c)) < 0
a = c;
else
b = c;
end
c = (a + b) / 2;
end
fprint('The root is %g\n', c)
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!