How to change output format from solve function
이전 댓글 표시
Hello,
I would like to change the output format from the solve equation.
For instance in this simple example:
syms d
dist = solve(115.7==20*log10(4*pi*d/lambda)-10*log10(Gr)-10*log10(Ge)-2.2,d)
I get as answer:
dist = 10^(691379199349428923/112589990684262400)/(24*pi)
What command could I use to receive
dist = 1.8337e+04
Thanks you.
채택된 답변
추가 답변 (1개)
Walter Roberson
2020년 11월 12일
Your use of 115.7 and 2.2 in the equation tells us that you are working with values that are fundamentally not exact. 115.7 here expresses "some indeterminate value that is between 11565/100 (inclusive) and 11575/100 (exclusive)" . As such it does not make sense to ask for an exact solution. solve() is for use in cases where you want indefinitely precise solutions, which is not the case here. You should be using vpasolve() instead.
If for some reason you believe that 115.7 is exactly 1157/10 then you should be using
syms d
Q = @(v) sym(V); %convert to symbolic algebraic number
dist = solve( Q(115.7) == Q(20)*log10(Q(4)*Q(pi)*d/lambda) - Q(10)*log10(Gr)-Q(10)*log10(Ge)-Q(2.2), d)
... and expect an exact solution formula. Which you could then vpa() or double() to see an approximation of.
The calls to Q() there are to convert floating point numbers into the closest algebraic number (or into Pi), such as 115.7 -> 1157/10 and 1.4142135623731 -> 2^(1/2)
댓글 수: 1
Quentin Dragomir
2020년 11월 12일
카테고리
도움말 센터 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!