MATLAB Answers

0

intermediate exponential calculation goes to infinity

Albert Hall さんによって質問されました 2019 年 6 月 19 日
最新アクティビティ Steven Lord
さんによって コメントされました 2019 年 6 月 24 日
trying to calculate y = exp(-t).*cumtrapz(t,(exp(t).*x));
were x is a bounded vector and t is corresponding time stamp vector
y Output is finite but intermediate values of the exponent exceed matlab capability for large numbers

  0 件のコメント

サインイン to comment.

タグ

製品

2 件の回答

John D'Errico
回答者: John D'Errico
2019 年 6 月 19 日
編集済み: John D'Errico
2019 年 6 月 19 日
 採用された回答

Calc 101.
An integral is a linear operator. You can move any multiplicative constant inside or outside of the integral.
Suppose you write t as:
tmax + (t - tmax)
where
tmax = max(t)
Does this help you? It should. Try substituting into your expression. What will happen? Look carefully.
y = exp(-(tmax + (t-tmax))).*cumtrapz(t,(exp(tmax + (t - tmax)).*x));
remember. tmax is a constant. What is
exp(-tmax)*exp(tmax)
Hint: exp(0) = 1
That lets you reduce the problem a bit:
y = exp(-(t-tmax)).*cumtrapz(t,(exp(t - tmax).*x));
Since t-tmax is now never larger than 0, exp(t-tmax) is never a large number.

  3 件のコメント

Albert Hall 2019 年 6 月 19 日
Now it blows up the begining instead of at end
the exp(-(t-tmax)) outside the integral reduces to exp(tmax) at t=0
and exceeds the matlab overflow
Steven Lord
2019 年 6 月 19 日
What are the bounds of your vector t? What are the minimum and maximum values it contains?
Albert Hall 2019 年 6 月 24 日
Looks this was a short term fix. From this general principle in the answer, I used the constant tmax/2 to help at the start and at the end. I have a fitting constant tau that I use with the expression that makes the problem tractable.
y = exp(-(t-tmax/2)/tau).*cumtrapz(t,(exp(t - tmax/2)/tau.*x));
For larger problems I may need another method. If youall have any additional ideas to reduce the expression let me know.
Thanks

サインイン to comment.


回答者: Albert Hall 2019 年 6 月 19 日

t = 0 to 79391

  2 件のコメント

Albert Hall 2019 年 6 月 19 日
I can foresee that I might need to calculate higher numbers in future.
Steven Lord
2019 年 6 月 24 日
Then you would need to use an arbitrary precision system like Symbolic Math Toolbox. Let's see what exp(79391) is:
>> vpa(exp(sym(79391)), 6)
ans =
1.18362e34479
To put that into perspective, that's a really big number. You're in the section about one googol to one googolplex in this Wikipedia article, which includes numbers like the number of legal positions in the game of Go (about 2e170), approximate number of Planck volumes in the observable universe (around 1e186), or number of distinguishable permutations in the 33-by-33-by-33 Rubix Cube (around 2e4099.) Your number is much larger than any of those.
By comparison, an upper bound on the number of legal chess positions is about 4.52e46, and the number of fundamental particles in the observable universe is estimated at 1e80 to 1e85.
What exactly are you trying to compute with this calculation? There may be a way to avoid needing to compute using such huge (and tiny, since you also use exp(-t) in your code) numbers. The probability that a monkey will type Shakespeare's Hamlet on its first try is much smaller than exp(-t), but it might be the probability of that monkey typing a sonnet or two on its first try.

サインイン to comment.



Translated by