/************************************* mataclass.do written 10/2007 by Russell Dimond Examples from http://ssc.wisc.edu/sscc/pubs/4-26.htm see also ex1.do and ex2.do ************************************/ mata mata clear end clear log using mataclass.log, replace /* Basics */ mata 2+2 x=2+2 x /* Column and Row Join Operators */ 1,2 1\2 1,2\3,4 /* Errors */ 1,2\3\4 1,\3\4 /* Parentheses */ 1,2\3,4 (1,2\3,4) (1,2)\(3,4) /* Range Operators */ 1..3 1::3 1.2..3.5 /* Variables */ x=3,4 y=5,6 z=(1,2)\x\y z /* Arithmatic Operators */ x=(1,2)\(3,4) y=(1,2)\(3,4) x*y x:*y /* Logical Operators */ x==y x>y xz x=1) { g=-4*x^3 if (todo==2) { H=-12*x^2 } } } function h(todo,x,y,g,H) { y=-x[1]^4-x[2]^4 } function i(todo,x,y,g,H) { y=J(2,1,.) y[1]=-x[1]^4 y[2]=-x[2]^4 } s=optimize_init() optimize_init_evaluator(s,&f()) optimize_init_params(s,-100) optimize(s) xmax=optimize(s) s=optimize_init() optimize_init_evaluator(s,&g()) optimize_init_evaluatortype(s,"d2") optimize_init_params(s,-100) optimize(s) s=optimize_init() optimize_init_evaluator(s,&h()) optimize_init_params(s,(-100,100)) optimize(s) s=optimize_init() optimize_init_evaluator(s,&i()) optimize_init_evaluatortype(s,"v0") optimize_init_params(s,(-100,100)) optimize(s) end log close