Ask Your Question
1

Beginner problem solving equations.

asked 3 years ago

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...

Preview: (hide)

Comments

Welcome to Ask Sage! Thank you for your question!

slelievre gravatar imageslelievre ( 3 years ago )
1

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.
show(x_ow_np_ow_p)
show(x_ow_p_r_p)

solve(x_ow_np_ow_p == x_ow_p_r_p, p_n)[0].rhs()
tolga gravatar imagetolga ( 3 years ago )

Exactly, thank you!

Boyko_Bu gravatar imageBoyko_Bu ( 3 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 3 years ago

Boyko_Bu gravatar image

updated 3 years ago

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!

Preview: (hide)
link

Comments

Good. You should accept your own answer.

slelievre gravatar imageslelievre ( 3 years ago )
1

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 ( 3 years ago )

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

Boyko_Bu gravatar imageBoyko_Bu ( 3 years ago )

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

Seen: 428 times

Last updated: Jun 08 '21