Derivation Current Value Hamiltonian. It should be as easy as 1-2-3-4

I want to be able to do the following in Maple
1) Set up the current value hamiltonian H:=u(c(t))+lambda(t)*(f(k)-c(t)-delta*k) ;
2) Take the foc with respect to c(t) which should give me u'(c(t))=lambda(t)
3) Differentiate with respect to time which should give me u''(c(t))*diff(c(t),t)=diff(lambda(t), t)
4) Divide both sides by u'(c(t))=lambda(t) should give me u''(c(t))*diff(c(t),t) / u'(c(t)) =diff(lambda(t), t) / lambda(t)

I have tried to set up the hamiltonian in maple but I find it quite hard for numerous reasons:

A) I cannot differentiate a function w.r.t a function i.e
H:=u(c(t))+lambda(t)*(f(k)-c(t)-delta*k) ;
foc_1:=diff(H,c(t))=0;
Error

B) Cannot isolate a function in an expression containing a function i.e
> foc_1;
> subs(u(c)=u(c(t)),%);
> isolate(%,lambda(t));
Error

C) If I use the sdiff function I still cannot isolate a function in an expression containing a function i.e
######
> restart;
> sdiff := proc(expr, sym)
> local t;
> subs(t=sym, diff( subs(sym=t,expr), t) );
> end;
#####
>H:=u(c(t))+lambda(t)*(f(k)-c(t)-delta*k) ;
>foc_1:=sdiff(H,c(t))=0;
>isolate(foc_1,lambda(t));
Error

D) I cannot differentiate a function w.r.t a function twice i.e
>diff( diff(u(c(t)),c(t)), c(t);
Error

Doug Meade's picture

as easy as 1-2-3-4

Nice problem. Good description of what you are trying to do, and the problems you are having.

I would solve this problem in the following four steps:

  • STEP 1: Define the Hamiltonian as a function of c (not c(t), that comes later)
H:=c -> u(c)+lambda(t)*(f(k)-c-delta*k) ;
  • STEP 2: Differentiate H(c) wrt c, then insert the dependence of c on t
foc_1 := D(H)(c(t));
                           D(u)(c(t)) - lambda(t)
  • STEP 3: Differentiate with respect to t
                   (and put the result into the equation form you request)
foc_2 := isolate( diff( foc_1, t )=0, c(t) );
                                  / d      \    d           
                @@(D, 2)(u)(c(t)) |--- c(t)| = --- lambda(t)
                                  \ dt     /    dt          
  • STEP 4: divide by lambda(t)
foc_2/lambda(t);
                                  / d      \    d           
                @@(D, 2)(u)(c(t)) |--- c(t)|   --- lambda(t)
                                  \ dt     /    dt          
                ---------------------------- = -------------
                         lambda(t)               lambda(t)  

I believe this is what you are trying to do. You were close. I hope this is helpful.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu       
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed

 

thanx Doug....I will have a

thanx Doug....I will have a try.... it looks like it might do the trick. Again thanx

with VariationalCalculus

H:=u(c(t))+lambda(t)*(f(k)-c(t)-delta*k); 
op(VariationalCalculus:-EulerLagrange( H, t, c(t))):
C:=isolate(%,lambda)(t);
Ct:=diff(%,t);
zip((a,b)->a/b,convert(Ct,list),convert(C,list)):
op(1,%)=op(2,%);

                      H := u(c(t))+lambda(t)*(f(k)-c(t)-delta*k)

                      C := lambda(t) = D(u)(c(t))

                                d                (2)           /d      \
                          Ct := -- lambda(t) = (D   )(u)(c(t)) |-- c(t)|
                                dt                             \dt     /
                             d                (2)           /d      \
                             -- lambda(t)   (D   )(u)(c(t)) |-- c(t)|
                             dt                             \dt     /
                             ------------ = -------------------------
                              lambda(t)            D(u)(c(t))

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}