24小时热门版块排行榜    

查看: 548  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] filecode +8 documentary 2026-08-10 8/400 2026-08-10 19:20 by loufangrui
[基金申请] 确定了,国自然21号放榜 +6 布布和一二 2026-08-10 7/350 2026-08-10 19:15 by 2000zf36392
[基金申请] 为什么网上很多人说本周 12号出结果 +3 瞬息宇宙 2026-08-10 3/150 2026-08-10 18:27 by Tide man
[基金申请] 静等基金结果 +5 gjjjzhong 2026-08-10 16/800 2026-08-10 17:19 by Tide man
[基金申请] 我的国基提前知道中了,可是同事的操作让我实在接受不了,怎么会有这样的人 +8 家与远方 2026-08-10 11/550 2026-08-10 17:09 by 六两废铜
[基金申请] 奇怪,两个人的filecode固定段从头到尾一模一样 +4 布布和一二 2026-08-10 4/200 2026-08-10 14:50 by 医学老男孩
[基金申请] 好奇怪的filecode +4 布布和一二 2026-08-08 5/250 2026-08-10 14:20 by 冰心玉壶晴
[基金申请] 2026国自然放榜时间 +9 布布和一二 2026-08-08 9/450 2026-08-10 11:22 by xxxx2020
[基金申请] filecode与中标关系的预测 +5 布布和一二 2026-08-07 5/250 2026-08-09 16:15 by 袁向阳007
[基金申请] 关于豆爷回答的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
[基金申请] 化学口download_prp&amp;fileCode的固定段好像这几天一直没变,有变的大神么? +3 Tide man 2026-08-07 4/200 2026-08-07 22:39 by Tide man
[基金申请] filecode变化情况 +6 布布和一二 2026-08-07 22/1100 2026-08-07 14:45 by 且听虎啸
[基金申请] 大家散了吧,后缀研究没有意义,别浪费时间了,过好目前的每一天,不要焦虑 +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 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
信息提示
请填处理意见