ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 22 May 2023 15:14:06 +0200Calculate FOC of a simple economics problemhttps://ask.sagemath.org/question/68641/calculate-foc-of-a-simple-economics-problem/Set C(t) is the consumption of time t; beta is the discount factor
The objective function of customer (choose C(t) for on each time t) is the sum of beta^t * log(C(t)) ; t is from 0 to +oo.
The budget constrain is Y(t) - C(t) + r(t)K(t) = K(t+1) for t = 0 ... +oo
How to get the right FOC of this function to C(t) and K(t) from SegaMath
for example:
FOC wrt C(t) : beta^t * 1/C(t) - lambda(t) = 0
FOC wrt K(t) : ...
Additionally, how to set the objective function as a expectation on time t (E_t(sum of beta^t * log(C(t)) ; t is from 0 to +oo) and get similar FOCssora16Mon, 22 May 2023 15:14:06 +0200https://ask.sagemath.org/question/68641/Trig simplification of implicit functions failshttps://ask.sagemath.org/question/51442/trig-simplification-of-implicit-functions-fails/I'd like to use Sage to verify my solutions to Lagrangian equations of motion for a double pendulum. However, Sage seems unable to handle some basic substitutions needed to make sense of this relatively simple problem.
For example, this all works fine:
var('z')
r = cos(z)**2 + sin(z)**2
assert r.simplify_trig() == 1
However, when z is a function of time, things break down entirely:
var('x,y,t,z')
θ1 = function('θ1')(t)
θ2 = function('θ2')(t)
K = sin(θ1)**2 + cos(θ1)**2
assert K.simplify_trig() == 1
Specifically, `K.simplify_trig()` throws:
> TypeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.
I would also expect
assert K.substitute_function(θ1, z) == cos(z)^2 + sin(z)^2
However `K.substitute_function(θ1, z)` just gives me K unchanged.
Seems related, but I'm still stumped: ask.sagemath.org/question/7856/lagranian-mechanics/calebhydeMon, 18 May 2020 04:25:54 +0200https://ask.sagemath.org/question/51442/Help with defining constraints in Lagrangianhttps://ask.sagemath.org/question/40908/help-with-defining-constraints-in-lagrangian/I am trying to maximize the function P, with constraints of x >= 75,000 and y >= 200,000. However, I do not think I am defining them correctly. I attempt to define them as arguments of the solve() function.
var('x','y', 'lam')
P = (0.05*x*(1-(x/150000) - 0.0000008*x*y)) + (0.08*y*(1-(y/200000) - 0.0000008*x*y))
diff(P, x)
-(4.00000000000000e-8)*x*y - (6.40000000000000e-8)*y^2 - (3.33333333333333e-7)*x*(0.120000000000000*y + 1) - (3.33333333333333e-7)*x + 0.0500000000000000
diff(P, y)
-(4.00000000000000e-8)*x^2 - (6.40000000000000e-8)*x*y - (4.00000000000000e-7)*(0.160000000000000*x + 1)*y - (4.00000000000000e-7)*y + 0.0800000000000000
solve([diff(P,x) == 0, diff(P,y) == 0, x >= 75000, y >= 200000], x, y, lam)
[[75000 < x, 200000 < y, -(4e-08)*x*y - (6.4e-08)*y^2 - (3.33333333333333e-07)*x*(0.12*y + 1) - (3.33333333333333e-07)*x + 0.05 == 0, -(4e-08)*x^2 - (6.4e-08)*x*y - ((6.4e-08)*x + 4e-07)*y - (4e-07)*y + 0.08 == 0], [x == 75000, 200000 < y, -(6.4e-08)*y^2 - 0.006*y == 0, -0.0096008*y - 224.92 == 0], [x == 75000, y == 200000, -3760.0 == 0, -2145.08 == 0], [y == 200000, 75000 < x, -0.01600066666666667*x - 2559.949999999999 == 0, -(4e-08)*x^2 - 0.0256*x - 0.08 == 0]]ds22Wed, 31 Jan 2018 23:26:36 +0100https://ask.sagemath.org/question/40908/How to define more complicated differential expressions in Sage?https://ask.sagemath.org/question/24983/how-to-define-more-complicated-differential-expressions-in-sage/ Dear Community,
i have a very hard time doing something pretty straight foreward in Sage. In mechanics, there is a Lagrange-formalism that yields the equation of motion of a system of $n$ degrees of freedom in the following way:
$$
0=\frac{d}{dt}\left(\frac{\partial L}{\partial x'_i(t)}\right) - \frac{\partial L}{\partial x_i(t)}
$$
where $L$ is the Lagrange function
$$
L=E_{Kin} (x'_{1}(t),x'_2(t)...x'_n(t); x_1(t),x_2(t)...x_n(t) ) - E _{Pot}(x_1(t),x_2(t),...,x_n(t))
$$
is the kinetic energy minus the potential energy. The kinetic energy depends on the speeds of the coordinates $x'_i(t)$, while the potential energy depends on the coordinates $x_i(t)$.
In Mathematica, the hack is
L = Ekin[x'[t]] - Epot[x[t]];
eq = 0 == D[D[L, x'[t]], t] - D[L, x[t]];
which gives
0 == Epot'[x[t]] + Ekin''[x'[t]] x''[t]
I can easily specify something for $E_{Kin}$ and $E_{Pot}$, solve the latter equation for $x''$, and give it as a right handside to some time integration scheme.
How can this be done in Sage? Assume you have complicated expressions for $E_{Pot}$ and $E_{Kin}$ which you do not want to differentiate by hand.
`var('L,x,t')`
`x = function('x',t)`
`L = function('L',x,t)`
allows for
`diff(L,t)`
but not
`diff(L,x)`
Thanks already!schneider chenMon, 24 Nov 2014 19:58:57 +0100https://ask.sagemath.org/question/24983/convex objective function with linear constrainthttps://ask.sagemath.org/question/7489/convex-objective-function-with-linear-constraint/for a no convex objective function with linear constraint, a lagrangian relaxation should work?
monseWed, 05 Oct 2011 21:46:01 +0200https://ask.sagemath.org/question/7489/