24小时热门版块排行榜    

查看: 489  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 265求调剂 +9 梁梁校校 2026-03-17 9/450 2026-03-21 02:17 by JourneyLucky
[考研] 278求调剂 +6 烟火先于春 2026-03-17 6/300 2026-03-21 01:57 by JourneyLucky
[考研] 324分 085600材料化工求调剂 +4 llllkkkhh 2026-03-18 4/200 2026-03-21 01:24 by JourneyLucky
[考研] 一志愿华中科技大学,080502,354分求调剂 +5 守候夕阳CF 2026-03-18 5/250 2026-03-21 01:06 by JourneyLucky
[考研] 一志愿重庆大学085700资源与环境专硕,总分308求调剂 +3 墨墨漠 2026-03-18 3/150 2026-03-21 00:39 by JourneyLucky
[考研] 材料学硕297已过四六级求调剂推荐 +11 adaie 2026-03-19 11/550 2026-03-20 21:30 by laoshidan
[考研] 一志愿武理材料工程348求调剂 +3  ̄^ ̄゜汗 2026-03-19 4/200 2026-03-20 21:01 by zhukairuo
[考研] 353求调剂 +3 拉钩不许变 2026-03-20 3/150 2026-03-20 19:56 by JourneyLucky
[考研] 工科材料085601 279求调剂 +7 困于星晨 2026-03-17 9/450 2026-03-20 17:38 by 无懈可击111
[考研] 08工学调剂 +5 用户573181 2026-03-20 5/250 2026-03-20 15:47 by xia_2003
[考研] 298-一志愿中国农业大学-求调剂 +9 手机用户 2026-03-17 9/450 2026-03-20 14:24 by 无懈可击111
[考研] 材料学硕318求调剂 +5 February_Feb 2026-03-19 5/250 2026-03-19 23:51 by 23Postgrad
[考研] 081700化工学硕调剂 +3 【1】 2026-03-16 3/150 2026-03-19 23:40 by edmund7
[考研] 一志愿福大288有机化学,求调剂 +3 小木虫200408204 2026-03-18 3/150 2026-03-19 13:31 by houyaoxu
[考研] 材料工程专硕调剂 +5 204818@lcx 2026-03-17 6/300 2026-03-18 22:55 by 204818@lcx
[考研] 化学工程321分求调剂 +15 大米饭! 2026-03-15 18/900 2026-03-18 14:52 by haxia
[考研] 0854,计算机类招收调剂 +3 胡辣汤放糖 2026-03-15 6/300 2026-03-18 12:09 by 上岸上岸……..
[考研] 考研化学学硕调剂,一志愿985 +4 张vvvv 2026-03-15 6/300 2026-03-17 17:15 by ruiyingmiao
[考研] 333求调剂 +3 文思客 2026-03-16 7/350 2026-03-16 18:21 by 文思客
[考研] 080500,材料学硕302分求调剂学校 +4 初识可乐 2026-03-14 5/250 2026-03-14 21:08 by peike
信息提示
请填处理意见