Weird answer while using Log
2 views (last 30 days)
Show older comments
syms n
x = some value
why do i get weird answer when i do n*log10(x)?
for ex: if i do 10*log10(8)i get output as 9.03. But when i include n*10*log10(8) i get
(20335778644494715*n)/2251799813685248
as the output
0 Comments
Answers (2)
Star Strider
on 5 Sep 2015
Different variable classes:
syms n
Q1 = 10*log10(8)
ClassQ1 = class(Q1)
Q2 = n*10*log10(8)
ClassQ2 = class(Q2)
Q1 =
9.0309e+000
ClassQ1 =
double
Q2 =
(20335778644494715*n)/2251799813685248
ClassQ2 =
sym
If you want to change the appearance of the output, use the vpa function:
Q2 = vpa(Q2, 5)
Q2 =
9.0309*n
0 Comments
Walter Roberson
on 6 Sep 2015
Look at http://www.mathworks.com/help/symbolic/sym.html#input_argument_flag and notice that the flag 'r', "rational" is the default. That means that all floating point numbers in MATLAB are automatically converted to rational form by default when they become associated with a symbolic expression. You can force a different interpretation by using sym() around the number with the appropriate conversion flag, such as
n*10*sym(log10(8),'d')
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!