Scientific notation in symbolic toolbox/use with subs(...)

11 views (last 30 days)
I'm working with systems of ODE's and using the symbolic toolbox. I have a function that retrieves numeric data from external files and substitutes it appropriately for the symbols in my systems.
Using either this function or just using subs(...), the function evaluates the expression and writes out the large numbers, which is rather inconvenient for later use.
As an example,
syms cs xe a b
eqn1 = 'Dcs = cs*a*b - a^2*b'
subs(eqn1,'a',1e24)
returns
Dcs = 1000000000000000000000000*b*cs...
I'm not sure how to modify the result since it's a string/sym and I'm less familiar working with these. Is there a way in how I'm using subs (or something other functon perhaps) or post-processing to get
Dcs = 1e24*b*cs...
Thanks all.

Answers (1)

Star Strider
Star Strider on 3 Aug 2012
The best you can hope for is to use ‘vpa’.
This (slight restatement) workd in 2012a:
syms cs xe a b Dcs(a)
Dcs(a) = cs*a*b - a^2*b
eqn1 = Dcs(1E24)
eqn1 = vpa(eqn1,15)
eqn2 = vpa(subs(cs*a*b - a^2*b, a, 1E+24),15)
yields:
Dcs(a) =
- b*a^2 + b*cs*a
eqn1 =
1000000000000000000000000*b*cs - 1000000000000000000000000000000000000000000000000*b
eqn1 =
1.0e24*b*cs - 1.0e48*b
eqn2 =
1.0e24*b*cs - 1.0e48*b
The symbolic function syntax that I used in order to define ‘Dcs(a)’ is new to 2012a. I couldn't get your initial code (using ‘subs’) to produce the same result with the ‘vpa’ call for some reason (I didn't see anything wrong with the code and it produced no error messages), but everything else in your initial code worked.

Products

Community Treasure Hunt

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

Start Hunting!