get sympy result as trig function rather than complex log











up vote
1
down vote

favorite












I'm doing some manipulation of trig equations and would like the results back in trig form.



What I'm doing is this:



from sympy import *
B,D,a=symbols(r'B,D,alpha',real=True,positive=True)
eq1=Eq(D,B*((sin(a)*sin(a))/(sin(a+a))))
solve(eq1,a)


I expect the result to be atan(2*D/B) but I'm getting:



[-I*log(-sqrt((B + 2*I*D)/(B - 2*I*D))), -I*log((B + 2*I*D)/(B - 2*I*D))/2]


I know sympy is expanding the trig functions into exponential form, but I can't seem to convince it to convert the results back.



I've tried:



[n.rewrite(atan) for n in solve(eq1,a)]


but I get the same result back...










share|improve this question






















  • have you tried using simplify() or trigsimp() docs.sympy.org/0.7.0/modules/simplify.html#trigsimp
    – user1269942
    Nov 10 at 1:44












  • I did try those on the result, without luck. Of course I didn't try them /before/ the solve, which does resove the issue.
    – Omegaman
    Nov 10 at 2:50















up vote
1
down vote

favorite












I'm doing some manipulation of trig equations and would like the results back in trig form.



What I'm doing is this:



from sympy import *
B,D,a=symbols(r'B,D,alpha',real=True,positive=True)
eq1=Eq(D,B*((sin(a)*sin(a))/(sin(a+a))))
solve(eq1,a)


I expect the result to be atan(2*D/B) but I'm getting:



[-I*log(-sqrt((B + 2*I*D)/(B - 2*I*D))), -I*log((B + 2*I*D)/(B - 2*I*D))/2]


I know sympy is expanding the trig functions into exponential form, but I can't seem to convince it to convert the results back.



I've tried:



[n.rewrite(atan) for n in solve(eq1,a)]


but I get the same result back...










share|improve this question






















  • have you tried using simplify() or trigsimp() docs.sympy.org/0.7.0/modules/simplify.html#trigsimp
    – user1269942
    Nov 10 at 1:44












  • I did try those on the result, without luck. Of course I didn't try them /before/ the solve, which does resove the issue.
    – Omegaman
    Nov 10 at 2:50













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm doing some manipulation of trig equations and would like the results back in trig form.



What I'm doing is this:



from sympy import *
B,D,a=symbols(r'B,D,alpha',real=True,positive=True)
eq1=Eq(D,B*((sin(a)*sin(a))/(sin(a+a))))
solve(eq1,a)


I expect the result to be atan(2*D/B) but I'm getting:



[-I*log(-sqrt((B + 2*I*D)/(B - 2*I*D))), -I*log((B + 2*I*D)/(B - 2*I*D))/2]


I know sympy is expanding the trig functions into exponential form, but I can't seem to convince it to convert the results back.



I've tried:



[n.rewrite(atan) for n in solve(eq1,a)]


but I get the same result back...










share|improve this question













I'm doing some manipulation of trig equations and would like the results back in trig form.



What I'm doing is this:



from sympy import *
B,D,a=symbols(r'B,D,alpha',real=True,positive=True)
eq1=Eq(D,B*((sin(a)*sin(a))/(sin(a+a))))
solve(eq1,a)


I expect the result to be atan(2*D/B) but I'm getting:



[-I*log(-sqrt((B + 2*I*D)/(B - 2*I*D))), -I*log((B + 2*I*D)/(B - 2*I*D))/2]


I know sympy is expanding the trig functions into exponential form, but I can't seem to convince it to convert the results back.



I've tried:



[n.rewrite(atan) for n in solve(eq1,a)]


but I get the same result back...







python sympy trigonometry






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 1:27









Omegaman

784618




784618












  • have you tried using simplify() or trigsimp() docs.sympy.org/0.7.0/modules/simplify.html#trigsimp
    – user1269942
    Nov 10 at 1:44












  • I did try those on the result, without luck. Of course I didn't try them /before/ the solve, which does resove the issue.
    – Omegaman
    Nov 10 at 2:50


















  • have you tried using simplify() or trigsimp() docs.sympy.org/0.7.0/modules/simplify.html#trigsimp
    – user1269942
    Nov 10 at 1:44












  • I did try those on the result, without luck. Of course I didn't try them /before/ the solve, which does resove the issue.
    – Omegaman
    Nov 10 at 2:50
















have you tried using simplify() or trigsimp() docs.sympy.org/0.7.0/modules/simplify.html#trigsimp
– user1269942
Nov 10 at 1:44






have you tried using simplify() or trigsimp() docs.sympy.org/0.7.0/modules/simplify.html#trigsimp
– user1269942
Nov 10 at 1:44














I did try those on the result, without luck. Of course I didn't try them /before/ the solve, which does resove the issue.
– Omegaman
Nov 10 at 2:50




I did try those on the result, without luck. Of course I didn't try them /before/ the solve, which does resove the issue.
– Omegaman
Nov 10 at 2:50












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










If you simplify before solving, the result looks better.



>>> solve(eq1.simplify(), a)
[atan(2*D/B)]


Also, the more mathematically rigorous solveset (a modern alternative to solve) returns a more mathematically correct answer without the need for simplification:



>>> solveset(eq1, a)
ConditionSet(alpha, Eq(tan(alpha)/2 - D/B, 0), Reals)


The point being that there are infinitely many solutions, so they cannot be given as a list: so, solveset presents them as the set of all alpha such that tan(alpha) is 2*D/B.






share|improve this answer





















  • In this case, I'm using it for engineering purposes so the one solution is enough... ;-) Thanks. Tried every way I could think of to fix the output, didn't think to tweak the input.
    – Omegaman
    Nov 10 at 2:49











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235242%2fget-sympy-result-as-trig-function-rather-than-complex-log%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










If you simplify before solving, the result looks better.



>>> solve(eq1.simplify(), a)
[atan(2*D/B)]


Also, the more mathematically rigorous solveset (a modern alternative to solve) returns a more mathematically correct answer without the need for simplification:



>>> solveset(eq1, a)
ConditionSet(alpha, Eq(tan(alpha)/2 - D/B, 0), Reals)


The point being that there are infinitely many solutions, so they cannot be given as a list: so, solveset presents them as the set of all alpha such that tan(alpha) is 2*D/B.






share|improve this answer





















  • In this case, I'm using it for engineering purposes so the one solution is enough... ;-) Thanks. Tried every way I could think of to fix the output, didn't think to tweak the input.
    – Omegaman
    Nov 10 at 2:49















up vote
1
down vote



accepted










If you simplify before solving, the result looks better.



>>> solve(eq1.simplify(), a)
[atan(2*D/B)]


Also, the more mathematically rigorous solveset (a modern alternative to solve) returns a more mathematically correct answer without the need for simplification:



>>> solveset(eq1, a)
ConditionSet(alpha, Eq(tan(alpha)/2 - D/B, 0), Reals)


The point being that there are infinitely many solutions, so they cannot be given as a list: so, solveset presents them as the set of all alpha such that tan(alpha) is 2*D/B.






share|improve this answer





















  • In this case, I'm using it for engineering purposes so the one solution is enough... ;-) Thanks. Tried every way I could think of to fix the output, didn't think to tweak the input.
    – Omegaman
    Nov 10 at 2:49













up vote
1
down vote



accepted







up vote
1
down vote



accepted






If you simplify before solving, the result looks better.



>>> solve(eq1.simplify(), a)
[atan(2*D/B)]


Also, the more mathematically rigorous solveset (a modern alternative to solve) returns a more mathematically correct answer without the need for simplification:



>>> solveset(eq1, a)
ConditionSet(alpha, Eq(tan(alpha)/2 - D/B, 0), Reals)


The point being that there are infinitely many solutions, so they cannot be given as a list: so, solveset presents them as the set of all alpha such that tan(alpha) is 2*D/B.






share|improve this answer












If you simplify before solving, the result looks better.



>>> solve(eq1.simplify(), a)
[atan(2*D/B)]


Also, the more mathematically rigorous solveset (a modern alternative to solve) returns a more mathematically correct answer without the need for simplification:



>>> solveset(eq1, a)
ConditionSet(alpha, Eq(tan(alpha)/2 - D/B, 0), Reals)


The point being that there are infinitely many solutions, so they cannot be given as a list: so, solveset presents them as the set of all alpha such that tan(alpha) is 2*D/B.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 2:25







user6655984



















  • In this case, I'm using it for engineering purposes so the one solution is enough... ;-) Thanks. Tried every way I could think of to fix the output, didn't think to tweak the input.
    – Omegaman
    Nov 10 at 2:49


















  • In this case, I'm using it for engineering purposes so the one solution is enough... ;-) Thanks. Tried every way I could think of to fix the output, didn't think to tweak the input.
    – Omegaman
    Nov 10 at 2:49
















In this case, I'm using it for engineering purposes so the one solution is enough... ;-) Thanks. Tried every way I could think of to fix the output, didn't think to tweak the input.
– Omegaman
Nov 10 at 2:49




In this case, I'm using it for engineering purposes so the one solution is enough... ;-) Thanks. Tried every way I could think of to fix the output, didn't think to tweak the input.
– Omegaman
Nov 10 at 2:49


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53235242%2fget-sympy-result-as-trig-function-rather-than-complex-log%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)