Ask Your Question
0

How to plug in the solution of an equation into an expression?

asked 2020-06-29 16:39:35 -0500

erw1 gravatar image

updated 2020-06-30 15:20:15 -0500

In the code below, how would I plug in the solution for x in Ln[18] into Ln[19]? (I should get Out[19] -5*a+10)

In[16] var('a,x')
In[17] eq1 = x+a==0
In[18] solve([eq1],x)
In[19] 5*x+10

PS: 1. Is there a way to declare 'a' a constant rather than a variable?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-06-30 07:59:49 -0500

Cyrille gravatar image

updated 2020-06-30 11:55:20 -0500

You must use a dictionary to reuse the result

a=3
var('x')
eq1 = x+a==0
sol=solve([eq1],x,solution_dict=True)
x_sol=sol[0][x]
show(LatexExpr(r"x\_sol="+latex(x_sol)))
f(x)=5*x +10
show(LatexExpr(r"f(x\_sol)="+latex(f(x_sol))))
edit flag offensive delete link more

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

Stats

Asked: 2020-06-29 16:39:35 -0500

Seen: 86 times

Last updated: Jun 30