Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Partial differentiation

I am trying to compute a partial differentiation of the sum of 3 utility functions (u0 + u1 + u2) with respect to s_t0. Is this the right way to do that in SageMath?

w = var('w'); 
tau_t0 = var('tau_t0'); tau_t1 = var('tau_t1'); 
s_t0 = var('s_t0'); s_t1 = var('s_t1')
r = var('r'); n = var('n')
u0 = function ('u0')(w, tau_t0, s_t0)
u1 = function ('u1')(w, tau_t1, s_t1)
u2 = function ('u2') (n, w, tau_t0, r, s_t0, s_t1)

u0(w, tau_t0, s_t0) = w*(1-tau_t0) - s_t0
u1(w, tau_t1, s_t1) = w*(1-tau_t1) - s_t1
u2(n, w, tau_t0, r, s_t0, s_t1) = (1+n)^2 * w * tau_t0 + (1+n) * w * tau_t0 + (1+r)^2 * s_t0 + (1+r) * s_t1

a = diff(u0 (w, tau_t0, s_t0), s_t0)
b = diff(u1 (w, tau_t1, s_t1), s_t0)
c = diff(u2 (n, w, tau_t0, r, s_t0, s_t1), s_t0)

U = a + b + c
U