Ask Your Question
1

convert .solve output to function

asked 2019-03-06 23:35:42 +0100

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

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

and then somehow have the output of that:

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

become a function

f(t)=-2/(5*e^(I*t)+3)

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
2

answered 2019-03-07 00:47:01 +0100

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()
w
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

Comments

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 19:27:03 +0100 )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

Stats

Asked: 2019-03-06 23:35:42 +0100

Seen: 371 times

Last updated: Mar 07 '19