Root finder matlab code is not displaying result
2 次查看(过去 30 天)
显示 更早的评论
I wrote this code below. It works without errors. However I can't see the result.
It finds the nth root of w, starting from guess g.
w=9;
g=5;
n=2;
function result=findRoot(w,g,n)
if (abs(newGuess-g)<(g*0.0001))
result = newGuess;
disp(result);
else
newGuess = (g - g^n - w) / (n*g^(n-1));
result = findRoot(w, newGuess,n);
disp(result);
end
end
I appreciate any help. Thank you.
2 个评论
Star Strider
2019-2-10
One problem is that you are calling your function from within the function:
result = findRoot(w, newGuess,n);
This will lead to ‘infinite recursion’, and so no output.
回答(1 个)
Anand Shirke
2019-2-10
Maybe the problem is while declaring the function, I would suggest you to declare the function in this way
function [result]=findRoot(w,g,n)
..
.....
end
After saving the code, type in command window :
findRoot(9,5,2)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!