DIsplay numbers in an expression in scientific notation

I have an expression that I'm plugging a bunch of values into and I would like for matlab to show me the result with the constants in scientific notation. By default, it shows the constants as big fractions that aren't as easy to work with. Here's what I mean:
syms L1 L2 C1 C2 C3 Rl s;
L1=10e-9;
L2=500e-12;
C1=600E-12;
C2=2E-9;
C3=100E-12;
Rl=2;
H_P_V2DivI1 = (C2*Rl*s + 1)/(C1*C2*L1*s^3 + C1*C2*Rl*s^2 + (C1 + C2)*s)
H_P_V2DivI1 =
((4835703278458517*s)/1208925819614629174706176 + 1)/((8362779449448985*s^3)/696898287454081973172991196020261297061888 + (3115378115120897*s^2)/1298074214633706907132624082305024 + (785801782749509*s)/302231454903657293676544)
Is there a way to display this expression using scientific notation instead? Thanks!

 Accepted Answer

syms L1 L2 C1 C2 C3 Rl s;
L1=10e-9;
L2=500e-12;
C1=600E-12;
C2=2E-9;
C3=100E-12;
Rl=2;
H_P_V2DivI1 = (C2*Rl*s + 1)/(C1*C2*L1*s^3 + C1*C2*Rl*s^2 + (C1 + C2)*s)
H_P_V2DivI1 = 
vpa(H_P_V2DivI1, 16)
ans = 

3 Comments

I recommend that you be more careful about mixing scientific notation input and symbolic expressions.
The default conversion is 'r', which tries first for multiples of Pi, then for square roots of rationals, and then for rationals; if it does not find any nice close rational then it ends up using a rational with a power of 2 that matches the algebraic meaning of internal double precision representation.
Because 1/10 is not exactly representable in binary double precision, it is common that the default conversion ends up representing multiples of a power of 10, as rationals divided by a power of 2 such as 2^53 . But in cases where you have reason to treat something like 600E-12 as being an exact value rather than as implying 600E-12 +/- 5E-13 (true scientific notation assumes that the true number is unknown and has been rounded to get the representation you see), then you can construct the parts in ways that give exact rationals.
syms L1 L2 C1 C2 C3 Rl s;
Q = @(v) sym(v);
L1 = Q(10)^(-9)
L1 = 
L2 = Q(500)*Q(10)^(-12)
L2 = 
C1 = Q(600)*Q(10)^(-12)
C1 = 
C2 = Q(2)*10^(-9)
C2 = 
C3 = Q(100)*10^(-12)
C3 = 
Rl = Q(2);
H_P_V2DivI1 = (C2*Rl*s + 1)/(C1*C2*L1*s^3 + C1*C2*Rl*s^2 + (C1 + C2)*s)
H_P_V2DivI1 = 
Thanks Walter! I'd noticed that the vpa command helped, but I didn't know there was a second term - I'm assuming that's number of digits after the decimal, right? I brought it down to 8 and got everything in scientific notation:
vpa(H_P_V2DivI1,8)
ans =
(4.0e-9*s + 1.0)/(1.2e-26*s^3 + 2.4e-18*s^2 + 2.6e-9*s)
yes optional second parameter is the number of digits. Otherwise it uses the current digits() setting

Sign in to comment.

More Answers (0)

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!