Ask Your Question

Beginner problem solving equations.

asked 2021-06-08 12:44:34 +0200

Boyko_Bu gravatar image

Dear all,

This is my second day on Sagemath!

I don't understand what I'm doing wrong, and right now, I can't even open the documentation online (I get error even there). I simply want to solve the last equation for p_n, I suppose that Sage sees that I am comparing two equations, so it doesn't understand that I want to compare the right-hand side of both, but then what is the purpose of the .rhs method? (Even here, it would be nice to understand what this is... I'm copying the code of a friend of mine and trying to apply it to my own problem).

P.S. Also with respect to the documentation, what should I read, about this stuff? I went through the first sections, but I saw nothing on methods.

var('x, p_r, p_n, t, beta, delta')

U_ow_np = x - p_n 
U_ow_p  = x*(1-beta) - p_n + (delta/(1-delta))*p_r*(1-t)
U_r_p   = 1-x*(1-beta) - delta*p_r
U_O_O   = 1-x
x_ow_np_ow_p = solve(U_ow_np == U_ow_p, x)[0].rhs
x_ow_p_r_p = solve(U_ow_p == U_r_p, x)[0].rhs
x_r_p_O_O = solve(U_r_p == U_O_O, x)[0].rhs

# Here I get the error.

solve(x_ow_np_ow_p == x_ow_p_r_p, p_n)[0].rhs

P.S. What does the [0] mean?

Sorry for the naivite, I tried to have a look on the forum, but this problem seems too basic for this forum...

edit retag flag offensive close merge delete


Welcome to Ask Sage! Thank you for your question!

slelievre gravatar imageslelievre ( 2021-06-08 12:57:14 +0200 )edit

Try using .rhs() with brackets. [0] gives you the first element of an array.

var('x, p_r, p_n, t, beta, delta')

U_ow_np = x - p_n 
U_ow_p  = x*(1-beta) - p_n + (delta/(1-delta))*p_r*(1-t)
U_r_p   = 1-x*(1-beta) - delta*p_r
U_O_O   = 1-x
x_ow_np_ow_p = solve(U_ow_np == U_ow_p, x)[0].rhs()
x_ow_p_r_p = solve(U_ow_p == U_r_p, x)[0].rhs()
x_r_p_O_O = solve(U_r_p == U_O_O, x)[0].rhs()

# Here I get the error.

solve(x_ow_np_ow_p == x_ow_p_r_p, p_n)[0].rhs()
tolga gravatar imagetolga ( 2021-06-08 13:05:18 +0200 )edit

Exactly, thank you!

Boyko_Bu gravatar imageBoyko_Bu ( 2021-06-08 15:08:03 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-06-08 13:00:22 +0200

Boyko_Bu gravatar image

updated 2021-06-08 15:08:34 +0200

Ok I see, I'm not using the parenthesis on the method, hence it doesn't work, and .rhs()tells to Sage exactly that it has to consider only the right hand side of the equation.

Sorry, I found the solution by myself, in the end... Delete everything!

edit flag offensive delete link more


Good. You should accept your own answer.

slelievre gravatar imageslelievre ( 2021-06-08 13:03:43 +0200 )edit

I strongly recommend this book f you want to ease your beginnings with Sagemath...

Also : state your answer explicitly : it could be of use to the next beginner...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2021-06-08 13:51:17 +0200 )edit

Hi guys, I am so noob that the forum doesn't even allow me to accept my own answer!

Boyko_Bu gravatar imageBoyko_Bu ( 2021-06-08 15:09:06 +0200 )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

1 follower


Asked: 2021-06-08 12:44:34 +0200

Seen: 65 times

Last updated: Jun 08