Different result command window and guide

Hello,
if I write in command window:
t=1
4.5582758767110180218764941687633*sin(314.0*t) - 16.557811525543529374688574837543*cos(314.0*t) + (16.557811525543529374688574837543*( 3.4028e+308*(1375.8856146096578468897575988832*t) + 0.48398685287825251446260421986529* 3.4028e+308*(1375.8856146096578468897575988832*t)))/exp(1485.7142857142857142857142857143*t)
I get NaN,but in guide I get -17.0711.....why?

回答(1 个)

John, in your expression you have two huge terms, basically,
Inf/Inf
which results in a NaN. You should get the same result for the same expression in your GUI.

3 个评论

sorry....in guide I calculate it with eval:
t=0:0.01:1
result=eval(vpa((4.5582758767110180218764941687633*sin(314.0*t) - 16.557811525543529374688574837543*cos(314.0*t) + (16.557811525543529374688574837543*( 3.4028e+308*(1375.8856146096578468897575988832*t) + 0.48398685287825251446260421986529* 3.4028e+308*(1375.8856146096578468897575988832*t)))/exp(1485.7142857142857142857142857143*t))))
I got:
Warning: Rank deficient, rank = 0, tol = NaN.
ggg =
Columns 1 through 4
-16.557811525543528 16.565050277096358 -16.572247010655047 16.579401707964752
Columns 5 through 8
-16.586514350877263 16.593584921351038 -16.600613401451270 16.607599773349886
Columns 9 through 12
-16.614544019325649 16.621446121764180 -16.628306063157943 16.635123826106454
Columns 13 through 16....
and so on....
So what can I do with cosh, if cosh has big value? regexprep(result,'cosh',' 3.4028e+10*')? or regexprep(result,'cosh','0*')?
Or how can I plot for any time:
92.9*cos(314.0*t) + 96.3*sin(314.0*t) - (7.94*(cosh(1399.0*t) + 4.06*sinh(1399.0*t)))/exp(1500.0*t)
You can do
syms t
expr = 92.9*cos(314.0*t) + 96.3*sin(314.0*t) - (7.94*(cosh(1399.0*t) + 4.06*sinh(1399.0*t)))/exp(1500.0*t);
expr = subs(expr, sinh(1399.0*t),(exp(1399.0*t) - exp(-1399.0*t))/2);
expr = subs(expr, cosh(1399.0*t),(exp(1399.0*t) + exp(-1399.0*t))/2);
expr = expand(expr,'ArithmeticOnly',true);
ezplot(expr,[0,0.1])
The two subs titutions are hyperbolic trig identities, thereby avoiding the Inf/Inf issue (in combination with the expand command).

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Code Generation 的更多信息

标签

提问:

2014-3-6

Community Treasure Hunt

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

Start Hunting!

Translated by