Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

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

asked 4 years ago

erw1 gravatar image

updated 4 years ago

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 4 years ago

Cyrille gravatar image

updated 4 years ago

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))))
Preview: (hide)
link

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: 4 years ago

Seen: 421 times

Last updated: Jun 30 '20