开发用于查找根的Secant方法程序(Developing a Secant Method Program for root finding)

编程入门 行业动态 更新时间:2024-10-28 12:22:49
开发用于查找根的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 end

The 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.

更多推荐

本文发布于:2023-07-27 15:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292455.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   方法   Developing   Secant   root

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!