Changing the output of a solve function
Mostra commenti meno recenti
Hello,
I have a question regarding the solve function and symbolic variables.
I have the following code :
syms a b r beta_3s
det_F1=(b*cos(beta_3s) - a*sin(beta_3s))/(r*sin(beta_3s))
sol = solve(det_F1==0,beta_3s,'Real',true)
When it is solved, I get the following solution:
sol =
-2*atan((a + (a^2 + b^2)^(1/2))/b)
-2*atan((a - (a^2 + b^2)^(1/2))/b)
However, I would like my solution to be in the following form
sol = atan2(b,a)
Is there a way to do this?
Thank you
Risposta accettata
Più risposte (1)
Walter Roberson
il 20 Giu 2020
It can be done with mapSymType
mapSymType(sol, 'atan', @fixup_atan2)
function at2 = fixup_atan2(v)
cv = children(v); %strip atan call
[n, d] = numden(cv);
at2 = atan2(n, d);
end
If you really need to it could be done with anonymous function calls instead of a real function, but using a real function makes the code a lot easier; you cannot use simple children() to get the numerator and denominator because you would not want to assume that the expression will be in the form of a division.
Categorie
Scopri di più su Assumptions in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!