Ask Your Question

convert .solve output to function

asked 2019-03-06 16:35:42 -0500

meresar gravatar image

I have a function of two variables and would like to solve for one of the variables and make that a function, eg

p(z,w)=5*z^2*w + 3*z*w +2*z

and then somehow have the output of that:

[w == -2/(5*e^(I*t) + 3)]

become a function


Does anyone know a good way to do this? The main issue I'm having is the w== part.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-03-06 17:47:01 -0500

slelievre gravatar image

Most of the work has been done with the code in the question.

Only a little step remains.

After defining

sage: t = var('t', domain='real')
sage: z, w = var('z w')
sage: p(z, w) = 5*z^2*w + 3*z*w + 2*z
sage: solns = p(e^(I*t), w).solve(w)

the name solns refers to as a list of solutions

sage: solns
[w == -2/(5*e^(I*t) + 3)]

which in this case has only one element, accessed as

sage: solns[0]
w == -2/(5*e^(I*t) + 3)

and whose left hand side and right hand side are

sage: solns[0].lhs()
sage: solns[0].rhs()
-2/(5*e^(I*t) + 3)

so we can define

sage: f(t) = solns[0].rhs()
sage: f(t)
-2/(5*e^(I*t) + 3)
edit flag offensive delete link more


Thank you! This is much better than what I was trying to do which involved translating to a string and back.

meresar gravatar imagemeresar ( 2019-03-11 13:27:03 -0500 )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


Asked: 2019-03-06 16:35:42 -0500

Seen: 18 times

Last updated: Mar 06