eval() returns NaN when my matrix gets really big.

Hi
Im making a model of a mass-spring system where I can increase the numbers of masses. I use modal analysis where I transform my eq's into the Q domain and then back again.
My final result is a [n,1] vector where n is the numbers of masses.
When I use:
n = 4 % Number os masses %
T = 1 % Time which is set as "syms T" %
eval(X) % X is my [n,1] vector %
my result is something like:
ans =
0.0158
0.0739
0.1778
0.8150
but when I pick n to be more then 4 i just get "NaN" and I think it is because my vector gets too big for eval()..
When I look at my X vector it looks like this:
(227072026347336273211456024361092029598452603947709420093308928000*sin(T))/3496036292367407553353910200384804229923697463840499539488117510161+..... and it continues likes this for 2 full pages.
What to do?
Thank you!

 채택된 답변

Alexander
Alexander 2012년 4월 25일

0 개 추천

Please try the following:
double(vpa(evalin(symengine, ['subs(' char(X) ', T=' num2str(T) ')'])))
This does the following steps:
  1. Substitute the sym T inside the symbolic engine.
  2. Evaluate the result using variable-precision arithmetic.
  3. Convert the result to double.

댓글 수: 2

I think you should probably be able to simplify that to
double(subs(X))
Sorry, I have similar problem.
But I cannot understand the given command. Can anyone clarify it ?
Thank you in advance!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mads
Mads 2012년 4월 25일

0 개 추천

Thanks you two!! Both suggestions worked but Alexanders was for some reason like 20times faster

댓글 수: 4

Mads
Mads 2012년 4월 25일
but I cant plot it like this:
plot(T,double(vpa(evalin(symengine, ['subs(' char(X) ', T=' num2str(T) ')']))))
Plotting plot(T,double(subs(X))) works fine
Strange, I would have expected Walters suggestion to be much faster but give the NaN answer. Good to know, that both works.
If T is a vector then you would need 'T=[' num2str(T) ']'
Yeah, you are right. My suggestion does not work for vectors, I did not think about that.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2012년 4월 25일

댓글:

2021년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by