| 查看: 444 | 回复: 1 | ||
[求助]
Sine Approximation 已知angle&阈值,返回terms值
|
|
输入两个参量X 和 threshold. 逐渐添加terms值,直到满足 abs((true 􀀀-approx)/true)< threshold ; true 是系统built-in 方程式sin(x)。 sin(x) = x 􀀀- x^3/3! + x^5/5! - x^7/7!+... 方程式要返回2值。 approx和terms(添加了几个数) 输入X=pi/5, threshold=1e-6时,显示如下: >> format long >> x = pi/5; >> threshold = 1e-6; >> [approx, terms] = approx_sine(x, threshold) approx = 0.587785210384344 terms = 3 以下是本人方程式: function [approx, terms] = approx_sine(x, threshold) approx = x; % 初始 approximation terms = 0; % Number of additional terms added to improve the approximation while threshold > abs((sin(x)-approx)/sin(x)) terms = terms + 1; approx = approx + (-1)^(terms)*x.^(2*terms+1)/factorial(2*terms+1) end end 请指点,为啥返回approx错误,而且还没返回terms值(请使用while loop解题) >> sine function(pi/5, 1e-6) approx = 1.256637061435917 ans = 1.256637061435917 |
» 猜你喜欢
职称评审没过,求安慰
已经有21人回复
垃圾破二本职称评审标准
已经有15人回复
投稿Elsevier的Neoplasia杂志,到最后选publishing options时页面空白,不能完成投稿
已经有20人回复
EST投稿状态问题
已经有7人回复
毕业后当辅导员了,天天各种学生超烦
已经有4人回复
聘U V热熔胶研究人员
已经有10人回复
求助文献
已经有3人回复
投稿返修后收到这样的回复,还有希望吗
已经有8人回复
三无产品还有机会吗
已经有6人回复
2楼2015-12-02 05:49:27













回复此楼