开发用于查找根的Secant方法程序(Developing a Secant Method Program for root finding)
所以我一直在试图开发一个割线方法程序,可以用来找到它的根
f(x)= tanh(x) - (x / 3)
然而答案的输出并不完全。 我找到的每个解决方案似乎都是解决它的更复杂的方法。
x = 2; prevx = x; for i = 1:20 x = x - (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3)))); prevx = prevx + x; x end答案应该是2.987。 尽管出于某种原因我得到了一个负数。
So I have been trying to develop a secant method program that can be used for finding the root of
f(x) = tanh(x) - (x / 3)
However the answer output is nowhere close. Every solution I have found seems a more complex way to solve it.
x = 2; prevx = x; for i = 1:20 x = x - (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3)))); prevx = prevx + x; x endThe answer should be 2.987. I am getting a negative number though for some reason.
最满意答案
你应该在这一行中加上术语来代替minus:
x = x - (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3))));加上:
x = x + (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3))));为了得到x的理想结果2.987 。 在循环结束之前还要删除x。
You suppose to add up terms so replace minus in this line:
x = x - (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3))));To a plus:
x = x + (tanh(x)-(x/3))*((x-(prevx))/((tanh(x)-(x/3))-(tanh(prevx))-((prevx/3))));To get a desired result of 2.987 for x. Also remove x before the end of the loop.
更多推荐
发布评论