Equation in Taylor series to show each iteration?
3 次查看(过去 30 天)
显示 更早的评论
In the attached document, how to I get the difference to display in my outputs. My equation in the taylor series is in the while loop in the variable 'Equation'. Also right now when I run my code it just keeps going continuously and never stops. I don't get any outputs, I'll attach my code for you to look at.
0 个评论
采纳的回答
Geoff Hayes
2015-10-10
Nick - you may want to review the pdf with your professor since the example showing the differences are not true for the case where x is 1.5. Looking at your code, the important line is that which computes the next estimate
Estimate=(-1)^(count)*(x-1)*((count+1)/(count+1));
Note how you are multiplying the (x-1) by ((count+1)/(count+1));. There are two problems here - the first is that ((count+1)/(count+1)) will always evaluate to one, and the second is that your code is multiplying rather than using an exponent and dividing. Remember that the kth term of your Taylor series is
(-1)^(k+1) * ((x - 1)^k)/k
for k = 1,2,3,... Remember also that you are summing over the above so you need to take that in mind on each iteration (you need to sum the Estmate). Your code should then be as follows
Estimate = Estimate + (-1)^(k+1)*((x-1)^k)/k;
Try incorporating the above into your code and see what happens!
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!