24小时热门版块排行榜    

查看: 550  |  回复: 1

livin325

新虫 (初入文坛)

[求助] Sine Approximation 已知angle&阈值,返回terms值

输入两个参量X 和 threshold. 逐渐添加terms值,直到满足
abs((true &#1048576;-approx)/true)< threshold ;
true 是系统built-in 方程式sin(x)。
sin(x) = x &#1048576;- 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
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

livin325

新虫 (初入文坛)

不好意思乱码区重新输入如下
abs((true-approx)/true)<threshold

sin(x)=x- x^3/3! + x^5/5! - x^7/7!+...
2楼2015-12-02 05:49:27
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 livin325 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 基金中了 +15 laoda193707 2026-08-06 15/750 2026-08-11 00:11 by jiafei2190
[基金申请] 小木虫上这么多卖论文的,真有人买论文么?感觉没必要啊 +3 Tide man 2026-08-10 3/150 2026-08-10 21:48 by GZUZM
[基金申请] FileCode能看出啥? +7 要乐观耀哥 2026-08-10 15/750 2026-08-10 19:29 by 要乐观耀哥
[基金申请] 综述论文作为代表作会不会影响评审专家的印象分? +10 yufeiwaner 2026-08-09 11/550 2026-08-10 18:47 by yufeiwaner
[基金申请] 静等基金结果 +5 gjjjzhong 2026-08-10 16/800 2026-08-10 17:19 by Tide man
[基金申请] 关于Filecode分析方法 +3 majunge000 2026-08-10 3/150 2026-08-10 15:46 by lch2012
[基金申请] 2026国自然放榜时间 +9 布布和一二 2026-08-08 9/450 2026-08-10 11:22 by xxxx2020
[基金申请] 这样的filecode谁见过 +11 布布和一二 2026-08-08 22/1100 2026-08-10 11:10 by wmfsnow
[基金申请] 面上项目filecode邪修 +5 西山十月 2026-08-09 7/350 2026-08-10 07:32 by 仁砚薪传
[基金申请] 关于filecode,很负责任的告诉大家 +6 爱看书的可乐 2026-08-08 7/350 2026-08-08 22:13 by a_niu
[基金申请] 关于豆爷回答的JTJC与%2F数量 +5 yang182083 2026-08-06 7/350 2026-08-08 18:29 by zhanghaozhu
[基金申请] 国基金的申报应该改成非等额制,评价高的钱多评价低的钱少,但是增加资助率 +7 a089 2026-08-07 7/350 2026-08-08 18:05 by gltch
[基金申请] 关于filecode +4 布布和一二 2026-08-07 7/350 2026-08-07 22:55 by zhanghaozhu
[基金申请] 大家散了吧,后缀研究没有意义,别浪费时间了,过好目前的每一天,不要焦虑 +5 Tide man 2026-08-06 7/350 2026-08-07 13:11 by 医学老男孩
[基金申请] filecode +14 等待解的谜 2026-08-06 19/950 2026-08-07 12:20 by wlwhappy
[基金申请] filecode +8 布布和一二 2026-08-06 11/550 2026-08-06 20:41 by tangpu318
[基金申请] 影响面上的因素 +8 布布和一二 2026-08-05 11/550 2026-08-06 10:41 by 宝贝虫子
[基金申请] 好消息?这个有何含义??? +8 Tide man 2026-08-05 10/500 2026-08-05 16:14 by xmuxiaoyu
[基金申请] 有没有H口的?有收到消息的吗? +3 超级海虾 2026-08-04 3/150 2026-08-04 17:26 by 学教育滴
[基金申请] 纯娱乐,不喜欢勿喷 +7 Tide man 2026-08-04 10/500 2026-08-04 15:10 by loufangrui
信息提示
请填处理意见