How to change output format from solve function
25 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Quentin Dragomir
le 12 Nov 2020
Commenté : Quentin Dragomir
le 12 Nov 2020
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.
0 commentaires
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 12 Nov 2020
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 commentaire
Voir également
Catégories
En savoir plus sur Numbers and Precision dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!