# Manipulate dummy variable after solving trig

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

sy(t)=sin(t)/2+7*sin(t/3)/2
sols=solve(sy(t)==0,t, to_poly_solve='force')
sols[0]


returns:

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:

sols[0](z=0)


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:

sols[0].rhs()(0)


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 close merge delete

Sort by ยป oldest newest most voted

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.

var('z')
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()


EDIT:

Another possibility is to use the solveset from sympy

from sympy import solveset
solveset(sy(t)._sympy_())


It gives the solution as a union of sets.

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:

var('z')
solz=[]
for i in range(len(sols)):
dummy_var = sols[i].rhs().variables()[0]
solz.append(sols[i].rhs().subs({dummy_var:z}))


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

( 2021-12-06 13:29:01 +0100 )edit