# f.mpl -- Generate code for the first and second derivatives of f # Written Nov 16, 2007 by Eric Olson for Math/CS 466/666 # # Maple script to create the file f.i containing the C code to compute # the gradient of f and the matrix J of second partials. restart; kernelopts(printbytes=false): with(codegen); f:=1-x^2-y^2+exp(-x^2-y^2+x+2*y+3); fx:=diff(f,x); fy:=diff(f,y); L:=array([fx,fy]); fxx:=diff(fx,x); fxy:=diff(fx,y); fyy:=diff(fy,y); J:=matrix([[fxx,fxy],[fxy,fyy]]); getvalue:=makeproc(f,[x,y]); getgrad:=makeproc(L,['L',x,y]); getjacobian:=makeproc(J,['J',x,y]); writeto("f.i"); printf("/* Automatically generated by f.mpl\n\n"); 'f'=f; printf("*/\n\n"); C(getvalue,optimized,ansi); C(getgrad,optimized,ansi); C(getjacobian,optimized,ansi); writeto(terminal);