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
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:
(and put the result into the equation form you request)
I believe this is what you are trying to do. You were close. I hope this is helpful.
Doug
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))