Ask Your Question
1

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

asked 2020-06-29 23:39:35 +0200

erw1 gravatar image

updated 2020-06-30 22:20:15 +0200

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
2

answered 2020-06-30 14:59:49 +0200

Cyrille gravatar image

updated 2020-06-30 18:55:20 +0200

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 23:39:35 +0200

Seen: 311 times

Last updated: Jun 30 '20