ADMB Documentation  11.2.2828
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_ma3.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: fvar_ma3.cpp 1919 2014-04-22 22:02:01Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  */
00011 #include "fvar.hpp"
00012 
00013 /*
00014 dvar_vector operator*(const dvar_vector& x, const dmatrix& m)
00015  {
00016    RETURN_ARRAYS_INCREMENT();
00017 
00018    if (x.indexmin() != m.rowmin() || x.indexmax() != m.rowmax())
00019    {
00020      cerr << " Incompatible array bounds in dvar_vector  operator * (const dvar_vector& x,const dmatrix& m)\n";
00021      ad_exit(21);
00022    }
00023    dvar_vector tmp(m.colmin(),m.colmax());
00024 
00025    for (int j=m.colmin(); j<=m.colmax(); j++)
00026    {
00027      tmp[j]=0.0;
00028      for (int i=x.indexmin(); i<=x.indexmax(); i++)
00029      {
00030        tmp[j]+=x[i]*m[i][j];
00031      }
00032      //cout << "tmp[j]= "<< value(tmp[j])<<"\n";
00033    }
00034    RETURN_ARRAYS_DECREMENT();
00035    return(tmp);
00036  }
00037 
00038 dvar_vector operator*(const dmatrix& m, const dvar_vector& x)
00039  {
00040    RETURN_ARRAYS_INCREMENT();
00041 
00042    if (x.indexmin() != m.colmin() || x.indexmax() != m.colmax())
00043    {
00044      cerr << " Incompatible array bounds in dvar_vector  operator*(const dvar_vector& x, const dmatrix& m)\n";
00045      ad_exit(21);
00046    }
00047 
00048    dvar_vector tmp(m.rowmin(),m.rowmax());
00049 
00050    for (int i=m.rowmin(); i<=m.rowmax(); i++)
00051    {
00052      tmp[i]=0.0;
00053      for (int j=x.indexmin(); j<=x.indexmax(); j++)
00054      {
00055        tmp[i]+=m[i][j]*x[j];
00056      }
00057    }
00058    RETURN_ARRAYS_DECREMENT();
00059    return(tmp);
00060  }
00061 */
00062 
00067 dvariable norm(const dvar_matrix& m1)
00068     {
00069       RETURN_ARRAYS_INCREMENT();
00070 
00071       dvariable tmp;
00072       tmp=0.0;
00073       for (int i=m1.rowmin(); i<=m1.rowmax(); i++)
00074       {
00075         tmp+=norm2(m1.elem(i));
00076       }
00077       if (tmp>0.)
00078       {
00079         tmp=pow(tmp,.5);
00080       }
00081       else
00082       {
00083         tmp=0.0;
00084       }
00085       RETURN_ARRAYS_DECREMENT();
00086       return(tmp);
00087     }
00088 
00089 dvariable norm2(const dvar_matrix& m1)
00090     {
00091       RETURN_ARRAYS_INCREMENT();
00092 
00093       dvariable tmp;
00094       tmp=0.0;
00095       for (int i=m1.rowmin(); i<=m1.rowmax(); i++)
00096       {
00097         tmp+=norm2(m1.elem(i));
00098       }
00099       RETURN_ARRAYS_DECREMENT();
00100       return(tmp);
00101     }
00102 dvariable sumsq(const dvar_matrix& m1) {return(norm2(m1));}
00103 
00104    /*
00105     dvar_matrix trans(const dvar_matrix& m1)
00106     {
00107       RETURN_ARRAYS_INCREMENT();
00108 
00109       dvar_matrix tmp(m1.colmin(),m1.colmax(),m1.rowmin(),m1.rowmax());
00110 
00111       for (int i=m1.rowmin(); i<=m1.rowmax(); i++)
00112       {
00113         for (int j=m1.colmin(); j<=m1.colmax(); j++)
00114         {
00115           tmp.elem(j,i)=m1.elem(i,j);
00116         }
00117       }
00118       RETURN_ARRAYS_DECREMENT();
00119       return (tmp);
00120     }
00121    */
00122