| 查看: 563 | 回复: 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 |
» 猜你喜欢
广西大学-广州大学招聘博士后 欢迎广大优秀人才!!!
已经有11人回复
闲聊
已经有3人回复
江苏省自然基金 什么时候出结果
已经有4人回复
如何查询2026年获批项目名称?
已经有3人回复
两块石头
已经有10人回复
科研人应该花精力去思考如何解决问题,而不是去凝练问题
已经有19人回复
售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急
已经有15人回复
面上没中,邀请各位路过的虫友分析一下分数
已经有13人回复
初秋的晨风
已经有6人回复
Ei源刊怎么投
已经有4人回复
2楼2015-12-02 05:49:27










回复此楼