ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a44.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include "fvar.hpp"
00012 
00013 void DF_dvsquare(void);
00014 
00019 dvar_vector square(const dvar_vector& v1)
00020 {
00021   //dvector cv1=value(v1);
00022 
00023   dvar_vector vtmp(v1.indexmin(),v1.indexmax());
00024   for (int i=v1.indexmin();i<=v1.indexmax();i++)
00025   {
00026     double x=v1.elem_value(i);
00027     vtmp.elem_value(i)=x*x;
00028   }
00029 
00030   save_identifier_string("sddd");
00031   v1.save_dvar_vector_value();
00032   v1.save_dvar_vector_position();
00033   vtmp.save_dvar_vector_position();
00034   save_identifier_string("eee");
00035   gradient_structure::GRAD_STACK1->
00036             set_gradient_stack(DF_dvsquare);
00037   return vtmp;
00038 }
00039 
00044 void DF_dvsquare(void)
00045 {
00046   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00047   verify_identifier_string("eee");
00048   dvar_vector_position tmp_pos=restore_dvar_vector_position();
00049   dvector dfvtmp=restore_dvar_vector_derivatives(tmp_pos);
00050   dvar_vector_position v1pos=restore_dvar_vector_position();
00051   dvector v1=restore_dvar_vector_value(v1pos);
00052   verify_identifier_string("sddd");
00053   dvector dfv1(dfvtmp.indexmin(),dfvtmp.indexmax());
00054   for (int i=dfvtmp.indexmin();i<=dfvtmp.indexmax();i++)
00055   {
00056     //vtmp.elem(i)=sin(value(v1.elem(i))));
00057     double x=v1.elem(i);
00058     dfv1(i)=dfvtmp(i)*2*x;
00059   }
00060   dfv1.save_dvector_derivatives(v1pos);
00061   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00062 }
00063 
00064 
00065 void DF_dvcube(void);
00066 
00071 dvar_vector cube(const dvar_vector& v1)
00072 {
00073   //dvector cv1=value(v1);
00074 
00075   dvar_vector vtmp(v1.indexmin(),v1.indexmax());
00076   for (int i=v1.indexmin();i<=v1.indexmax();i++)
00077   {
00078     double x=v1.elem_value(i);
00079     vtmp.elem_value(i)=x*x*x;
00080   }
00081 
00082   save_identifier_string("sssd");
00083   v1.save_dvar_vector_value();
00084   v1.save_dvar_vector_position();
00085   vtmp.save_dvar_vector_position();
00086   save_identifier_string("tee");
00087   gradient_structure::GRAD_STACK1->
00088             set_gradient_stack(DF_dvcube);
00089   return vtmp;
00090 }
00091 
00096 void DF_dvcube(void)
00097 {
00098   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00099   verify_identifier_string("tee");
00100   dvar_vector_position tmp_pos=restore_dvar_vector_position();
00101   dvector dfvtmp=restore_dvar_vector_derivatives(tmp_pos);
00102   dvar_vector_position v1pos=restore_dvar_vector_position();
00103   dvector v1=restore_dvar_vector_value(v1pos);
00104   verify_identifier_string("sssd");
00105   dvector dfv1(dfvtmp.indexmin(),dfvtmp.indexmax());
00106   for (int i=dfvtmp.indexmin();i<=dfvtmp.indexmax();i++)
00107   {
00108     //vtmp.elem(i)=sin(value(v1.elem(i))));
00109     double x=v1.elem(i);
00110     dfv1(i)=dfvtmp(i)*3*x*x;
00111   }
00112   dfv1.save_dvector_derivatives(v1pos);
00113   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00114 }
00115 
00116 void DF_dvfourth(void);
00117 
00122 dvar_vector fourth(const dvar_vector& v1)
00123 {
00124   //dvector cv1=value(v1);
00125 
00126   dvar_vector vtmp(v1.indexmin(),v1.indexmax());
00127   for (int i=v1.indexmin();i<=v1.indexmax();i++)
00128   {
00129     double x=v1.elem_value(i);
00130     double x2=x*x;
00131     vtmp.elem_value(i)=x2*x2;
00132   }
00133 
00134   save_identifier_string("ssf");
00135   v1.save_dvar_vector_value();
00136   v1.save_dvar_vector_position();
00137   vtmp.save_dvar_vector_position();
00138   save_identifier_string("gee");
00139   gradient_structure::GRAD_STACK1->
00140             set_gradient_stack(DF_dvfourth);
00141   return vtmp;
00142 }
00143 
00148 void DF_dvfourth(void)
00149 {
00150   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00151   verify_identifier_string("gee");
00152   dvar_vector_position tmp_pos=restore_dvar_vector_position();
00153   dvector dfvtmp=restore_dvar_vector_derivatives(tmp_pos);
00154   dvar_vector_position v1pos=restore_dvar_vector_position();
00155   dvector v1=restore_dvar_vector_value(v1pos);
00156   verify_identifier_string("ssf");
00157   dvector dfv1(dfvtmp.indexmin(),dfvtmp.indexmax());
00158   for (int i=dfvtmp.indexmin();i<=dfvtmp.indexmax();i++)
00159   {
00160     //vtmp.elem(i)=sin(value(v1.elem(i))));
00161     double x=v1.elem(i);
00162     dfv1(i)=dfvtmp(i)*4*x*x*x;
00163   }
00164   dfv1.save_dvector_derivatives(v1pos);
00165   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00166 }