MATLAB SUMMATION HELP Please????

1 回表示 (過去 30 日間)
nick pa
nick pa 2014 年 7 月 21 日
回答済み: Roger Stafford 2014 年 7 月 22 日
So i need to know how i can do this summation? ik its a for loop but when i ran it all i got was zeros.
e^x=(1+x/1!+x^2/2!+x^3/3!+⋯,)-50<x<50 Eq (1)
e^'x=A*(1+x/1!+x^2/2!+x^3/3!+⋯),-50<x<50 Eq (2)
For the above equations build a vector named X from -50 to 50 in increment of 0.5. Then calculate the values of ex and e’x. Plot the values of these two functions with the following formats:
I got the vector built, but am stuck
  1 件のコメント
James Tursa
James Tursa 2014 年 7 月 22 日
Please post your code so far and we can comment on it and offer suggestions.

サインインしてコメントする。

回答 (1 件)

Roger Stafford
Roger Stafford 2014 年 7 月 22 日
I notice on your other thread at Answers #142842 you have written:
n = 0:201
x = [-50:0.5:50]
xs = sum((x.^n./factorial(n))
As you may have already seen, this will give you trouble because for both ends of that x-range, the value of both x^201 and 201! will be extremely large and overflow to infinity, thereby producing a NaN in taking their ratio.
The way around this is to use a for-loop which runs through the series backwards. You start with 1. On the first trip you compute 1+x/201*1. On the second trip you get 1+x/200*(1+x/201*1). On the third trip you get
1+x/199*(1+x/200*(1+x/201*1))
And so forth. I think you can see the pattern here. At each step there is first a multiplication of the previous value times x, then a division by an integer that is successively 201, 200, 199, etc., and finally 1 is added. If you follow this method, your computed value of ex will be extremely close to the ideal exp(x) for numbers as extreme as 50 and -50.
You face one additional difficulty. In making a plot, you will find that for the plot to be scaled to fit values for ex with x = 50 on the plot, smaller values of x will give much smaller values for ex and the plot line will look as if those values are all zeros.
I haven't understood the significance of your second equation (2). What is 'A'?

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by