ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a48.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_cdble_dv_diveq(void);
00014 
00019 dvar_vector& dvar_vector::operator/=(const double x)
00020   {
00021     RETURN_ARRAYS_INCREMENT();
00022     save_identifier_string("wctf");
00023     double xinv=1./x;
00024     for (int i=indexmin(); i<=indexmax(); i++)
00025     {
00026       elem_value(i)*=xinv;
00027     }
00028     save_dvar_vector_position();
00029     save_double_value(x);
00030     save_identifier_string("cmtu");
00031     RETURN_ARRAYS_DECREMENT();
00032     gradient_structure::GRAD_STACK1->set_gradient_stack(DF_cdble_dv_diveq);
00033     return(*this);
00034   }
00035 
00040  void DF_cdble_dv_diveq(void)
00041  {
00042     verify_identifier_string("cmtu");
00043     double x=restore_double_value();
00044     dvar_vector_position this_pos=restore_dvar_vector_position();
00045     dvector dfthis=restore_dvar_vector_derivatives(this_pos);
00046     verify_identifier_string("wctf");
00047     double xinv=1./x;
00048     for (int i=dfthis.indexmax(); i>=dfthis.indexmin(); i--)
00049     {
00050       // elem_value(i)=elem_value(i)/x;
00051       dfthis(i)*=xinv;
00052     }
00053     dfthis.save_dvector_derivatives(this_pos);
00054  }
00055 
00056 
00057   void DF_vdble_dv_diveq(void);
00058 
00063 dvar_vector& dvar_vector::operator/=(const prevariable& x)
00064   {
00065     RETURN_ARRAYS_INCREMENT();
00066     double xinv=1./value(x);
00067     for (int i=indexmin(); i<=indexmax(); i++)
00068     {
00069       elem_value(i)=elem_value(i)*xinv;
00070     }
00071     save_identifier_string("wctg");
00072     save_dvar_vector_value();
00073     save_dvar_vector_position();
00074     x.save_prevariable_value();
00075     x.save_prevariable_position();
00076     save_identifier_string("cmtu");
00077     RETURN_ARRAYS_DECREMENT();
00078     gradient_structure::GRAD_STACK1->set_gradient_stack(DF_vdble_dv_diveq);
00079     return(*this);
00080   }
00081 
00086  void DF_vdble_dv_diveq(void)
00087  {
00088     verify_identifier_string("cmtu");
00089     prevariable_position x_pos=restore_prevariable_position();
00090     double dfx=restore_prevariable_derivative(x_pos);
00091     double x=restore_prevariable_value();
00092     dvar_vector_position this_pos=restore_dvar_vector_position();
00093     dvector tmp=restore_dvar_vector_value(this_pos);
00094     dvector dfthis=restore_dvar_vector_derivatives(this_pos);
00095     verify_identifier_string("wctg");
00096     double tmp1=0.;
00097     double xinv=1./x;
00098     int i;
00099     for (i=dfthis.indexmax(); i>=dfthis.indexmin(); i--)
00100     {
00101       // elem_value(i)=elem_value(i)/x;
00102       tmp1+=dfthis(i)*tmp(i);
00103     }
00104     tmp1*=-xinv;
00105 
00106     for (i=dfthis.indexmax(); i>=dfthis.indexmin(); i--)
00107     {
00108       // elem_value(i)=elem_value(i)/x;
00109       dfthis(i)*=xinv;
00110     }
00111     dfthis.save_dvector_derivatives(this_pos);
00112     save_double_derivative(dfx+tmp1,x_pos);
00113  }