ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
fvar_a49.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 #ifdef __TURBOC__
00014   #pragma hdrstop
00015   #include <iostream.h>
00016 #endif
00017 
00018 #ifdef __ZTC__
00019   #include <iostream.hpp>
00020 #endif
00021 
00022 #include <math.h>
00023 
00028 dvariable var(const dvar_vector& v)
00029   {
00030     dvariable tmp;
00031     RETURN_ARRAYS_INCREMENT();
00032     tmp=norm(v)/sqrt(double(v.size()));
00033     dvariable tmp1;
00034     tmp1=mean(v);
00035     RETURN_ARRAYS_DECREMENT();
00036     return(tmp*tmp-tmp1*tmp1);
00037   }
00038 
00043 dvariable std_dev(const dvar_vector& v)
00044   {
00045     dvariable tmp;
00046     RETURN_ARRAYS_INCREMENT();
00047     tmp=norm(v)/sqrt(double(v.size()));
00048     dvariable tmp1;
00049     tmp1=mean(v);
00050     RETURN_ARRAYS_DECREMENT();
00051     return(sqrt(tmp*tmp-tmp1*tmp1));
00052   }
00053 
00058 dvariable mean(const dvar_vector& v)
00059   {
00060     dvariable tmp;
00061     RETURN_ARRAYS_INCREMENT();
00062     tmp=sum(v)/double(v.size());
00063     RETURN_ARRAYS_DECREMENT();
00064     return(tmp);
00065   }