ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a50.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_dvmfexp(void);
00014 
00019 dvar_vector mfexp(const dvar_vector& v1)
00020 {
00021   //dvector cv1=value(v1);
00022   int mmin=v1.indexmin();
00023   int mmax=v1.indexmax();
00024   dvar_vector vtmp(mmin,mmax);
00025   for (int i=mmin;i<=mmax;i++)
00026   {
00027     if (v1.elem_value(i)<60.)
00028     {
00029       vtmp.elem_value(i)=exp(v1.elem_value(i));
00030     }
00031     else
00032     {
00033      double x=v1.elem_value(i)-60.;
00034      vtmp.elem_value(i)=exp(60.)*(1.+2.*x)/(1.+x);
00035     }
00036   }
00037 
00038   save_identifier_string("ddt");
00039   v1.save_dvar_vector_value();
00040   v1.save_dvar_vector_position();
00041   vtmp.save_dvar_vector_value();
00042   vtmp.save_dvar_vector_position();
00043   save_identifier_string("see");
00044   gradient_structure::GRAD_STACK1->
00045             set_gradient_stack(DF_dvmfexp);
00046   return vtmp;
00047 }
00048 
00053 void DF_dvmfexp(void)
00054 {
00055   // int ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00056   verify_identifier_string("see");
00057   dvar_vector_position tmp_pos=restore_dvar_vector_position();
00058   dvector dfvtmp=restore_dvar_vector_derivatives(tmp_pos);
00059   dvector vtmp=restore_dvar_vector_value(tmp_pos);
00060   dvar_vector_position v1pos=restore_dvar_vector_position();
00061   dvector v1=restore_dvar_vector_value(v1pos);
00062   verify_identifier_string("ddt");
00063   dvector dfv1(dfvtmp.indexmin(),dfvtmp.indexmax());
00064   for (int i=dfvtmp.indexmin();i<=dfvtmp.indexmax();i++)
00065   {
00066     //vtmp.elem(i)=mfexp(value(v1.elem(i))));
00067     if (v1.elem(i)<60)
00068     {
00069       dfv1(i)=dfvtmp(i)*vtmp.elem(i);
00070     }
00071     else
00072     {
00073       double b=v1.elem(i)-60.0;
00074       dfv1(i)=dfvtmp(i)*exp(60.0)*(1./(1.+b*b));
00075     }
00076   }
00077   dfv1.save_dvector_derivatives(v1pos);
00078   //ierr=fsetpos(gradient_structure::get_fp(),&filepos);
00079 }