Ask Your Question
0

simple numerical solve (2-variables!!)

asked 2012-09-17 07:01:13 +0100

mattias gravatar image

updated 2012-09-20 08:54:48 +0100

Hello,

Thanks for the help, I'm trying to move from Mathematica to Sage, but I'm still having some trouble with the basics. Specifically, I'm moving from 1-var to 2-var numerical optimization/solver. I want to optimize function g or, equivalently, solve the system of first-order conditions, f. So far, I have not been able to get any of the scipy routines to work. Is there a simple way to do this? (Note: the objective function is concave wrt to both arguments.)

Thanks! jv

Constants

y_a = 50 y_b = 50 x = 40 alpha_a = .2 alpha_b = .2

Functions

v(n)= n^.5 v1(n) = derivative(v(n),n) u(n)= n^.5 u1(n) = derivative(u(n),n)

Variables

var('g_a') var('x_a')

Optimization (over [0, x])

g = (v(g_a+alpha_b(x-g_a))-u(y_a)+u(y_a-x_a))(v(x-g_a+alpha_a*(g_a))-u(y_b)+u(y_b-(x-x_a)))

f1 = ((1-alpha_b)v1(g_a+alpha_b(x - g_a)))/((1-alpha_a)v1(x-g_a+alpha_a(g_a)))==(v(g_a+alpha_b(x-g_a))-u(y_a)+u(y_a-x_a))/(v(x-g_a+alpha_a(g_a))-u(y_b)+u(y_b-(x-x_a)))

f2 = (u1(x_a)/u1(x-x_a)) == (v(g_a+alpha_b(x-g_a))-u(y_a)+u(y_a-x_a))/(v(x-g_a+alpha_a(g_a))-u(y_b)+u(y_b-(x-x_a)))

f(g_a, x_a) = (f1, f2)

edit retag flag offensive close merge delete

Comments

2

Did you completely change your question? If you have another question to ask, please revert this one to its first version and ask your second question as a separate topic.

niles gravatar imageniles ( 2012-09-20 09:43:00 +0100 )edit
1

Hi mattias. If you restore the first question and ask the second as a separate one I can show how to obtain (20,20) as the answer

achrzesz gravatar imageachrzesz ( 2012-09-20 14:56:07 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2012-09-17 07:52:12 +0100

achrzesz gravatar image

updated 2012-09-17 12:46:54 +0100

var('g_a')
eq=g_a == -31375155/31496372*sqrt(-4/5*g_a + 1) + 31375155/31496372*sqrt(4/5*g_a + 8) - 35/8
solve(eq,g_a,to_poly_solve=True)
[g_a == (-35/8)]
bool(eq.subs(g_a=-35/8))
#True
edit flag offensive delete link more
1

answered 2012-09-17 10:01:35 +0100

niles gravatar image

updated 2012-09-17 10:05:48 +0100

What function are you using to do this? simplify? Showing us a minimal example might be helpful.

If you're not using it already, I recommend find_root for numerical solutions to 1-variable equations.

As far as I can tell, Maxima is used primarily for symbolic manipulations in Sage, and other things are used for numerical optimization. So if you're using a function that uses Maxima, you might only get symbolic output.

edit flag offensive delete link more

Comments

Thanks, this is exactly what I was looking for. I was using solve with a rather messy function. After a bit of troubleshooting I was able to get find_root to work for me.

mattias gravatar imagemattias ( 2012-09-17 12:57:16 +0100 )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

Stats

Asked: 2012-09-17 07:01:13 +0100

Seen: 1,030 times

Last updated: Sep 20 '12