필터 지우기
필터 지우기

Matlab is unable to evaluate very a very long expression

조회 수: 8 (최근 30일)
Dominik Hiltbrunner
Dominik Hiltbrunner 2021년 11월 5일
편집: Dominik Hiltbrunner 2021년 11월 5일
Attached to this post is a text file containing a very long expression.
I want to evaluate this expression numerically in a Matlab function, i.e. something like this:
function result = (<long lost of all the parameters>)
result = '<this very long expression from the text file>'
end
The computer gets stuck when doing so, not returning a result even after hours of running.
Is there anything I can do to speed up the computation of very long expressions?
  댓글 수: 2
Stephen23
Stephen23 2021년 11월 5일
Note that you should replace all of the ^(1/2) with SQRT.
What sizes are the input arrays?
Are you intentionally using matrix operations instead of array operations everywhere in this code?
Dominik Hiltbrunner
Dominik Hiltbrunner 2021년 11월 5일
The ^(1/2) terms are in fact generated by Matlab itself, i.e. the long expression also comes from a Matlab file in which my sqrt(...) inputs are then printed in this way. Can I prevent Matlab from doing so?
Every variable in this expression is a scalar, no arrays or matrix operations are performed.

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

채택된 답변

Steven Lord
Steven Lord 2021년 11월 5일
How did you generate this long expression? Did you generate this using Symbolic Math Toolbox? If so consider using matlabFunction to create a function file from this expression (leaving the 'Optimize' option set to its default value of true) and see if the optimization process simplifies the computation of that expression by extracting out some common terms that it can compute once and use repeatedly.
  댓글 수: 1
Dominik Hiltbrunner
Dominik Hiltbrunner 2021년 11월 5일
편집: Dominik Hiltbrunner 2021년 11월 5일
This is fantastic!
I didn't know about this function before. I used it as follows:
matlabFunction(symbolic_expression,'File','file_name','Optimize',true);
I takes almost 20 minutes to generate/optimize this file, but the computation is incredible fast.
Godd job!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by