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...
python sympy trigonometry
add a comment |
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...
python sympy trigonometry
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
add a comment |
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...
python sympy trigonometry
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
python sympy trigonometry
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
add a comment |
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
add a comment |
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
.
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
add a comment |
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
.
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
add a comment |
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
.
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
add a comment |
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
.
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
.
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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