Strange output from symbolic calculation
Show older comments
Can someone explain this output (in particular, the numbers)
syms f0 T t0 Omegan t n
subs(2*f0*pi^2/(Omegan*T*(- Omegan^2*t0^2 + 4*pi^2)),Omegan,2*n*pi/T)
ans =
-(2778046668940015*f0)/(281474976710656*n*pi*((4*n^2*t0^2*pi^2)/T^2 - 2778046668940015/70368744177664))
Accepted Answer
More Answers (2)
Gautam Chettiar
on 1 Nov 2022
Edited: Gautam Chettiar
on 1 Nov 2022
% The numbers come because of your substitution of Omegan to 2*n*pi/T, with
% some of the variables cancelling out, and most of the numbers coming from
% 2 and pi
syms f0 T t0 Omegan t n
ans = subs(2*f0*pi^2/(Omegan*T*(- Omegan^2*t0^2 + 4*pi^2)),Omegan,2*n*pi/T)
vpa(simplify(ans), 3)
James Tursa
on 1 Nov 2022
Edited: James Tursa
on 1 Nov 2022
This isn't strange at all. You are asking the Symbolic Engine to examine all floating point expressions involving pi, which isn't even represented exactly in IEEE floating point, and extract the pi part. There are an infinite number of such expressions, of course, so you can't expect the Symbolic Engine to get them all. As such, it only gets the simple ones. E.g.,
sym(pi)
sym(4*pi)
sym(pi/3)
sym(pi^2)
sym(pi)^2
sym(exp(1))
exp(sym(1))
sym(exp(1)/3)
exp(sym(1))/3
sym(pi*exp(1))
sym(pi)*exp(sym(1))
The solution, as you have already discovered, is to insert symbolic constants up front rather than passing results of floating point expressions to the Symbolic Engine and expecting it to divine the source in all cases. Even the simple expressions have a limit for when the Symbolic Engine stops looking. E.g.,
sym(pi/100000)
sym(pi/100001)
1 Comment
Steven Lord
on 1 Nov 2022
See the description of the 'r' value for the flag input argument on the sym function's documentation page for a list of the expressions sym "recognizes". Most of the examples you posted that convert pi to π fall into the p*pi/q (for modest-sized integers p and q) case.
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
