- Symbolic-only phase. Everything that is changeable is generalized as a symbolic variable. The final outputs are written to files by using matlabFunction. This all might be in a seperate design session.
- Numeric-only phase, using the functions produced above. This might well be in a different session, even within an executable produced by MATLAB Compiler.
Deciding when to call a Matlab function: Within my symbolic math code, or within my converted numerical code?
48 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Noob
am 18 Nov. 2024 um 22:59
Kommentiert: Noob
am 19 Nov. 2024 um 14:46
Hi there!
I wrote a symbolic math code and used the algebraic solver solve( ) to get the equations that I want. I then converted these equations to Matlab functions, using matlabFunction( ) and wrote these converted equations to a separate file. Then I have a file with a full system of numerical equations. And, last but not least, I have a file which will solve these numerical equations, using, say, ode45( ). My equations are not solvable analytically using dsolve( ).
My question is: At some point in my workflow, I have to call certain specific models / functions, which I've defined as Matlab functions, in separate .m-files. If I call a numerical Matlab function within my very first symbolic-math script, then must the function I'm calling also be symbolic? Is it perhaps better to call my numerical Matlab functions later in the workflow, such as after the conversion from symbolic to numerical? What is the best practice? I suspect that it is not converting numerical Matlab functions to symbolic functions; that does not seem sensible to do, but I could be wrong. (E.g. there are lots of parameters within each Matlab numerical function that are decimal representations, but perhaps this isn't really important.)
Thanks in advance!
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 18 Nov. 2024 um 23:49
Typically you compute in two phases:
Sometimes this needs to be varied a bit. There are cases where the symbolic engine is able to integrate or solve() when a variable is given a specific numeric value, but not able to handle the general case. In such a situation, sometimes you need to fetch the specific numeric value first, then enter the symbolic phase, and then the numeric phase.
4 Kommentare
Paul
am 19 Nov. 2024 um 2:54
I've always thought it best to delay numerical evaluation as long as possible to give the SMT maximum opportunity to simplify expressions. But having said that one does need to guard against situations such as
syms big1 big2 big3
x = big1*big2/big3;
x might be a reasonsably sized number and would be found as such using VPA with numeric values for big*, but converting x to a matlabFunction and then evaluating with doubles for big* could result in overflow.
I'd be curious to see an example where an SMT function works better with a numeric value in a symbolic expression.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!