24小时热门版块排行榜    

查看: 490  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 070300化学319求调剂 +7 锦鲤0909 2026-03-17 7/350 2026-03-21 03:46 by JourneyLucky
[考研] 材料工程(专)一志愿985 初试335求调剂 +3 hiloiy 2026-03-17 4/200 2026-03-21 03:04 by JourneyLucky
[考研] 初始318分求调剂(有工作经验) +3 1911236844 2026-03-17 3/150 2026-03-21 02:33 by JourneyLucky
[考研] 332求调剂 +4 ydfyh 2026-03-17 4/200 2026-03-21 02:20 by JourneyLucky
[考研] 278求调剂 +6 烟火先于春 2026-03-17 6/300 2026-03-21 01:57 by JourneyLucky
[考研] 280求调剂 +7 咕噜晓晓 2026-03-18 8/400 2026-03-21 01:27 by JourneyLucky
[考研] 一志愿华南师大 070300(化学)304分求调剂 +3 0703武芊慧雪304 2026-03-18 3/150 2026-03-21 00:48 by JourneyLucky
[考研] 296求调剂 +6 www_q 2026-03-18 10/500 2026-03-20 23:56 by JourneyLucky
[考研] 一志愿武汉理工材料工程专硕调剂 +9 Doleres 2026-03-19 9/450 2026-03-20 22:36 by JourneyLucky
[考研] 一志愿 西北大学 ,070300化学学硕,总分287,双非一本,求调剂。 +4 晨昏线与星海 2026-03-19 4/200 2026-03-20 22:15 by JourneyLucky
[考研] 材料学硕297已过四六级求调剂推荐 +11 adaie 2026-03-19 11/550 2026-03-20 21:30 by laoshidan
[考研] 260求调剂 +3 朱芷琳 2026-03-20 3/150 2026-03-20 20:35 by 学员8dgXkO
[论文投稿] 申请回稿延期一个月,编辑同意了。但系统上的时间没变,给编辑又写邮件了,没回复 10+3 wangf9518 2026-03-17 4/200 2026-03-19 23:55 by babero
[考研] 一志愿985,本科211,0817化学工程与技术319求调剂 +10 Liwangman 2026-03-15 10/500 2026-03-19 10:25 by 无际的草原
[考研] 311求调剂 +11 冬十三 2026-03-15 12/600 2026-03-18 14:36 by 星空星月
[考研] 277调剂 +5 自由煎饼果子 2026-03-16 6/300 2026-03-17 19:26 by 李leezz
[考研] 302求调剂 +4 小贾同学123 2026-03-15 8/400 2026-03-17 10:33 by 小贾同学123
[考研] 考研调剂 +3 淇ya_~ 2026-03-17 5/250 2026-03-17 09:25 by Winj1e
[考研] 0703化学调剂 290分有科研经历,论文在投 +7 腻腻gk 2026-03-14 7/350 2026-03-16 10:12 by houyaoxu
[考研] 复试调剂 +3 呼呼?~+123456 2026-03-14 3/150 2026-03-14 16:53 by WTUChen
信息提示
请填处理意见