Effacer les filtres
Effacer les filtres

Numbers as multiply of pi?

6 vues (au cours des 30 derniers jours)
Fabian Glutz
Fabian Glutz le 11 Mar 2021
Commenté : Walter Roberson le 11 Mar 2021
Hi, does anyone know how to tell Matlab it should show a number as a multiply of pi?
Example: atan(sqrt(3)/1) = 1.0472 but I want to see it as pi/3
Thx for the help guys.

Réponse acceptée

Stephen23
Stephen23 le 11 Mar 2021
atan(sqrt(sym(3))/1)
ans = 
  3 commentaires
Steven Lord
Steven Lord le 11 Mar 2021
The order in which you call sym and other operations doesn't always matter, but it can.
Do you want to perform the calculations numerically then convert the result to a symbolic answer? Or do you want to perform the calculations symbolically from the beginning?
x = sym(2)^2000
x = 
114813069527425452423283320117768198402231770208869520047764273682576626139237031385665948631650626991844596463898746277344711896086305533142593135616665318539129989145312280000688779148240044871428926990063486244781615463646388363947317026040466353970904996558162398808944629605623311649536164221970332681344168908984458505602379484807914058900934776500429002716706625830522008132236281291761267883317206598995396418127021779858404042159853183251540889433902091920554957783589672039160081957216630582755380425583726015528348786419432054508915275783882625175435528800822842770817965453762184851149029376
y = sym(2^2000)
y = 
Calculating y computed 2^2000 in double precision first (which overflows to Inf) and then converts that infinity into a symbolic result. Calculating x "computes" 2 in double precision (which doesn't overflow), converts that 2 to a symbolic result that I'll call two, then computes two^2000 symbolically. Symbolic Math Toolbox can handle that large number.
If you have something where doing the work in double precision will lose desired precision, overflow, or underflow you probably want to go symbolic first. On the other hand, performing calculations symbolically has a bit more overhead.
Walter Roberson
Walter Roberson le 11 Mar 2021
sym(atan(sqrt(3)/1))
ans = 
That happened to work. The symbolic toolbox can deal with pi divided by 1 to 9999 if I recall correctly
sym(pi/5987)
ans = 
But beyond some simple ratios, it loses track
sym((pi-1)/3)
ans = 
(sym(pi)-1)/3
ans = 

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by