Series summation issue - conversion to double error

1 回表示 (過去 30 日間)
Jon
Jon 2013 年 2 月 20 日
Hi, I'm trying to write a series summation code and I'm getting the "conversion to double" error when I plot.
Here's the part of the code with trouble:
syms m
rhs = (1./(1+(2.*(t- m.*p))./tc)).* exp((-2.*r^2)./(r^2.*(1+ (2.*(t-m.*p)./tc))));
summation1 = symsum(rhs,0,1.89E5);
Where tc, r, and p are constants and t is a timespace with 36 spaces.
Is the problem that I'm asking it to sum from 0 to 1.89e5 with those 36 time spaces?
Thanks
EDIT: http://i.imgur.com/mz2KV5h.jpg Link is of the sum

採用された回答

bym
bym 2013 年 2 月 21 日
At some point, Matlab gives up & returns the indefinite summation. You can try this:
clc;clear
syms m
tc = 3;
p = 3;
t = 1:10;
r =2;
rhs = (1./(1+(2.*(t- m.*p))./tc)).* exp((-2.*r^2)./(r^2.*(1+ (2.*(t-m.*p)./tc))));
summation1 = symsum(rhs);
f = matlabFunction(summation1);
f(189000)
f(10)
ans =
1.0e-005 *
Columns 1 through 8
-0.2646 -0.2646 -0.2646 -0.2646 -0.2646 -0.2646 -0.2646 -0.2646
Columns 9 through 10
-0.2646 -0.2646
ans =
Columns 1 through 8
-0.0608 -0.0634 -0.0662 -0.0692 -0.0725 -0.0762 -0.0802 -0.0847
Columns 9 through 10
-0.0897 -0.0954
  1 件のコメント
Jon
Jon 2013 年 2 月 23 日
Thank you, this will work for now while I have a dozen or so points, but it gets quite complex when I want to extend my time.
Many thanks!

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 2 月 20 日
You could try
double(summation1)
If that gives you the same error then your summation1 must still contain some symbolic variable. Try
symvar(summation1)
  2 件のコメント
Jon
Jon 2013 年 2 月 20 日
編集済み: Jon 2013 年 2 月 21 日
I get the same error when using both
Conversion to double from sym is not possible.
I had read about converting that symbolic variable and figured that could be the issue but I used the
subs(summation1, 'new array to replace "m" ' )
and that seemed to accept it, now it's about fixing my values
EDIT: False alarm - it just makes the variable a single value.
Jon
Jon 2013 年 2 月 21 日
Here's the sum for completeness

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

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by