Ask Your Question

Manipulate dummy variable after solving trig

asked 2021-12-06 00:36:56 +0200

jakupl gravatar image

updated 2021-12-06 00:40:35 +0200

Hi! This might be somewhat basic, but is there a way to directly reference the dummy variable that pops up, when solving trigonometric functions?

sols=solve(sy(t)==0,t, to_poly_solve='force')


t == 3*pi + 6*pi*z27541

This dummy variable obviously changes every time the command is run, so there is no way of directly referencing it without changing the reference every time. Obviously this doesn't work:


The closest I have come, is just blindly referencing the variable which works if there are no other variables in the right hand side, like this:


but this gives the obnoxious error message, that "Substitution using function-call syntax and unnamed arguments is deprecated (...)"

Is there a way to cleanly tell sage to evaluate an expression, when all z variables are 0 or 1 etc?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-12-06 05:42:42 +0200

cav_rt gravatar image

updated 2021-12-07 21:39:52 +0200

You can get the dummy variable by

dummy_var = sols[0].rhs().variables()[0]

And then define a callable function changing the dummy variable to a proper symbolic one.

f(z) = sols[0].rhs().subs({dummy_var:z})

Now you can simply do f(0), f(1) or whatever you want.

PS, for some reason it does not work if you try to define a callable function using the dummy variable directly, like

f(dummy_var) = sols[0].rhs()


Another possibility is to use the solveset from sympy

from sympy import solveset

It gives the solution as a union of sets.

edit flag offensive delete link more


Thank you! I had been trying something like this, but it's the curly brackets that got me. Not experienced enough in python yet. My life will be so much easier now, being able to quickly do:

for i in range(len(sols)):
    dummy_var = sols[i].rhs().variables()[0]

(as long as there are not other variables obviously.)

jakupl gravatar imagejakupl ( 2021-12-06 13:29:01 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2021-12-06 00:36:56 +0200

Seen: 227 times

Last updated: Dec 07 '21