필터 지우기
필터 지우기

Numbers as multiply of pi?

조회 수: 6 (최근 30일)
Fabian Glutz
Fabian Glutz 2021년 3월 11일
댓글: Walter Roberson 2021년 3월 11일
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.

채택된 답변

Stephen23
Stephen23 2021년 3월 11일
atan(sqrt(sym(3))/1)
ans = 
  댓글 수: 3
Steven Lord
Steven Lord 2021년 3월 11일
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 2021년 3월 11일
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 = 

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by