Changing the output of a solve function
이전 댓글 표시
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
채택된 답변
추가 답변 (1개)
Walter Roberson
2020년 6월 20일
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.
카테고리
도움말 센터 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!