void moveToConstReferenceNegatives() { // No warning when actual move takes place. MoveSemantics move_semantics; callByValue(std::move(move_semantics)); callByRValueRef(std::move(move_semantics)); MoveSemantics other(std::move(move_semantics)); other = std::move(move_semantics); // No warning if std::move() not used. NoMoveSemantics no_move_semantics; callByConstRef(no_move_semantics); // No warning if instantiating a template. templateFunction(no_move_semantics); // No warning inside of macro expansions. M3(NoMoveSemantics, no_move_semantics); // No warning inside of macro expansion, even if the macro expansion is inside // a lambda that is, in turn, an argument to a macro. CALL([no_move_semantics] { M3(NoMoveSemantics, no_move_semantics); }); auto lambda = [] {}; auto lambda2 = std::move(lambda); }
/* Adds an orientation observation to the "attitude profile matrix" B * * This is done with * B += a * W * V' * where * a is the weight of the current measurment (how good it is, how often...) * W is the observed vector * V' is the (transposed) reference direction, that belongs to W. * * See Davenport's solution for Wabha's problem for more information */ void add_orientation_measurement(struct DoubleMat33 *B, struct Orientation_Measurement a) { M3(*B, 0, 0) += a.weight_of_the_measurement * a.measured_direction.x * a.reference_direction.x; M3(*B, 0, 1) += a.weight_of_the_measurement * a.measured_direction.x * a.reference_direction.y; M3(*B, 0, 2) += a.weight_of_the_measurement * a.measured_direction.x * a.reference_direction.z; M3(*B, 1, 0) += a.weight_of_the_measurement * a.measured_direction.y * a.reference_direction.x; M3(*B, 1, 1) += a.weight_of_the_measurement * a.measured_direction.y * a.reference_direction.y; M3(*B, 1, 2) += a.weight_of_the_measurement * a.measured_direction.y * a.reference_direction.z; M3(*B, 2, 0) += a.weight_of_the_measurement * a.measured_direction.z * a.reference_direction.x; M3(*B, 2, 1) += a.weight_of_the_measurement * a.measured_direction.z * a.reference_direction.y; M3(*B, 2, 2) += a.weight_of_the_measurement * a.measured_direction.z * a.reference_direction.z; }
// ================================================= void DenseSubMatrix::left_multiply (const DenseMatrixBase& M2) { // (*this) <- M2 * M3 Where: (*this) = (m x n), M2= (m x p), M3= (p x n) // M3 is a simply a copy of *this DenseSubMatrix M3(*this); // Call the multiply function in the base class this->multiply(*this, M2, M3); }
int main() { vpMatrix M ; vpMatrix M1(2,3) ; vpMatrix M2(3,3) ; vpMatrix M3(2,2) ; std::cout << "** test matrix exception during multiplication" << std::endl; try { M = M1*M3 ; } catch (vpException &e) { std::cout << "Catch an exception: " << e << std::endl; } std::cout << "** test matrix exception during addition" << std::endl; try { M = M1+M3 ; } catch (vpException &e) { std::cout << "Catch an exception: " << e << std::endl; } }
static double strikeyH0 (MagComp component, const fault_params *fault, const magnetic_params *mag, double xi, double et, double qq, double y, double z) { double val; double h = mag->dcurier; double qd = y * sd + (fault->fdepth - h) * cd; double K2_val = K2 (component, 1.0, xi, et, qq); double log_re_val = log_re (component, 1.0, xi, et, qq); double J2_val = J2 (component, 1.0, xi, et, qq); // double L2_val = L2 (component, 1.0, xi, et, qq); double L2_val = L2 (component, 1.0, xi, et, qq) * cd; // todo: check this! double M2_val = M2 (component, 1.0, xi, et, qq); double M3_val = M3 (component, 1.0, xi, et, qq); double M2y_val = M2y (component, 1.0, xi, et, qq); double M2z_val = M2z (component, 1.0, xi, et, qq); val = - (2.0 - alpha4) * K2_val + alpha4 * log_re_val * sd + alpha3 * J2_val - alpha3 * (qd * M2_val + (z - h) * L2_val * sd) - 2.0 * alpha4 * h * (M2_val * cd - L2_val * sd) - 4.0 * alpha1 * h * L2_val * sd + 2.0 * alpha2 * h * M3_val * sd + 2.0 * alpha2 * h * ((qd + h * cd) * M2z_val - (z - 2.0 * h) * M2y_val * sd); return val; }
int main(int argc, char** argv) { Manoscritto M1(0, "aaa", "aaa", 10), M2(1, "bbb", "bbb", 10), M3(3, "bbb", "bbb", 10); Lettera L1(4, "aaa", "aaa", 10, "aaa", "aaa"), L2(5, "bbb", "bbb", 10, "bbb", "bbb"), L3=L1; cout <<"Stampa normale:\n"; cout << M1 <<'\n'<< M2 <<'\n' << M3 <<"\n\n"; cout << L1 <<'\n'<< L2 <<'\n' << L3 ; cout <<"\n\nStampa polimorfismo:\n"; Manoscritto * v[2]; v[0] = &M1; v[1] = &L2; for(int i=0; i<2; i++) { v[i] -> visualizzaDati(); cout<<'\n'; } cout <<"\n\nElenco:\n"; Elenco E1, E2; E1.push(&M1); E1.push(&M2); E1.push(&L1); E1.push(&L2); E1.push(&M3); E1.pop(0); E1.stampa(); ofstream file; file.open("./test.txt", ios::out); if(!file) { cout << "Errore file"; } else { E1.memorizzaDati(file); } file.close(); cout <<"\n\nEccezione:\n"; try { E2.push(&M1); E2.push(&M1); } catch (Duplicato e) { cout << e.what() << endl; } }
double TtbarHypothesis::M3() const { JetCollection jets; jets.clear(); jets.push_back(jet1FromW); jets.push_back(jet2FromW); jets.push_back(leptonicBjet); jets.push_back(hadronicBJet); return M3(jets); }
/////////////////////////////////////////////////////////////////////////////// // Ditto above, but for doubles void m3dRotationMatrix33(M3DMatrix33d m, double angle, double x, double y, double z) { double mag, s, c; double xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c; s = sin(angle); c = cos(angle); mag = sqrt( x*x + y*y + z*z ); // Identity matrix if (mag == 0.0) { m3dLoadIdentity33(m); return; } // Rotation matrix is normalized x /= mag; y /= mag; z /= mag; #define M3(row,col) m[col*3+row] xx = x * x; yy = y * y; zz = z * z; xy = x * y; yz = y * z; zx = z * x; xs = x * s; ys = y * s; zs = z * s; one_c = 1.0 - c; M3(0,0) = (one_c * xx) + c; M3(0,1) = (one_c * xy) - zs; M3(0,2) = (one_c * zx) + ys; M3(1,0) = (one_c * xy) + zs; M3(1,1) = (one_c * yy) + c; M3(1,2) = (one_c * yz) - xs; M3(2,0) = (one_c * zx) - ys; M3(2,1) = (one_c * yz) + xs; M3(2,2) = (one_c * zz) + c; #undef M3 }
SCMatrix operator-(const SCMatrix& M1,const SCMatrix& M2){ if (M1.Rows() != M2.Rows() || M1.Columns() != M2.Columns()){ cerr<<"Incompatible dimensions for matrix addition."<<endl; exit(1); } SCMatrix M3(M1.Rows(),M1.Columns()); for (int i=0;i<M1.Rows();i++){ for (int j=0;j<M1.Columns();j++){ M3.data[i][j]=M1.data[i][j]-M2.data[i][j]; } } return M3; }
static void ggcm_mhd_diag_item_v_run(struct ggcm_mhd_diag_item *item, struct mrc_io *io, struct mrc_fld *fld, int diag_type, float plane) { struct ggcm_mhd *mhd = item->diag->mhd; int bnd = fld->_nr_ghosts; struct mrc_fld *fld_r = mrc_domain_fld_create(mhd->domain, bnd, "vx:vy:vz"); mrc_fld_set_type(fld_r, FLD_TYPE); mrc_fld_setup(fld_r); struct mrc_fld *r = mrc_fld_get_as(fld_r, FLD_TYPE); struct mrc_fld *f = mrc_fld_get_as(fld, FLD_TYPE); for (int p = 0; p < mrc_fld_nr_patches(fld); p++) { mrc_fld_foreach(f, ix,iy,iz, bnd, bnd) { mrc_fld_data_t rri = 1.f / RR_(f, ix,iy,iz, p); M3(r, 0, ix,iy,iz, p) = rri * RVX_(f, ix,iy,iz, p); M3(r, 1, ix,iy,iz, p) = rri * RVY_(f, ix,iy,iz, p); M3(r, 2, ix,iy,iz, p) = rri * RVZ_(f, ix,iy,iz, p); } mrc_fld_foreach_end; }
int main (int narg, const char** argv) { typedef Range<false> R; typedef Range<true> CR; Matrix<double> M1(10, 1), M2, M3(M1), M4(3, 4), M6(4, 3), M5(3, 4, 2), M7(3, 4, 2), M8, M9, M10, M11; M1 = 0.0; M2 = M1; for (size_t i = 1; i < M1.Size(); ++i) M1[i] = i; for (size_t i = 1; i < M4.Size(); ++i) M4[i] = i; for (size_t i = 1; i < M5.Size(); ++i) M5[i] = i; M3(R(7,-2,2)) = M1(CR(2,4)); M6(R(3,-2,0),R(0,1)) = M4(CR(0,1),CR(1,2)); M7(R(2,-2,0),R(0,1),R(0,0)) = M5(CR(0,1),CR(1,2),CR(0,0)); M8 = M6(CR(1,-1,0),CR(1,2)); M6(R(0,1),R(1,2)) = M8; M9 = M6(CR("1:-1:0"),CR("1:2")); M10 = M6(CR("1:-1:0,1"),CR("1:2")); M11 = M6(CR(),CR()) * M6(CR(),CR()); M11 = M6 * M6(CR(),CR()); std::cout << M3 << std::endl<< std::endl; std::cout << M4 << std::endl<< std::endl; std::cout << M6 << std::endl<< std::endl; std::cout << M5 << std::endl<< std::endl; std::cout << M7 << std::endl<< std::endl; std::cout << M8 << std::endl<< std::endl; std::cout << M9 << std::endl<< std::endl; std::cout << M10 << std::endl<< std::endl; std::cout << M11 << std::endl<< std::endl; return 0; }
static double strikezHIII (MagComp component, const fault_params *fault, const magnetic_params *mag, double xi, double et, double qq, double y, double z) { double val; double h = mag->dcurier; double qd = y * sd + (fault->fdepth - h) * cd; double K3_val = K3 (component, 1.0, xi, et, qq); double log_re_val = log_re (component, 1.0, xi, et, qq); double M2_val = M2 (component, 1.0, xi, et, qq); double M3_val = M3 (component, 1.0, xi, et, qq); val = alpha5 * K3_val + fault->alpha * log_re_val * cd + alpha3 * (qd * M3_val - (z - h) * M2_val * sd); return val; }
static void ggcm_mhd_bnd_open_x_fill_ghosts_fcons_cc(struct ggcm_mhd_bnd *bnd, struct mrc_fld *fld, float bntim) { struct ggcm_mhd *mhd = bnd->mhd; struct mrc_fld *f = mrc_fld_get_as(fld, FLD_TYPE); int gdims[3]; mrc_domain_get_global_dims(mhd->domain, gdims); int sw_y = gdims[1] > 1 ? SW_2 : 0; int sw_z = gdims[2] > 1 ? SW_2 : 0; assert(mrc_fld_nr_patches(f) == 1); int p = 0; const int *ldims = mrc_fld_spatial_dims(f); int mx = ldims[0]; struct mrc_patch_info info; mrc_domain_get_local_patch_info(mhd->domain, 0, &info); int nr_comps = mrc_fld_nr_comps(f); if (info.off[0] == 0) { // x lo FIXME, there is (?) a function for this for (int k = -sw_z; k < ldims[2] + sw_z; k++) { for (int j = -sw_y; j < ldims[1] + sw_y; j++) { for (int m = 0; m < nr_comps; m++) { M3(f, m, -1,j,k, p) = M3(f, m, 0,j,k, p); M3(f, m, -2,j,k, p) = M3(f, m, 1,j,k, p); } } } } if (info.off[0] + info.ldims[0] == gdims[0]) { // x hi for (int k = -sw_z; k < ldims[2] + sw_z; k++) { for (int j = -sw_y; j < ldims[1] + sw_y; j++) { for (int m = 0; m < nr_comps; m++) { M3(f, m, mx ,j,k, p) = M3(f, m, mx-1,j,k, p); M3(f, m, mx+1,j,k, p) = M3(f, m, mx-2,j,k, p); } } } } mrc_fld_put_as(f, fld); }
TEST(ResMonoidDense, create) { ResMonoidDense M1(4, std::vector<int>{1, 1, 1, 1}, std::vector<int>{}, MonomialOrderingType::GRevLex); ResMonoidDense M2(4, std::vector<int>{1, 2, 3, 4}, std::vector<int>{1, 1, 1, 1, 1, 1, 0, 0}, MonomialOrderingType::Weights); ResMonoidDense M3(4, std::vector<int>{1, 1, 1, 1}, std::vector<int>{}, MonomialOrderingType::Lex); EXPECT_EQ(4, M1.n_vars()); std::vector<res_monomial_word> monomspace(100); EXPECT_EQ(100, monomspace.size()); }
void DenseMatrix<T>::left_multiply (const DenseMatrixBase<T>& M2) { if (this->use_blas_lapack) this->_multiply_blas(M2, LEFT_MULTIPLY); else { // (*this) <- M2 * (*this) // Where: // (*this) = (m x n), // M2 = (m x p), // M3 = (p x n) // M3 is a copy of *this before it gets resize()d DenseMatrix<T> M3(*this); // Resize *this so that the result can fit this->resize (M2.m(), M3.n()); // Call the multiply function in the base class this->multiply(*this, M2, M3); } }
static double strikezH0 (MagComp component, const fault_params *fault, const magnetic_params *mag, double xi, double et, double qq, double y, double z) { double val; double h = mag->dcurier; double qd = y * sd + (fault->fdepth - h) * cd; double K3_val = K3 (component, 1.0, xi, et, qq); double log_re_val = log_re (component, 1.0, xi, et, qq); double M2_val = M2 (component, 1.0, xi, et, qq); double M3_val = M3 (component, 1.0, xi, et, qq); double M3y_val = M3y (component, 1.0, xi, et, qq); double M3z_val = M3z (component, 1.0, xi, et, qq); val = - (2.0 + alpha5) * K3_val - fault->alpha * log_re_val * cd - alpha3 * (qd * M3_val - (z - h) * M2_val * sd) + 2.0 * fault->alpha * h * (M3_val * cd + M2_val * sd) - 4.0 * alpha1 * h * M2_val * sd - 2.0 * alpha2 * h * M2_val * sd - 2.0 * alpha2 * h * ((qd + h * cd) * M3z_val - (z - 2.0 * h) * M3y_val * sd); return val; }
int main() { try { vpMatrix M ; vpMatrix M1(2,3) ; vpMatrix M2(3,3) ; vpMatrix M3(2,2) ; vpTRACE("test matrix size in multiply") ; try { M = M1*M3 ; } catch (vpMatrixException me) { std::cout << me << std::endl ; } vpTRACE("test matrix size in addition") ; try { M = M1+M3 ; } catch (vpMatrixException me) { std::cout << me << std::endl ; } } catch(vpException e) { std::cout << "Catch an exception: " << e << std::endl; return 1; } }
static void ggcm_mhd_bnd_open_x_fill_ghosts_scons(struct ggcm_mhd_bnd *bnd, struct mrc_fld *fld, float bntim) { struct ggcm_mhd *mhd = bnd->mhd; struct mrc_fld *f3 = mrc_fld_get_as(fld, FLD_TYPE); assert(mrc_fld_nr_patches(f3) == 1); int p = 0; int gdims[3]; mrc_domain_get_global_dims(mhd->domain, gdims); int dy = (gdims[1] > 1), dz = (gdims[2] > 1); int sw_y = gdims[1] > 1 ? SW_2 : 0; int sw_z = gdims[2] > 1 ? SW_2 : 0; const int *dims = mrc_fld_dims(f3); int nx = dims[0], ny = dims[1], nz = dims[2]; struct mrc_patch_info info; mrc_domain_get_local_patch_info(mhd->domain, 0, &info); float *bd2x = ggcm_mhd_crds_get_crd(mhd->crds, 0, BD2); float *bd2y = ggcm_mhd_crds_get_crd(mhd->crds, 1, BD2); float *bd2z = ggcm_mhd_crds_get_crd(mhd->crds, 2, BD2); // fill boundary values with closes non-zero value // FIXME: should this be necessary? bd2x[-2] = bd2x[0]; bd2x[-1] = bd2x[0]; bd2x[nx] = bd2x[nx-1]; bd2x[nx+1] = bd2x[nx-1]; bd2y[-2] = bd2y[0]; bd2y[-1] = bd2y[0]; bd2y[ny] = bd2y[ny-1]; bd2y[ny+1] = bd2y[ny-1]; bd2z[-2] = bd2z[0]; bd2z[-1] = bd2z[0]; bd2z[nz] = bd2z[nz-1]; bd2z[nz+1] = bd2z[nz-1]; //-----------------------------------------------------------------------------------// // lower bound //-----------------------------------------------------------------------------------// if (info.off[0] == 0) { // x lo // transverse magnetic extrapolated for (int iz = -sw_z; iz < nz + sw_z; iz++) { for (int iy = -sw_y; iy < ny + sw_y; iy++) { // bd1y and bd2y indices offset by one M3(f3,BY, -1,iy,iz, p) = M3(f3,BY, 0,iy,iz, p); M3(f3,BZ, -1,iy,iz, p) = M3(f3,BZ, 0,iy,iz, p); } } // set normal magnetic field component for divB=0 for (int iz = -sw_z; iz < nz + sw_z; iz++) { for (int iy = -sw_y; iy < ny + sw_y; iy++) { M3(f3,BX, -1,iy,iz, p) = M3(f3,BX, 0,iy,iz, p) + bd2x[0] * ((M3(f3,BY, 0,iy,iz, p) - M3(f3,BY, 0,iy-dy,iz, p) ) / bd2y[iy] + (M3(f3,BZ, 0,iy,iz, p) - M3(f3,BZ, 0,iy,iz-dz, p) ) / bd2z[iz]); } } // transverse magnetic field extrapolated for (int iz = -sw_z; iz < nz + sw_z; iz++) { for (int iy = -sw_y; iy < ny + sw_y; iy++) { // bd1x and bd2y indices offset by one M3(f3,BY, -2,iy,iz, p) = M3(f3,BY, 1,iy,iz, p); M3(f3,BZ, -2,iy,iz, p) = M3(f3,BZ, 1,iy,iz, p); } } // set normal magnetic field component for divB=0 for (int iz = -sw_z; iz < nz + sw_z; iz++) { for (int iy = -sw_y; iy < ny + sw_y; iy++) { M3(f3,BX, -2,iy,iz, p) = M3(f3,BX, -1,iy,iz, p) + bd2x[-1] * ((M3(f3,BY, -1,iy,iz, p) - M3(f3,BY, -1,iy-dy,iz, p) ) / bd2y[iy] + (M3(f3,BZ, -1,iy,iz, p) - M3(f3,BZ, -1,iy,iz-dz, p) ) / bd2z[iz]); } } for (int iz = -sw_z; iz < nz + sw_z; iz++) { for (int iy = -sw_y; iy < ny + sw_y; iy++) { M3(f3,RVX, -1,iy,iz, p) = M3(f3,RVX, 0,iy,iz, p); M3(f3,RVX, -2,iy,iz, p) = M3(f3,RVX, 1,iy,iz, p); M3(f3,RR, -1,iy,iz, p) = M3(f3,RR, 0,iy,iz, p); M3(f3,RR, -2,iy,iz, p) = M3(f3,RR, 1,iy,iz, p); M3(f3,RVY, -1,iy,iz, p) = M3(f3,RVY, 0,iy,iz, p); M3(f3,RVY, -2,iy,iz, p) = M3(f3,RVY, 1,iy,iz, p); M3(f3,RVZ, -1,iy,iz, p) = M3(f3,RVZ, 0,iy,iz, p); M3(f3,RVZ, -2,iy,iz, p) = M3(f3,RVZ, 1,iy,iz, p); M3(f3,UU, -1,iy,iz, p) = M3(f3,UU, 0,iy,iz, p); M3(f3,UU, -2,iy,iz, p) = M3(f3,UU, 1,iy,iz, p); } } } //-----------------------------------------------------------------------------------// // upper bound //-----------------------------------------------------------------------------------// if (info.off[0] + info.ldims[0] == gdims[0]) { // x hi // transverse magnetic field extrapolated for (int iz = -sw_z; iz < nz + sw_z; iz++) { for (int iy = -sw_y; iy < ny + sw_y; iy++) { M3(f3,BY, nx,iy,iz, p) = M3(f3, BY, nx-1,iy,iz, p); M3(f3,BZ, nx,iy,iz, p) = M3(f3, BZ, nx-1,iy,iz, p); } } // set normal magnetic field component for divB=0 for (int iz = -sw_z; iz < nz + sw_z; iz++) { for (int iy = -sw_y; iy < ny + sw_y; iy++) { M3(f3,BX, nx-1,iy,iz, p) = M3(f3,BX, nx-2,iy,iz, p) - bd2x[nx-1] * ((M3(f3,BY, nx-1,iy,iz, p) - M3(f3,BY, nx-1,iy-dy,iz, p) ) / bd2y[iy] + (M3(f3,BZ, nx-1,iy,iz, p) - M3(f3,BZ, nx-1,iy,iz-dz, p) ) / bd2z[iz]); } } // transverse magnetic field extrapolated for (int iz = -sw_z; iz < nz + sw_z; iz++) { for (int iy = -sw_y; iy < ny + sw_y; iy++) { M3(f3,BY, nx+1,iy,iz, p) = M3(f3, BY, nx-2,iy,iz, p); M3(f3,BZ, nx+1,iy,iz, p) = M3(f3, BZ, nx-2,iy,iz, p); } } // set normal magnetic field component for divB=0 for (int iz = -sw_z; iz < nz + sw_z; iz++) { for (int iy = -sw_y; iy < ny + sw_y; iy++) { M3(f3,BX, nx,iy,iz, p) = M3(f3,BX, nx-1,iy,iz, p) - bd2x[nx] * ((M3(f3,BY, nx,iy,iz, p) - M3(f3,BY, nx,iy-dy,iz, p) ) / bd2y[iy] + (M3(f3,BZ, nx,iy,iz, p) - M3(f3,BZ, nx,iy,iz-dz, p) ) / bd2z[iz]); } } for (int iz = -sw_z; iz < nz + sw_z; iz++) { for (int iy = -sw_y; iy < ny + sw_y; iy++) { M3(f3,RVX, nx+1,iy,iz, p) = M3(f3,RVX, nx-2,iy,iz, p); M3(f3,RVX, nx,iy,iz, p) = M3(f3,RVX, nx-1,iy,iz, p); M3(f3,RR, nx+1,iy,iz, p) = M3(f3,RR, nx-2,iy,iz, p); M3(f3,RR, nx,iy,iz, p) = M3(f3,RR, nx-1,iy,iz, p); M3(f3,RVY, nx+1,iy,iz, p) = M3(f3,RVY, nx-2,iy,iz, p); M3(f3,RVY, nx,iy,iz, p) = M3(f3,RVY, nx-1,iy,iz, p); M3(f3,RVZ, nx+1,iy,iz, p) = M3(f3,RVZ, nx-2,iy,iz, p); M3(f3,RVZ, nx,iy,iz, p) = M3(f3,RVZ, nx-1,iy,iz, p); M3(f3,UU, nx+1,iy,iz, p) = M3(f3,UU, nx-2,iy,iz, p); M3(f3,UU, nx,iy,iz, p) = M3(f3,UU, nx-1,iy,iz, p); } } } mrc_fld_put_as(f3, fld); }
/* This function generates the "K"-matrix out of an attitude profile matrix * * I don't know the real name of the "K"-Matrix, but everybody (see References from the other functions) * calls it "K", so I do it as well. */ struct DoubleMat44 generate_K_matrix(struct DoubleMat33 B) { struct DoubleMat44 K; double traceB = RMAT_TRACE(B); double z1 = M3(B, 1, 2) - M3(B, 2, 1); double z2 = M3(B, 2, 0) - M3(B, 0, 2); double z3 = M3(B, 0, 1) - M3(B, 1, 0); /** The "K"-Matrix. See the references for it **/ /* Fill the upper triangle matrix */ M4(K, 0, 0) = traceB; M4(K, 0, 1) = z1; M4(K, 0, 2) = z2; M4(K, 0, 3) = z3; M4(K, 1, 1) = 2 * M3(B, 0, 0) - traceB; M4(K, 1, 2) = M3(B, 0, 1) + M3(B, 1, 0); M4(K, 1, 3) = M3(B, 0, 2) + M3(B, 2, 0); M4(K, 2, 2) = 2 * M3(B, 1, 1) - traceB; M4(K, 2, 3) = M3(B, 1, 2) + M3(B, 2, 1); M4(K, 3, 3) = 2 * M3(B, 2, 2) - traceB; /* Copy to lower triangle matrix */ M4(K, 1, 0) = M4(K, 0, 1); M4(K, 2, 0) = M4(K, 0, 2); M4(K, 2, 1) = M4(K, 1, 2); M4(K, 3, 0) = M4(K, 0, 3); M4(K, 3, 1) = M4(K, 1, 3); M4(K, 3, 2) = M4(K, 2, 3); return K; }
//declared the function for rho4 from rho3 double rho4(double r, double m, double p) { double Fn = rho(r+h,m+h*M3(r,m,p),p+h*rho3(r,m,p)); return Fn; }
inline V3 Contact::calculate_friction_impulse(M3* inv_inertia_tensor) { F inverse_mass = bodies[0]->get_inverse_mass(); auto o = relative_contact_position[0]; //Usually you get a torque from an impulse by a cross product with the relative distance. //If we build a M3 from the relative distance in this way, we have a matrix //that goes from impulse to torque M3 impulse_to_torque = -M3( 0, -o.z, o.y, o.z, 0, -o.x, -o.y, o.x, 0 ); M3 delta_vel_world = impulse_to_torque; delta_vel_world *= inv_inertia_tensor[0]; //Rotation generated by unit torque delta_vel_world *= impulse_to_torque; //Same as crossing the relative contact pos. Gives linear vel generated by torque only delta_vel_world *= -1; //M1 x M2 = - M2 x M1, thus the minus // Check if we need to the second body's data if (bodies[1]) { auto o = relative_contact_position[1]; impulse_to_torque = -M3( 0, -o.z, o.y, o.z, 0, -o.x, -o.y, o.x, 0 ); M3 delta_vel_world_2 = impulse_to_torque; delta_vel_world_2 *= inv_inertia_tensor[1]; //Rotation generated by unit torque delta_vel_world_2 *= impulse_to_torque; //Same as crossing the relative contact pos. Gives linear vel generated by torque only delta_vel_world_2 *= -1; //M1 x M2 = - M2 x M1, thus the minus //combine velocities and masses delta_vel_world += delta_vel_world_2; inverse_mass += bodies[1]->get_inverse_mass(); } //change base of matrix (B x M x B^-1) to get velocity in contact coords M3 delta_velocity = transpose(contact_to_world) * delta_vel_world * contact_to_world; //Add the linear velocity. Need to build a matrix like this: //m,0,0 //0,m,0 //0,0,m delta_velocity[0].x += inverse_mass; delta_velocity[1].y += inverse_mass; delta_velocity[2].z += inverse_mass; //From: //unit velocity generated by impulse //To: //Impulse requires to generate unit velocity M3 impulse_matrix = inverse(delta_velocity); //Velocities to kill. The x element is the same as the frictionless impulse //and must be completely null out V3 vel_kill(desired_delta_velocity, -contact_velocity.y, -contact_velocity.z); //Get impulse necessary to kill the velocities V3 impulse_contact = impulse_matrix * vel_kill; //Get only the planar impulse F planar_impulse = sqrt(impulse_contact.y*impulse_contact.y + impulse_contact.z * impulse_contact.z); //The X of the impulse is the one along the normal. //This impulse, multiplied by friction, is the amount to overcome. //If the planar is greater, than there is enough force for dynamic friction if (planar_impulse > impulse_contact.x * friction) { impulse_contact.y /= planar_impulse; impulse_contact.z /= planar_impulse; //Recalculate delta_velocity (and store it in impulse_contact.X just for caching) impulse_contact.x = delta_velocity[0].x + delta_velocity[1].x * impulse_contact.y * friction + delta_velocity[2].x * impulse_contact.z * friction; impulse_contact.x = desired_delta_velocity / impulse_contact.x; impulse_contact.y *= friction * impulse_contact.x; impulse_contact.z *= friction * impulse_contact.x; } return impulse_contact; }
void lidarBoostEngine::build_superresolution(short coeff) { std::cout<< "Num of clouds : " << Y.size() << std::endl; // std::cout << Y[0] << std::endl; beta = coeff; std::vector < MatrixXd > optflow = lk_optical_flow( Y[2], Y[4], 10 ); MatrixXd D( beta*n, beta*m ); //, X( beta*n, beta*m ); // SparseMatrix<double> W( beta*n, beta*m ), T( beta*n, beta*m ); D = apply_optical_flow(Y[2], optflow); T = check_unreliable_samples(intensityMap[2], 0.0001); MatrixXd up_D = nearest_neigh_upsampling(D); //// Display and Debug cv::Mat M(n, m, CV_32FC1); // MatrixXd diff1(n, m); // diff1 = MatrixXd::Ones(n, m) - Y[0]; cv::eigen2cv(Y[2], M); cv::Mat M1(n, m, CV_32FC1); cv::eigen2cv(Y[4], M1); // MatrixXd diff(beta*n, beta*m); // diff = MatrixXd::Ones(beta*n, beta*m) - up_D; cv::Mat M2(beta*n, beta*m, CV_32FC1); cv::eigen2cv(up_D, M2); cv::namedWindow("check", cv::WINDOW_AUTOSIZE ); cv::imshow("check", M); cv::namedWindow("check1", cv::WINDOW_AUTOSIZE ); cv::imshow("check1", M1); cv::namedWindow("check2", cv::WINDOW_AUTOSIZE ); cv::imshow("check2", M2); //// Solve example equation with eigen // Eigen::VectorXd x(2); // x(0) = 10.0; // x(1) = 25.0; // std::cout << "x: " << x << std::endl; // my_functor functor; // Eigen::NumericalDiff<my_functor> numDiff(functor); // Eigen::LevenbergMarquardt<Eigen::NumericalDiff<my_functor>,double> lm(numDiff); // lm.parameters.maxfev = 2000; // lm.parameters.xtol = 1.0e-10; // std::cout << lm.parameters.maxfev << std::endl; // int ret = lm.minimize(x); // std::cout << lm.iter << std::endl; // std::cout << ret << std::endl; // std::cout << "x that minimizes the function: " << x << std::endl; ////// Try to solve lidarboost with Eigen // my_functor functor; // Eigen::NumericalDiff<my_functor> numDiff(functor); // Eigen::LevenbergMarquardt<Eigen::NumericalDiff<my_functor>,double> lm(numDiff); // lm.parameters.maxfev = 2000; // lm.parameters.xtol = 1.0e-10; // std::cout << lm.parameters.maxfev << std::endl; // VectorXd val(2); // for(int i = 0; i < X.rows(); i++) // { // for(int j = 0; j < X.cols(); j++) // { // val = X(i, j); // int ret = lm.minimize(val); // } // } // std::cout << lm.iter << std::endl; // std::cout << ret << std::endl; // std::cout << "x that minimizes the function: " << X << std::endl; //// Solve example using ceres // The variable to solve for with its initial value. // double initial_x = 5.0; // double x = initial_x; MatrixXd X(beta*n, beta*m);// init_X(beta*n, beta*m); // X = MatrixXd::Zero(beta*n,beta*m); X = up_D; // MatrixXd init_X( beta*n, beta*m ); // init_X = X; // int M[2][2], M2[2][2]; // M[0][0] = 5; // M[1][0] = 10; // M[0][1] = 20; // M[1][1] = 30; // M2 = *M; // Build the problem. Problem problem; // Set up the only cost function (also known as residual). This uses // auto-differentiation to obtain the derivative (jacobian). double val, w, t, d; Solver::Options options; options.linear_solver_type = ceres::DENSE_QR; options.minimizer_progress_to_stdout = false; Solver::Summary summary; for(int i = 0; i < X.rows(); i++) { for(int j = 0; j < X.cols(); j++) { val = X(i, j); w = W(i, j); t = T(i, j); d = up_D(i, j); std::cout << "i = " << i << "; j = " << j << std::endl; std::cout << "w = " << w << "; t = " << t << "; d = " << d << std::endl; CostFunction* cost_function = new AutoDiffCostFunction<CostFunctor, 1, 1>(new CostFunctor(w, t, d)); problem.AddResidualBlock(cost_function, NULL, &val); // Run the solver Solve(options, &problem, &summary); X(i, j) = val; } } std::cout << summary.BriefReport() << "\n"; // std::cout << "x : " << init_X // << " -> " << X << "\n"; cv::Mat M3(beta*n, beta*m, CV_32FC1); cv::eigen2cv(X, M3); cv::namedWindow("check3", cv::WINDOW_AUTOSIZE ); cv::imshow("check3", M3); }
void main() //main code { printf("\nRUNGE-KUTTA METHOD\n\nR M Rho\n"); //printing titles for values displayed double c = 10.0; //the parameter rho(c) int n; //the integer steps, n //declare arrays float x[N]; float y[N]; float z[N]; //r,m,p as the radius, mass and density double r,m,p; //declare initial conditons for arrays x[0] = h; //first array is for r=h y[0] = (h*h*h/3)*c; //initial conditon for scaled mass (m) z[0] = c*(1-((h*h*c)/(6*gamma(c)))); //initial conditon for rho //for loop for n=0,1,...,200 for(n=0;n<N;n++) { //declared how x(n+1) relates to x(n), y(n+1) relates to y(n), z(n+1) relates to z(n) x[n+1] = x[n]+h; y[n+1] = y[n]+(h/6)*(M(x[n],y[n],z[n])+2*M2(x[n],y[n],z[n])+2*M3(x[n],y[n],z[n])+M4(x[n],y[n],z[n])); z[n+1] = z[n]+(h/6)*(rho(x[n],y[n],z[n])+2*rho2(x[n],y[n],z[n])+2*rho3(x[n],y[n],z[n])+rho4(x[n],y[n],z[n])); if(isnan(z[n+1])) { break; } //r,m,p will be declared in pg-plot r = x[n+1]; m = y[n+1]; p = z[n+1]; printf("%.2e %.2e %.2e\n",x[n+1],y[n+1],z[n+1]); //printed values for x and y respectively } //Use pg-plot to plot mass and density // cpgbeg starts a plotting page, in this case with 2x1 panels cpgbeg(0,"?",2,1); // sets colour: 1-black, 2-red, 3-green, 4-blue cpgsci(1); // sets line style: 1-solid, 2-dashed, 3-dot-dashed, 4-dotted cpgsls(1); // sets charachter height, larger number = bigger cpgsch(1.); // cpgpage() moves to the next panel cpgpage(); // sets the axes limits in the panel cpgswin(0,r,0,m); // draw the axes cpgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0); // label the bottom axis cpgmtxt("B",2.,.5,.5,"radius"); // label the left axis cpgmtxt("L",2.5,.5,.5,"saclaed mass"); // connect N points in ax and ay with a line cpgline(n,x,y); // cpgpage() moves to the next panel cpgpage(); // sets the axes limits in the panel cpgswin(0,r,0,c); // draw the axes cpgbox("BCNST", 0.0, 0, "BCNST", 0.0, 0); // label the bottom axis cpgmtxt("B",2.,.5,.5,"radius"); // label the left axis cpgmtxt("L",2.5,.5,.5,"density"); // connect N points in ax and ay with a line cpgline(n,x,z); // close all pgplot applications cpgend(); // end program return; }
void FastMatmulRecursive(LockAndCounter& locker, MemoryManager<Scalar>& mem_mngr, Matrix<Scalar>& A, Matrix<Scalar>& B, Matrix<Scalar>& C, int total_steps, int steps_left, int start_index, double x, int num_threads, Scalar beta) { // Update multipliers C.UpdateMultiplier(A.multiplier()); C.UpdateMultiplier(B.multiplier()); A.set_multiplier(Scalar(1.0)); B.set_multiplier(Scalar(1.0)); // Base case for recursion if (steps_left == 0) { MatMul(A, B, C); return; } Matrix<Scalar> A11 = A.Subblock(2, 2, 1, 1); Matrix<Scalar> A12 = A.Subblock(2, 2, 1, 2); Matrix<Scalar> A21 = A.Subblock(2, 2, 2, 1); Matrix<Scalar> A22 = A.Subblock(2, 2, 2, 2); Matrix<Scalar> B11 = B.Subblock(2, 2, 1, 1); Matrix<Scalar> B12 = B.Subblock(2, 2, 1, 2); Matrix<Scalar> B21 = B.Subblock(2, 2, 2, 1); Matrix<Scalar> B22 = B.Subblock(2, 2, 2, 2); Matrix<Scalar> C11 = C.Subblock(2, 2, 1, 1); Matrix<Scalar> C12 = C.Subblock(2, 2, 1, 2); Matrix<Scalar> C21 = C.Subblock(2, 2, 2, 1); Matrix<Scalar> C22 = C.Subblock(2, 2, 2, 2); // Matrices to store the results of multiplications. #ifdef _PARALLEL_ Matrix<Scalar> M1(mem_mngr.GetMem(start_index, 1, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M2(mem_mngr.GetMem(start_index, 2, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M3(mem_mngr.GetMem(start_index, 3, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M4(mem_mngr.GetMem(start_index, 4, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M5(mem_mngr.GetMem(start_index, 5, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M6(mem_mngr.GetMem(start_index, 6, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M7(mem_mngr.GetMem(start_index, 7, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M8(mem_mngr.GetMem(start_index, 8, total_steps - steps_left, M), C11.m(), C11.m(), C11.n(), C.multiplier()); #else Matrix<Scalar> M1(C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M2(C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M3(C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M4(C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M5(C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M6(C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M7(C11.m(), C11.n(), C.multiplier()); Matrix<Scalar> M8(C11.m(), C11.n(), C.multiplier()); #endif #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) bool sequential1 = should_launch_task(8, total_steps, steps_left, start_index, 1, num_threads); bool sequential2 = should_launch_task(8, total_steps, steps_left, start_index, 2, num_threads); bool sequential3 = should_launch_task(8, total_steps, steps_left, start_index, 3, num_threads); bool sequential4 = should_launch_task(8, total_steps, steps_left, start_index, 4, num_threads); bool sequential5 = should_launch_task(8, total_steps, steps_left, start_index, 5, num_threads); bool sequential6 = should_launch_task(8, total_steps, steps_left, start_index, 6, num_threads); bool sequential7 = should_launch_task(8, total_steps, steps_left, start_index, 7, num_threads); bool sequential8 = should_launch_task(8, total_steps, steps_left, start_index, 8, num_threads); #else bool sequential1 = false; bool sequential2 = false; bool sequential3 = false; bool sequential4 = false; bool sequential5 = false; bool sequential6 = false; bool sequential7 = false; bool sequential8 = false; #endif // M1 = (1 * A11) * (1 * B11) #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) # pragma omp task if(sequential1) shared(mem_mngr, locker) untied { #endif M1.UpdateMultiplier(Scalar(1)); M1.UpdateMultiplier(Scalar(1)); FastMatmulRecursive(locker, mem_mngr, A11, B11, M1, total_steps, steps_left - 1, (start_index + 1 - 1) * 8, x, num_threads, Scalar(0.0)); #ifndef _PARALLEL_ #endif #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) locker.Decrement(); } if (should_task_wait(8, total_steps, steps_left, start_index, 1, num_threads)) { # pragma omp taskwait # if defined(_PARALLEL_) && (_PARALLEL_ == _HYBRID_PAR_) SwitchToDFS(locker, num_threads); # endif } #endif // M2 = (1 * A12) * (1 * B21) #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) # pragma omp task if(sequential2) shared(mem_mngr, locker) untied { #endif M2.UpdateMultiplier(Scalar(1)); M2.UpdateMultiplier(Scalar(1)); FastMatmulRecursive(locker, mem_mngr, A12, B21, M2, total_steps, steps_left - 1, (start_index + 2 - 1) * 8, x, num_threads, Scalar(0.0)); #ifndef _PARALLEL_ #endif #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) locker.Decrement(); } if (should_task_wait(8, total_steps, steps_left, start_index, 2, num_threads)) { # pragma omp taskwait # if defined(_PARALLEL_) && (_PARALLEL_ == _HYBRID_PAR_) SwitchToDFS(locker, num_threads); # endif } #endif // M3 = (1 * A11) * (1 * B12) #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) # pragma omp task if(sequential3) shared(mem_mngr, locker) untied { #endif M3.UpdateMultiplier(Scalar(1)); M3.UpdateMultiplier(Scalar(1)); FastMatmulRecursive(locker, mem_mngr, A11, B12, M3, total_steps, steps_left - 1, (start_index + 3 - 1) * 8, x, num_threads, Scalar(0.0)); #ifndef _PARALLEL_ #endif #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) locker.Decrement(); } if (should_task_wait(8, total_steps, steps_left, start_index, 3, num_threads)) { # pragma omp taskwait # if defined(_PARALLEL_) && (_PARALLEL_ == _HYBRID_PAR_) SwitchToDFS(locker, num_threads); # endif } #endif // M4 = (1 * A12) * (1 * B22) #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) # pragma omp task if(sequential4) shared(mem_mngr, locker) untied { #endif M4.UpdateMultiplier(Scalar(1)); M4.UpdateMultiplier(Scalar(1)); FastMatmulRecursive(locker, mem_mngr, A12, B22, M4, total_steps, steps_left - 1, (start_index + 4 - 1) * 8, x, num_threads, Scalar(0.0)); #ifndef _PARALLEL_ #endif #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) locker.Decrement(); } if (should_task_wait(8, total_steps, steps_left, start_index, 4, num_threads)) { # pragma omp taskwait # if defined(_PARALLEL_) && (_PARALLEL_ == _HYBRID_PAR_) SwitchToDFS(locker, num_threads); # endif } #endif // M5 = (1 * A21) * (1 * B11) #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) # pragma omp task if(sequential5) shared(mem_mngr, locker) untied { #endif M5.UpdateMultiplier(Scalar(1)); M5.UpdateMultiplier(Scalar(1)); FastMatmulRecursive(locker, mem_mngr, A21, B11, M5, total_steps, steps_left - 1, (start_index + 5 - 1) * 8, x, num_threads, Scalar(0.0)); #ifndef _PARALLEL_ #endif #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) locker.Decrement(); } if (should_task_wait(8, total_steps, steps_left, start_index, 5, num_threads)) { # pragma omp taskwait # if defined(_PARALLEL_) && (_PARALLEL_ == _HYBRID_PAR_) SwitchToDFS(locker, num_threads); # endif } #endif // M6 = (1 * A22) * (1 * B21) #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) # pragma omp task if(sequential6) shared(mem_mngr, locker) untied { #endif M6.UpdateMultiplier(Scalar(1)); M6.UpdateMultiplier(Scalar(1)); FastMatmulRecursive(locker, mem_mngr, A22, B21, M6, total_steps, steps_left - 1, (start_index + 6 - 1) * 8, x, num_threads, Scalar(0.0)); #ifndef _PARALLEL_ #endif #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) locker.Decrement(); } if (should_task_wait(8, total_steps, steps_left, start_index, 6, num_threads)) { # pragma omp taskwait # if defined(_PARALLEL_) && (_PARALLEL_ == _HYBRID_PAR_) SwitchToDFS(locker, num_threads); # endif } #endif // M7 = (1 * A21) * (1 * B12) #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) # pragma omp task if(sequential7) shared(mem_mngr, locker) untied { #endif M7.UpdateMultiplier(Scalar(1)); M7.UpdateMultiplier(Scalar(1)); FastMatmulRecursive(locker, mem_mngr, A21, B12, M7, total_steps, steps_left - 1, (start_index + 7 - 1) * 8, x, num_threads, Scalar(0.0)); #ifndef _PARALLEL_ #endif #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) locker.Decrement(); } if (should_task_wait(8, total_steps, steps_left, start_index, 7, num_threads)) { # pragma omp taskwait # if defined(_PARALLEL_) && (_PARALLEL_ == _HYBRID_PAR_) SwitchToDFS(locker, num_threads); # endif } #endif // M8 = (1 * A22) * (1 * B22) #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) # pragma omp task if(sequential8) shared(mem_mngr, locker) untied { #endif M8.UpdateMultiplier(Scalar(1)); M8.UpdateMultiplier(Scalar(1)); FastMatmulRecursive(locker, mem_mngr, A22, B22, M8, total_steps, steps_left - 1, (start_index + 8 - 1) * 8, x, num_threads, Scalar(0.0)); #ifndef _PARALLEL_ #endif #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) locker.Decrement(); } if (should_task_wait(8, total_steps, steps_left, start_index, 8, num_threads)) { # pragma omp taskwait } #endif M_Add1(M1, M2, C11, x, false, beta); M_Add2(M3, M4, C12, x, false, beta); M_Add3(M5, M6, C21, x, false, beta); M_Add4(M7, M8, C22, x, false, beta); // Handle edge cases with dynamic peeling #if defined(_PARALLEL_) && (_PARALLEL_ == _BFS_PAR_ || _PARALLEL_ == _HYBRID_PAR_) if (total_steps == steps_left) { mkl_set_num_threads_local(num_threads); mkl_set_dynamic(0); } #endif DynamicPeeling(A, B, C, 2, 2, 2, beta); }
int multiple_detector_fit() { std::cout << "Beginning : ... " << std::endl; Int_t npoints = 1000; Double_t emin = 0.2; Double_t emax = 3.0; bool use100m = true; bool use470m = true; bool use600m = true; std::vector<int> baselines; std::vector<double> scales; std::vector<std::string> names; std::vector<double> volume; if (use100m) baselines.push_back(100); if (use470m) baselines.push_back(470); if (use600m) baselines.push_back(600); double NULLVec[2][20]; double OscVec[2][1001][7][20]; for(int i = 0; i < 20; i++){ NULLVec[0][i] = 0; NULLVec[1][i] = 0; } for(int u = 0; u < 1000; u++){ for(int s = 0; s < 7; s++){ for(int i = 0; i < 20; i++){ OscVec[0][u][s][i] = 0; OscVec[1][u][s][i] = 0; } } } int nbinsE = 0; if (use100m){ std::string temp_name = /*"../MatrixFiles/combined_ntuple_100m_nu_processed_numu.root";*/"../MatrixFiles/combined_ntuple_100m_nu_processed_CoreyBins_numu.root"; TFile temp_file(temp_name.c_str()); TH1D *NULL_100; NULL_100 = (TH1D*)(temp_file.Get("NumuCC")); nbinsE = NULL_100->GetNbinsX(); std::cout << nbinsE << std::endl; for(int i = 1; i <= nbinsE; i++){ NULLVec[0][i-1] = (NULL_100->GetBinContent(i)); } for(int u = 0; u < npoints; u++){ for(int s = 0; s < 7; s++){ TH1D *OSC_100; TString upoint = Form("%d",u); TString name = "Universe_"; TString name2 = "_MultiSim_"; TString mul = Form("%d",s); name += upoint; name += name2; name += mul; OSC_100 = (TH1D*)(temp_file.Get(name)); for(int i = 1; i <= nbinsE; i++){ OscVec[0][u][s][i-1] = (OSC_100->GetBinContent(i)); // if(OscVec[0][u][s][i-1] != OscVec[0][u][s][i-1]) std::cout << "erm" <<std::endl; } delete OSC_100; } } delete NULL_100; temp_file.Close(); } if (use470m){ std::string temp_name = /*"../MatrixFiles/combined_ntuple_600m_onaxis_nu_processed_numu.root";*/"../MatrixFiles/combined_ntuple_600m_onaxis_nu_processed_CoreyBins_numu.root"; TFile temp_file(temp_name.c_str()); TH1D *NULL_470; NULL_470 = (TH1D*)(temp_file.Get("NumuCC")); nbinsE = NULL_470->GetNbinsX(); std::cout << nbinsE<< std::endl; for(int i = 1; i <= nbinsE; i++){ NULLVec[1][i-1] = (NULL_470->GetBinContent(i)); } for(int u = 0; u < npoints; u++){ for(int s = 0; s < 7; s++){ TH1D *OSC_470; TString upoint = Form("%d",u);//std::to_string(u); TString name = "Universe_"; TString name2 = "_MultiSim_"; TString mul = Form("%d",s);// = std::to_string(s); name += upoint; name += name2; name += mul; OSC_470 = (TH1D*)(temp_file.Get(name)); for(int i = 1; i <= nbinsE; i++){ OscVec[1][u][s][i-1] = (OSC_470->GetBinContent(i)); if(OscVec[1][u][s][i-1] != OscVec[1][u][s][i-1]) OscVec[1][u][s][i-1] = NULLVec[1][i-1];//std::cout << "erm, u :" << u << " s : " << s << " E : " << i <<std::endl; } delete OSC_470; } } delete NULL_470; temp_file.Close(); } int nL = 2; int mbins = (nbinsE*nL); TMatrix M6 (mbins,mbins); TMatrix M5 (mbins,mbins); TMatrix M4 (mbins,mbins); TMatrix M3 (mbins,mbins); TMatrix M2 (mbins,mbins); TMatrix M1 (mbins,mbins); TMatrix M0 (mbins,mbins); TMatrix C6 (mbins,mbins); TMatrix C5 (mbins,mbins); TMatrix C4 (mbins,mbins); TMatrix C3 (mbins,mbins); TMatrix C2 (mbins,mbins); TMatrix C1 (mbins,mbins); TMatrix C0 (mbins,mbins); int N = 0; TH1D *Fig6 = new TH1D("Fig6",";;",mbins,0,mbins); TH1D *Fig5 = new TH1D("Fig5",";;",mbins,0,mbins); TH1D *Fig4 = new TH1D("Fig4",";;",mbins,0,mbins); TH1D *Fig3 = new TH1D("Fig3",";;",mbins,0,mbins); TH1D *Fig2 = new TH1D("Fig2",";;",mbins,0,mbins); TH1D *Fig1 = new TH1D("Fig1",";;",mbins,0,mbins); TH1D *Fig0 = new TH1D("Fig0",";;",mbins,0,mbins); int Erri = 0, Errj = 0; std::cout << "Filling Error Matrix..." << std::endl; for(int Lrow = 0; Lrow < 2; Lrow++){ for(int Erow = 0; Erow < nbinsE; Erow++){ Errj = 0; for(int Lcol = 0; Lcol < 2; Lcol++){ for(int Ecol = 0; Ecol < nbinsE; Ecol++){ M6 (Erri,Errj) = 0; M5 (Erri,Errj) = 0; M4 (Erri,Errj) = 0; M3 (Erri,Errj) = 0; M2 (Erri,Errj) = 0; M1 (Erri,Errj) = 0; M0 (Erri,Errj) = 0; N = 0; for(int u = 0; u < npoints; u++){ M6 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][6][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][6][Ecol]); M5 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][5][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][5][Ecol]); M4 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][4][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][4][Ecol]); M3 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][3][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][3][Ecol]); M2 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][2][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][2][Ecol]); M1 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][1][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][1][Ecol]); M0 (Erri,Errj) += (NULLVec[Lrow][Erow]-OscVec[Lrow][u][0][Erow])*(NULLVec[Lcol][Ecol]-OscVec[Lcol][u][0][Ecol]); N++; } M6 (Erri,Errj) /= N; M5 (Erri,Errj) /= N; M4 (Erri,Errj) /= N; M3 (Erri,Errj) /= N; M2 (Erri,Errj) /= N; M1 (Erri,Errj) /= N; M0 (Erri,Errj) /= N; M6 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol]; M5 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol]; M4 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol]; M3 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol]; M2 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol]; M1 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol]; M0 (Erri,Errj) /= NULLVec[Lrow][Erow]*NULLVec[Lcol][Ecol]; if(Erri == Errj) Fig6->SetBinContent(Erri+1, sqrt(M6 (Erri,Errj))); if(Erri == Errj) Fig5->SetBinContent(Erri+1, sqrt(M5 (Erri,Errj))); if(Erri == Errj) Fig4->SetBinContent(Erri+1, sqrt(M4 (Erri,Errj))); if(Erri == Errj) Fig3->SetBinContent(Erri+1, sqrt(M3 (Erri,Errj))); if(Erri == Errj) Fig2->SetBinContent(Erri+1, sqrt(M2 (Erri,Errj))); if(Erri == Errj) Fig1->SetBinContent(Erri+1, sqrt(M1 (Erri,Errj))); if(Erri == Errj) Fig0->SetBinContent(Erri+1, sqrt(M0 (Erri,Errj))); std::cout << M6 (Erri,Errj) << "\t"; Errj++; }} Erri++; }} for(int i = 0; i < Erri; i++){ for(int j = 0; j < Errj; j++){ C6 (i,j) = M6(i,j) / sqrt(M6 (i,i) * M6 (j,j)); C5 (i,j) = M5(i,j) / sqrt(M5 (i,i) * M5 (j,j)); C4 (i,j) = M4(i,j) / sqrt(M4 (i,i) * M4 (j,j)); C3 (i,j) = M3(i,j) / sqrt(M3 (i,i) * M3 (j,j)); C2 (i,j) = M2(i,j) / sqrt(M2 (i,i) * M2 (j,j)); C1 (i,j) = M1(i,j) / sqrt(M1 (i,i) * M1 (j,j)); C0 (i,j) = M0(i,j) / sqrt(M0 (i,i) * M0 (j,j)); } } std::cout << "...Error Matrix Filled" << std::endl; TCanvas* c6 = new TCanvas("c6","",700,700); c6->SetLeftMargin(.1); c6->SetBottomMargin(.1); c6->SetTopMargin(.075); c6->SetRightMargin(.15); c6->cd(); M6.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); // TMatrixFBase->GetZaxis()->SetRangeUser(-0.05,0.4); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); // TMatrixFBase->GetZaxis()->SetTitle("Fractional Error Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kBlue); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *ND = new TLatex(.15,.01,"LAr1-ND (100m) "); ND->SetNDC(); ND->SetTextFont(62); ND->SetTextSize(0.04); ND->Draw(); TLatex *MD = new TLatex(.5,.01,"T600 (600m, on axis)"); MD->SetNDC(); MD->SetTextFont(62); MD->SetTextSize(0.04); MD->Draw(); TLatex *ND45 = new TLatex(.05,.15,"LAr1-ND (100m) "); ND45->SetNDC(); ND45->SetTextAngle(90); ND45->SetTextFont(62); ND45->SetTextSize(0.04); ND45->Draw(); TLatex *MD45 = new TLatex(.05,.54,"T600 (600m, on axis)"); MD45->SetNDC(); MD45->SetTextAngle(90); MD45->SetTextFont(62); MD45->SetTextSize(0.04); MD45->Draw(); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} Flux Fractional Error Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); // c6->Print("total_matrix.pdf"); TCanvas* c61 = new TCanvas("c61","",700,700); c61->SetLeftMargin(.1); c61->SetBottomMargin(.1); c61->SetTopMargin(.075); c61->SetRightMargin(.15); c61->cd(); C6.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kYellow); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} Flux Correlation Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); // c61->Print("total_correlation_matrix.pdf"); TCanvas* c5 = new TCanvas("c5","",700,700); c5->SetLeftMargin(.1); c5->SetBottomMargin(.1); c5->SetTopMargin(.075); c5->SetRightMargin(.15); c5->cd(); M5.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); // TMatrixFBase->GetZaxis()->SetTitle("K^{+} Covariance Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kBlue); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{+} Fractional Error Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c5->Print("mult5_matrix.pdf"); TCanvas* c51 = new TCanvas("c51","",700,700); c51->SetLeftMargin(.1); c51->SetBottomMargin(.1); c51->SetTopMargin(.075); c51->SetRightMargin(.15); c51->cd(); C5.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); // TMatrixFBase->GetZaxis()->SetTitle("K#lower[-0.15]{+} Correlation Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kYellow); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{+} Correlation Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c51->Print("mult5_correlation_matrix.pdf"); TCanvas* c4 = new TCanvas("c4","",700,700); c4->SetLeftMargin(.1); c4->SetBottomMargin(.1); c4->SetTopMargin(.075); c4->SetRightMargin(.15); c4->cd(); M4.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); //TMatrixFBase->GetZaxis()->SetTitle("K#lower[-0.15]{-} Covariance Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kBlue); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{-} Fractional Error Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c4->Print("mult4_matrix.pdf"); TCanvas* c41 = new TCanvas("c41","",700,700); c41->SetLeftMargin(.1); c41->SetBottomMargin(.1); c41->SetTopMargin(.075); c41->SetRightMargin(.15); c41->cd(); C4.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); // TMatrixFBase->GetZaxis()->SetTitle("K#lower[-0.15]{-} Correlation Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kYellow); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{-} Correlation Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c41->Print("mult4_correlation_matrix.pdf"); TCanvas* c3 = new TCanvas("c3","",700,700); c3->SetLeftMargin(.1); c3->SetBottomMargin(.1); c3->SetTopMargin(.075); c3->SetRightMargin(.15); c3->cd(); M3.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); //TMatrixFBase->GetZaxis()->SetTitle("K#lower[-0.15]{0} Covariance Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kBlue); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{0} Fractional Error Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c3->Print("mult3_matrix.pdf"); TCanvas* c31 = new TCanvas("c31","",700,700); c31->SetLeftMargin(.1); c31->SetBottomMargin(.1); c31->SetTopMargin(.075); c31->SetRightMargin(.15); c31->cd(); C3.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); //TMatrixFBase->GetZaxis()->SetTitle("K#lower[-0.15]{0} Correlation Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kYellow); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} K#lower[-0.15]{0} Correlation Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c31->Print("mult3_correlation_matrix.pdf"); TCanvas* c2 = new TCanvas("c2","",700,700); c2->SetLeftMargin(.1); c2->SetBottomMargin(.1); c2->SetTopMargin(.075); c2->SetRightMargin(.15); c2->cd(); M2.Draw("COLZ"); gStyle->SetPalette(56,0); //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045); TMatrixFBase->SetContour(999); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); //TMatrixFBase->GetZaxis()->SetTitle("#pi#lower[-0.15]{+} Covariance Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kBlue); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} #pi#lower[-0.15]{+} Fractional Error Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c2->Print("mult2_matrix.pdf"); TCanvas* c21 = new TCanvas("c21","",700,700); c21->SetLeftMargin(.1); c21->SetBottomMargin(.1); c21->SetTopMargin(.075); c21->SetRightMargin(.15); c21->cd(); C2.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); //TMatrixFBase->GetZaxis()->SetTitle("#pi#lower[-0.15]{+} Correlation Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kYellow); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} #pi#lower[-0.15]{+} Correlation Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c21->Print("mult2_correlation_matrix.pdf"); TCanvas* c1 = new TCanvas("c1","",700,700); c1->SetLeftMargin(.1); c1->SetBottomMargin(.1); c1->SetTopMargin(.075); c1->SetRightMargin(.15); c1->cd(); M1.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); //TMatrixFBase->GetZaxis()->SetTitle("#pi#lower[-0.15]{-} Covariance Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kBlue); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} #pi#lower[-0.15]{-} Fractional Error Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c1->Print("mult1_matrix.pdf"); TCanvas* c11 = new TCanvas("c11","",700,700); c11->SetLeftMargin(.1); c11->SetBottomMargin(.1); c11->SetTopMargin(.075); c11->SetRightMargin(.15); c11->cd(); C1.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); // TMatrixFBase->GetZaxis()->SetTitle("#pi#lower[-0.15]{-} Correlation Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kYellow); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} #pi#lower[-0.15]{-} Correlation Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c11->Print("mult1_correlation_matrix.pdf"); TCanvas* c0 = new TCanvas("c0","",700,700); c0->SetLeftMargin(.1); c0->SetBottomMargin(.1); c0->SetTopMargin(.075); c0->SetRightMargin(.15); c0->cd(); M0.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-0.005,0.045); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); // TMatrixFBase->GetZaxis()->SetTitle("Beam UniSim Covariance Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kBlue); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} Beam Fractional Error Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c0->Print("mult0_matrix.pdf"); TCanvas* c01 = new TCanvas("c01","",700,700); c01->SetLeftMargin(.1); c01->SetBottomMargin(.1); c01->SetTopMargin(.075); c01->SetRightMargin(.15); c01->cd(); C0.Draw("COLZ"); gStyle->SetPalette(56,0); TMatrixFBase->SetContour(999); //TMatrixFBase->GetZaxis()->SetRangeUser(-1,1); TMatrixFBase->GetZaxis()->SetTitleFont(62); TMatrixFBase->GetZaxis()->SetLabelFont(62); TMatrixFBase->GetZaxis()->SetTitleSize(0.045); // TMatrixFBase->GetZaxis()->SetTitle("Beam UniSim Correlation Matrix"); TMatrixFBase->GetZaxis()->SetTitleOffset(1.5); TMatrixFBase->GetXaxis()->SetTitle(""); TMatrixFBase->GetXaxis()->SetLabelSize(0); TMatrixFBase->GetXaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetTitle(""); TMatrixFBase->GetYaxis()->SetTitleOffset(1.5); TMatrixFBase->GetYaxis()->SetLabelSize(0); TMatrixFBase->SetStats(0); TLine *split = new TLine(); split->SetLineStyle(2); split->SetLineWidth(5); split->SetLineColor(kYellow); split->DrawLineNDC(.1,.51,.849,.51); split->DrawLineNDC(.475,.101,.475,.930); add_plot_label("| 0.2 #minus 3.0 GeV | 0.2 #minus 3.0 GeV | ", 0.48,0.08,0.03); TLatex *Total = new TLatex(.2,.96,"#nu#lower[0.3]{#mu} Beam Correlation Matrix"); Total->SetNDC(); Total->SetTextFont(62); Total->SetTextSize(0.045); Total->Draw(); ND->Draw(); MD->Draw(); ND45->Draw(); MD45->Draw(); // c01->Print("mult0_correlation_matrix.pdf"); TCanvas* c86 = new TCanvas("c86","",800,400); c86->SetLeftMargin(.1); c86->SetBottomMargin(.1); c86->SetTopMargin(.05); c86->SetRightMargin(.05); c86->cd(); Fig6->GetYaxis()->SetTitle("Fractional Error"); Fig6->GetYaxis()->SetTitleFont(62); Fig6->GetXaxis()->SetTitleFont(62); Fig6->GetYaxis()->SetLabelFont(62); Fig6->GetXaxis()->SetLabelFont(62); Fig6->GetYaxis()->CenterTitle(); Fig6->GetYaxis()->SetTitleSize(0.06); Fig6->GetYaxis()->SetTitleOffset(0.8); Fig6->GetXaxis()->SetLabelSize(0.06); Fig6->GetYaxis()->SetLabelSize(0.06); Fig6->GetXaxis()->SetTitleOffset(1.5); Fig6->SetStats(0); Fig6->SetMinimum(-0.01); Fig6->SetMaximum(0.21); Fig6->SetMarkerStyle(8); Fig6->GetYaxis()->SetNdivisions(509); Fig6->GetXaxis()->SetNdivisions(509); Fig6->Draw("P"); split->SetLineColor(1); split->SetLineWidth(2); split->DrawLine(19,-0.01,19,0.21); TLatex *ND = new TLatex(.23,.85,"LAr1-ND (100m) "); ND->SetNDC(); ND->SetTextFont(62); ND->SetTextSize(0.05); ND->Draw(); TLatex *MD = new TLatex(.65,.85,"T600 (600m, on axis)"); MD->SetNDC(); MD->SetTextFont(62); MD->SetTextSize(0.05); MD->Draw(); // c86->Print("FractionalErrors_Total.pdf"); TCanvas* c85 = new TCanvas("c85","",800,400); c85->SetLeftMargin(.1); c85->SetBottomMargin(.1); c85->SetTopMargin(.05); c85->SetRightMargin(.05); c85->cd(); Fig5->GetYaxis()->SetTitle("K#lower[-0.2]{+} Fractional Error"); Fig5->GetYaxis()->SetTitleFont(62); Fig5->GetXaxis()->SetTitleFont(62); Fig5->GetYaxis()->SetLabelFont(62); Fig5->GetXaxis()->SetLabelFont(62); Fig5->GetYaxis()->CenterTitle(); Fig5->GetYaxis()->SetTitleSize(0.06); Fig5->GetYaxis()->SetTitleOffset(0.8); Fig5->GetXaxis()->SetLabelSize(0.06); Fig5->GetYaxis()->SetLabelSize(0.06); Fig5->GetXaxis()->SetTitleOffset(1.5); Fig5->SetStats(0); Fig5->SetMinimum(-0.01); Fig5->SetMaximum(0.21); Fig5->SetMarkerStyle(8); Fig5->GetYaxis()->SetNdivisions(509); Fig5->GetXaxis()->SetNdivisions(509); Fig5->Draw("P"); split->SetLineColor(1); split->SetLineWidth(2); split->DrawLine(19,-0.01,19,0.21); ND->Draw(); MD->Draw(); // c85->Print("FractionalErrors_Kplus.pdf"); TCanvas* c84 = new TCanvas("c84","",800,400); c84->SetLeftMargin(.1); c84->SetBottomMargin(.1); c84->SetTopMargin(.05); c84->SetRightMargin(.05); c84->cd(); Fig4->GetYaxis()->SetTitle("K#lower[-0.2]{-} Fractional Error"); Fig4->GetYaxis()->SetTitleFont(62); Fig4->GetXaxis()->SetTitleFont(62); Fig4->GetYaxis()->SetLabelFont(62); Fig4->GetXaxis()->SetLabelFont(62); Fig4->GetYaxis()->CenterTitle(); Fig4->GetYaxis()->SetTitleSize(0.06); Fig4->GetYaxis()->SetTitleOffset(0.8); Fig4->GetXaxis()->SetLabelSize(0.06); Fig4->GetYaxis()->SetLabelSize(0.06); Fig4->GetXaxis()->SetTitleOffset(1.5); Fig4->SetStats(0); Fig4->SetMinimum(-0.01); Fig4->SetMaximum(0.21); Fig4->SetMarkerStyle(8); Fig4->GetYaxis()->SetNdivisions(509); Fig4->GetXaxis()->SetNdivisions(509); Fig4->Draw("P"); split->SetLineColor(1); split->SetLineWidth(2); split->DrawLine(19,-0.01,19,0.21); ND->Draw(); MD->Draw(); // c84->Print("FractionalErrors_Kmin.pdf"); TCanvas* c83 = new TCanvas("c83","",800,400); c83->SetLeftMargin(.1); c83->SetBottomMargin(.1); c83->SetTopMargin(.05); c83->SetRightMargin(.05); c83->cd(); Fig3->GetYaxis()->SetTitle("K#lower[-0.2]{0} Fractional Error"); Fig3->GetYaxis()->SetTitleFont(62); Fig3->GetXaxis()->SetTitleFont(62); Fig3->GetYaxis()->SetLabelFont(62); Fig3->GetXaxis()->SetLabelFont(62); Fig3->GetYaxis()->CenterTitle(); Fig3->GetYaxis()->SetTitleSize(0.06); Fig3->GetYaxis()->SetTitleOffset(0.8); Fig3->GetXaxis()->SetLabelSize(0.06); Fig3->GetYaxis()->SetLabelSize(0.06); Fig3->GetXaxis()->SetTitleOffset(1.5); Fig3->SetStats(0); Fig3->SetMinimum(-0.01); Fig3->SetMaximum(0.21); Fig3->SetMarkerStyle(8); Fig3->GetYaxis()->SetNdivisions(509); Fig3->GetXaxis()->SetNdivisions(509); Fig3->Draw("P"); split->SetLineColor(1); split->SetLineWidth(2); split->DrawLine(19,-0.01,19,0.21); ND->Draw(); MD->Draw(); // c83->Print("FractionalErrors_K0.pdf"); TCanvas* c82 = new TCanvas("c82","",800,400); c82->SetLeftMargin(.1); c82->SetBottomMargin(.1); c82->SetTopMargin(.05); c82->SetRightMargin(.05); c82->cd(); Fig2->GetYaxis()->SetTitle("#pi#lower[-0.2]{+} Fractional Error"); Fig2->GetYaxis()->SetTitleFont(62); Fig2->GetXaxis()->SetTitleFont(62); Fig2->GetYaxis()->SetLabelFont(62); Fig2->GetXaxis()->SetLabelFont(62); Fig2->GetYaxis()->CenterTitle(); Fig2->GetYaxis()->SetTitleSize(0.06); Fig2->GetYaxis()->SetTitleOffset(0.8); Fig2->GetXaxis()->SetLabelSize(0.06); Fig2->GetYaxis()->SetLabelSize(0.06); Fig2->GetXaxis()->SetTitleOffset(1.5); Fig2->SetStats(0); Fig2->SetMinimum(-0.01); Fig2->SetMaximum(0.21); Fig2->SetMarkerStyle(8); Fig2->GetYaxis()->SetNdivisions(509); Fig2->GetXaxis()->SetNdivisions(509); Fig2->Draw("P"); split->SetLineColor(1); split->SetLineWidth(2); split->DrawLine(19,-0.01,19,0.21); ND->Draw(); MD->Draw(); // c82->Print("FractionalErrors_piplus.pdf"); TCanvas* c81 = new TCanvas("c81","",800,400); c81->SetLeftMargin(.1); c81->SetBottomMargin(.1); c81->SetTopMargin(.05); c81->SetRightMargin(.05); c81->cd(); Fig1->GetYaxis()->SetTitle("#pi#lower[-0.2]{-} Fractional Error"); Fig1->GetYaxis()->SetTitleFont(62); Fig1->GetXaxis()->SetTitleFont(62); Fig1->GetYaxis()->SetLabelFont(62); Fig1->GetXaxis()->SetLabelFont(62); Fig1->GetYaxis()->CenterTitle(); Fig1->GetYaxis()->SetTitleSize(0.06); Fig1->GetYaxis()->SetTitleOffset(0.8); Fig1->GetXaxis()->SetLabelSize(0.06); Fig1->GetYaxis()->SetLabelSize(0.06); Fig1->GetXaxis()->SetTitleOffset(1.5); Fig1->SetStats(0); Fig1->SetMinimum(-0.01); Fig1->SetMaximum(0.21); Fig1->SetMarkerStyle(8); Fig1->GetYaxis()->SetNdivisions(509); Fig1->GetXaxis()->SetNdivisions(509); Fig1->Draw("P"); split->SetLineColor(1); split->SetLineWidth(2); split->DrawLine(19,-0.01,19,0.21); ND->Draw(); MD->Draw(); // c81->Print("FractionalErrors_pimin.pdf"); TCanvas* c80 = new TCanvas("c80","",800,400); c80->SetLeftMargin(.1); c80->SetBottomMargin(.1); c80->SetTopMargin(.05); c80->SetRightMargin(.05); c80->cd(); Fig0->GetYaxis()->SetTitle("Beam Fractional Error"); Fig0->GetYaxis()->SetTitleFont(62); Fig0->GetXaxis()->SetTitleFont(62); Fig0->GetYaxis()->SetLabelFont(62); Fig0->GetXaxis()->SetLabelFont(62); Fig0->GetYaxis()->CenterTitle(); Fig0->GetYaxis()->SetTitleSize(0.06); Fig0->GetYaxis()->SetTitleOffset(0.8); Fig0->GetXaxis()->SetLabelSize(0.06); Fig0->GetYaxis()->SetLabelSize(0.06); Fig0->GetXaxis()->SetTitleOffset(1.5); Fig0->SetStats(0); Fig0->SetMinimum(-0.01); Fig0->SetMaximum(0.21); Fig0->SetMarkerStyle(8); Fig0->GetYaxis()->SetNdivisions(509); Fig0->GetXaxis()->SetNdivisions(509); Fig0->Draw("P"); split->SetLineColor(1); split->SetLineWidth(2); split->DrawLine(19,-0.01,19,0.21); ND->Draw(); MD->Draw(); // c80->Print("FractionalErrors_beam.pdf"); cout<<"\nEnd of routine.\n"; return 0; }
void main() //main code { //printing titles for values displayed printf("\nRUNGE-KUTTA METHOD\nstep size R M Last Rho iterations\n"); double i; //power order for rho(c) double c = 10; //the parameter rho(c) int n; //the integer steps, n //declare arrays float x[N]; float y[N]; float z[N]; float x2[N]; float y2[N]; float z2[N]; //r,m,p as the radius, mass and density double r,m,p,r2,m2,p2; for(i=-5;i<2;i++) { h = pow(10,i); //how h is varied by i c = 10; //the parameter rho(c) //declare initial conditons for arrays x[0] = h; //first array is for r=h y[0] = (h*h*h/3)*c; //initial conditon for scaled mass (m) z[0] = c*(1-((h*h*c)/(6*gamma(c)))); //initial conditon for rho //for loop for n=0,1,...,when z[n]>1 for(n=0;z[n]>1;n++) { //declared how x(n+1) relates to x(n), y(n+1) relates to y(n), z(n+1) relates to z(n) x[n+1] = x[n]+h; y[n+1] = y[n]+(h/6)*(M(x[n],y[n],z[n])+2*M2(x[n],y[n],z[n])+2*M3(x[n],y[n],z[n])+M4(x[n],y[n],z[n])); z[n+1] = z[n]+(h/6)*(rho(x[n],y[n],z[n])+2*rho2(x[n],y[n],z[n])+2*rho3(x[n],y[n],z[n])+rho4(x[n],y[n],z[n])); //r,m,p will be declared for printf statement r = x[n]; m = y[n]; p = z[n]; } //printed values for x and y respectively printf("%.2e %.2e %.2e %.2e %i\n",h,r,m,p,n); } //printing titles for values displayed printf("\nEULER METHOD\nstep size R M Last Rho iterations\n"); for(i=-5;i<2;i++) { h = pow(10,i); //how h is varied by i c = 10; //the parameter rho(c) //declare initial conditons for arrays x2[0] = h; //first array is for r=h y2[0] = (h*h*h/3)*c; //initial conditon for scaled mass (m) z2[0] = fabs(c*(1-((h*h*c)/(6*gamma(c))))); //initial conditon for rho //for loop for n=0,1,..., when z2[n]>1 for(n=0;z2[n]>1;n++) { //declared how x2(n+1) relates to x2(n), y2(n+1) relates to y2(n), z2(n+1) relates to z2(n) x2[n+1] = x2[n]+h; y2[n+1] = y2[n]+h*(M(x2[n],y2[n],z2[n])); z2[n+1] = z2[n]+h*(rho(x2[n],y2[n],z2[n])); //r2,m2,p2 will be declared in pg-plot r2 = x2[n]; m2 = y2[n]; p2 = z2[n]; } //printed values for x and y respectively printf("%.2e %.2e %.2e %.2e %i\n",h,r2,m2,p2,n); } }
void InitSLState( const dTensorBC4& q, const dTensorBC4& aux, SL_state& sl_state ) { void ComputeElecField(double t, const dTensor2& node1d, const dTensorBC4& qvals, dTensorBC3& Evals); void ConvertQ2dToQ1d(const int &mopt, int istart, int iend, const dTensorBC4& qin, dTensorBC3& qout); void IntegrateQ1dMoment1(const dTensorBC4& q2d, dTensorBC3& q1d); const int space_order = dogParams.get_space_order(); const int mx = q.getsize(1); const int my = q.getsize(2); const int meqn = q.getsize(3); const int maux = aux.getsize(2); const int kmax = q.getsize(4); const int mbc = q.getmbc(); const int mpoints = space_order*space_order; const int kmax1d = space_order; const double tn = sl_state.tn; //////////////////////// Compute Electric Field E(t) //////////////////// // save 1d grid points ( this is used for poisson solve ) dTensorBC3 Enow(mx, meqn, kmax1d, mbc, 1); ComputeElecField( tn, *sl_state.node1d, *sl_state.qnew, Enow); //////////// Necessary terms for Et = -M1 + g(x,t) ///////////////////// dTensorBC3 M1(mx, meqn, kmax1d,mbc,1); IntegrateQ1dMoment1(q, M1); // first moment //////////// Necessary terms for Ett = 2*KE_x - rho*E + g_t - psi_u /////// dTensorBC3 KE(mx, meqn, kmax1d,mbc,1); void IntegrateQ1dMoment2(const dTensorBC4& q2d, dTensorBC3& q1d); IntegrateQ1dMoment2(q, KE); // 1/2 * \int v^2 * f dv // SetBndValues1D( KE ); SetBndValues1D( Enow ); SetBndValues1D( M1 ); // do something to compute KE_x ... // dTensorBC3 gradKE(mx,2,kmax1d,mbc,1); FiniteDiff( 1, 2, KE, gradKE ); // compute KE_x and KE_xx // dTensorBC3 rho(mx,meqn,kmax1d,mbc,1); dTensorBC3 prod(mx,meqn,kmax1d,mbc,1); void IntegrateQ1d(const int mopt, const dTensorBC4& q2d, dTensorBC3& q1d); void MultiplyFunctions(const dTensorBC3& Q1, const dTensorBC3& Q2, dTensorBC3& qnew); IntegrateQ1d( 1, q, rho ); MultiplyFunctions( rho, Enow, prod ); /////////////////////// Save E, Et, Ett, ////////////////////////////////// for( int i = 1; i <= mx; i++ ) for( int k = 1; k <= kmax1d; k ++ ) { double E = Enow.get ( i, 1, k ); double Et = -M1.get ( i, 1, k ); // + g(x,t) double Ett = -prod.get(i,1,k) + 2.0*gradKE.get(i,1,k); // + others // sl_state.aux1d->set(i,2,1, k, E ); sl_state.aux1d->set(i,2,2, k, Et ); sl_state.aux1d->set(i,2,3, k, Ett ); } /////////////////////////////////////////////////////////////////////////// // terms used for 4th order stuff ... // // Ettt = -M3_xx + (2*E_x+rho)*M1 + 3*E*(M1)_x dTensorBC3 tmp0(mx,2*meqn,kmax1d,mbc,1); dTensorBC3 tmp1(mx,meqn,kmax1d,mbc,1); // compute the third moment and its 2nd derivative dTensorBC3 M3 (mx,meqn,kmax1d,mbc,1); dTensorBC3 M3_x (mx,2*meqn,kmax1d,mbc,1); void IntegrateQ1dMoment3(const dTensorBC4& q2d, dTensorBC3& q1d); IntegrateQ1dMoment3(q, M3 ); SetBndValues1D( M3 ); FiniteDiff( 1, 2, M3, M3_x ); // Compute 2*Ex+rho // FiniteDiff(1, 2*meqn, Enow, tmp0); for( int i=1; i <= mx; i++ ) for( int k=1; k <= kmax1d; k++ ) { tmp1.set(i,1,k, 2.0*tmp0.get(i,1,k) + rho.get(i,1,k) ); } // compute (2Ex+rho) * M1 dTensorBC3 prod1(mx,meqn,kmax1d,mbc,1); MultiplyFunctions( tmp1, M1, prod1 ); // compute M1_x and M1_xx dTensorBC3 M1_x (mx,2*meqn,kmax1d,mbc,1); FiniteDiff( 1, 2, M1, M1_x ); //compute 3*M1_x and E * (3*M1)_x dTensorBC3 prod2(mx,meqn,kmax1d,mbc,1); for( int i=1; i <= mx; i++ ) for( int k=1; k <= kmax1d; k++ ) { tmp1.set(i, 1, k, 3.0*M1_x.get(i, 1, k) ); } MultiplyFunctions( Enow, tmp1, prod2 ); /////////////////////// Save Ettt ///////////////////////////////////////// for( int i = 1; i <= mx; i++ ) for( int k = 1; k <= kmax1d; k ++ ) { double Ettt = -M3_x.get(i,2,k) + prod1.get(i,1,k) + prod2.get(i,1,k); sl_state.aux1d->set(i,2,4, k, Ettt ); } /////////////////////////////////////////////////////////////////////////// if ( dogParams.get_source_term()>0 ) { double* t_ptr = new double; *t_ptr = tn; // 2D Electric field, and 1D Electric Field dTensorBC4* ExactE; ExactE = new dTensorBC4(mx,1,4,kmax,mbc); dTensorBC3* ExactE1d; ExactE1d = new dTensorBC3(mx,4,kmax1d,mbc,1); // Extra Source terms needed for the electric field dTensorBC4* ExtraE; ExtraE = new dTensorBC4(mx,1,4,kmax,mbc); dTensorBC3* ExtraE1d; ExtraE1d = new dTensorBC3(mx,4,kmax1d,mbc,1); // Exact, electric field: (TODO - REMOVE THIS!) // void ElectricField(const dTensor2& xpts, dTensor2& e, void* data); // L2Project_extra(1-mbc, mx+mbc, 1, 1, space_order, -1, ExactE, // &ElectricField, (void*)t_ptr ); // ConvertQ2dToQ1d(1, 1, mx, *ExactE, *ExactE1d); // Extra Source terms: void ExtraSourceWrap(const dTensor2& xpts, const dTensor2& NOT_USED_1, const dTensor2& NOT_USED_2, dTensor2& e, void* data); L2Project_extra(1, mx, 1, 1, 20, space_order, space_order, space_order, &q, &aux, ExtraE, &ExtraSourceWrap, (void*)t_ptr ); ConvertQ2dToQ1d(1, 1, mx, *ExtraE, *ExtraE1d); for( int i=1; i <= mx; i++ ) for( int k=1; k <= kmax1d; k++ ) { // electric fields w/o source term parts added in // double Et = sl_state.aux1d->get(i,2,2,k); double Ett = sl_state.aux1d->get(i,2,3,k); double Ettt = sl_state.aux1d->get(i,2,4,k); // add in missing terms from previously set values // sl_state.aux1d->set(i,2,2, k, Et + ExtraE1d->get(i,2,k) ); sl_state.aux1d->set(i,2,3, k, Ett + ExtraE1d->get(i,3,k) ); sl_state.aux1d->set(i,2,4, k, Ettt + ExtraE1d->get(i,4,k) ); // sl_state.aux1d->set(i,2,1, k, 0. ); // sl_state.aux1d->set(i,2,2, k, 0. ); // sl_state.aux1d->set(i,2,3, k, 0. ); // sl_state.aux1d->set(i,2,4, k, 0. ); // ADD IN EXACT ELECTRIC FIELD HERE: // sl_state.aux1d->set(i,2,1, k, ExactE1d->get(i,1,k) ); // sl_state.aux1d->set(i,2,2, k, ExactE1d->get(i,2,k) ); // sl_state.aux1d->set(i,2,3, k, ExactE1d->get(i,3,k) ); // sl_state.aux1d->set(i,2,4, k, ExactE1d->get(i,4,k) ); } delete ExactE; delete ExactE1d; delete t_ptr; delete ExtraE; delete ExtraE1d; } }
Func ColorMgather(Func stBasis, float angle, uint8_t * orders, Expr filterthreshold, Expr divisionthreshold, Expr divisionthreshold2) { uint8_t x_order = orders[0]; uint8_t y_order = orders[1]; uint8_t t_order = orders[2]; uint8_t c_order = orders[3]; Func X("X"),Y("Y"),T("T"),Xrg("Xrg"),Yrg("Yrg"),Trg("Trg"); uint8_t max_order = x_order; // std::vector<Expr>Xk_expr (max_order,cast<float>(0.0f)); // std::vector<Expr>Yk_expr (max_order,cast<float>(0.0f)); // std::vector<Expr>Tk_expr (max_order,cast<float>(0.0f)); uint8_t Xk_uI[max_order]; uint8_t Yk_uI[max_order]; uint8_t Tk_uI[max_order]; Func Xk[max_order]; Func Yk[max_order]; Func Tk[max_order]; // Expr Xk[max_order],Yk[max_order],Tk[max_order]; for (int iO=0; iO < x_order; iO++) { Xk[iO](x,y,t) = Expr(0.0f); Yk[iO](x,y,t) = Expr(0.0f); Tk[iO](x,y,t) = Expr(0.0f); Xk_uI[iO] = 0; Yk_uI[iO] = 0; Tk_uI[iO] = 0; } int k = 0; for (int iXo = 0; iXo < x_order; iXo++) // x_order for (int iYo = 0; iYo < y_order; iYo++) // y_oder for (int iTo = 0; iTo < t_order; iTo++) // t_order for (int iCo = 0; iCo < c_order; iCo ++ ) // c_order: index of color channel { if ((iYo+iTo+iCo == 0 || iYo+iTo+iCo == 1) && ((iXo+iYo+iTo+iCo+1) < (x_order + 1))) { X = ColorMgetfilter(stBasis, angle, iXo+1, iYo, iTo, iCo); Y = ColorMgetfilter(stBasis, angle, iXo, iYo+1, iTo, iCo); T = ColorMgetfilter(stBasis, angle, iXo, iYo, iTo+1, iCo); Xrg = ColorMgetfilter(stBasis, angle, iXo+1, iYo, iTo, iCo+1); Yrg = ColorMgetfilter(stBasis, angle, iXo, iYo+1, iTo, iCo+1); Trg = ColorMgetfilter(stBasis, angle, iXo, iYo, iTo+1, iCo+1); k = iXo + iYo + iTo + iCo; Xk[k](x,y,t) += X(x,y,t) + Xrg(x,y,t); Yk[k](x,y,t) += Y(x,y,t) + Yrg(x,y,t); Tk[k](x,y,t) += T(x,y,t) + Trg(x,y,t); Xk[k].update(Xk_uI[k]); Xk_uI[k]++; Yk[k].update(Yk_uI[k]); Yk_uI[k]++; Tk[k].update(Tk_uI[k]); Tk_uI[k]++; } } // Scheduling for (int iO = 0; iO <= k; iO++) { Xk[iO].compute_root(); Yk[iO].compute_root(); Tk[iO].compute_root(); } std::vector<Expr> st_expr(6,cast<float>(0.0f)); for (int iK=0; iK <= k; iK++) { st_expr[0] += Xk[iK](x,y,t)*Tk[iK](x,y,t); st_expr[1] += Tk[iK](x,y,t)*Tk[iK](x,y,t); st_expr[2] += Xk[iK](x,y,t)*Xk[iK](x,y,t); st_expr[3] += Yk[iK](x,y,t)*Tk[iK](x,y,t); st_expr[4] += Yk[iK](x,y,t)*Yk[iK](x,y,t); st_expr[5] += Xk[iK](x,y,t)*Yk[iK](x,y,t); } Func st("st"); st(x,y,t) = Tuple(st_expr); st.compute_root(); Expr x_clamped = clamp(x,0,width-1); Expr y_clamped = clamp(y,0,height-1); Func st_clamped("st_clamped"); st_clamped(x,y,t) = st(x_clamped,y_clamped,t); // float win = 7.0; // Image<float> meanfilter(7,7,"meanfilter_data"); // meanfilter(x,y) = Expr(1.0f/(win*win)); // RDom rMF(meanfilter); uint8_t win = 7; RDom rMF(0,win,0,win); Func st_filtered[6]; for (uint8_t iPc=0; iPc<6; iPc++) { // iPc: index of product component // Apply average filter st_filtered[iPc](x,y,t) = sum(rMF,st_clamped(x + rMF.x,y + rMF.y,t)[iPc]/Expr(float(win*win)),"mean_filter"); st_filtered[iPc].compute_root(); } // Tuple st_tuple = Tuple(st_expr); // 4 debug // Func tmpOut("tmpOut"); tmpOut(x,y,t) = Tuple(st_filtered[0](x,y,t),st_filtered[1](x,y,t),st_filtered[2](x,y,t),st_filtered[3](x,y,t),st_filtered[4](x,y,t),st_filtered[5](x,y,t)); // return tmpOut; Tuple pbx = Tuple(st_filtered[2](x,y,t),st_filtered[5](x,y,t),st_filtered[0](x,y,t)); Tuple pby = Tuple(st_filtered[5](x,y,t),st_filtered[4](x,y,t),st_filtered[3](x,y,t)); Tuple pbt = Tuple(st_filtered[0](x,y,t),st_filtered[3](x,y,t),st_filtered[1](x,y,t)); Func pbxy("pbxy"); pbxy = cross(pby,pbx); pbxy.compute_root(); Func pbxt("pbxt"); pbxt = cross(pbx,pbt); pbxt.compute_root(); Func pbyt("pbyt"); pbyt = cross(pby,pbt); pbyt.compute_root(); Func pbxyd("pbxyd"); pbxyd = dot(pby,pbx); pbxyd.compute_root(); Func pbxtd("pbxtd"); pbxtd = dot(pbx,pbt); pbxtd.compute_root(); Func pbytd("pbytd"); pbytd = dot(pby,pbt); pbytd.compute_root(); // 4 debug // Func tmpOut("tmpOut"); tmpOut(x,y,t) = Tuple(pbxy(x,y,t)[0],pbxt(x,y,t)[0],pbyt(x,y,t)[0],pbxyd(x,y,t),pbxtd(x,y,t),pbytd(x,y,t)); // return tmpOut; Func yt_xy("yt_xy"); yt_xy = dot(pbyt(x,y,t),pbxy(x,y,t)); yt_xy.compute_root(); Func xt_yt("xt_yt"); xt_yt = dot(pbxt(x,y,t),pbyt(x,y,t)); xt_yt.compute_root(); Func xt_xy("xt_xy"); xt_xy = dot(pbxt(x,y,t),pbxy(x,y,t)); xt_xy.compute_root(); Func yt_yt("yt_yt"); yt_yt = dot(pbyt(x,y,t),pbyt(x,y,t)); yt_yt.compute_root(); Func xt_xt("xt_xt"); xt_xt = dot(pbxt(x,y,t),pbxt(x,y,t)); xt_xt.compute_root(); Func xy_xy("xy_xy"); xy_xy = dot(pbxy(x,y,t),pbxy(x,y,t)); xy_xy.compute_root(); Tuple Tk_tuple = Tuple(Tk[0](x,y,t),Tk[1](x,y,t),Tk[2](x,y,t), Tk[3](x,y,t),Tk[4](x,y,t)); Func Tkd("Tkd"); Tkd = dot(Tk_tuple,Tk_tuple); Tkd.compute_root(); // Expr Dimen = pbxyd/xy_xy; Expr kill(1.0f); Func Oxy; Oxy(x,y,t) = Mdefdiv(st_filtered[5](x,y,t) - Mdefdivang(yt_xy(x,y,t),yt_yt(x,y,t),pbxyd(x,y,t),divisionthreshold2)*st_filtered[3](x,y,t)*kill,st_filtered[4](x,y,t),divisionthreshold); Oxy.compute_root(); Func Oyx; Oyx(x,y,t) = Mdefdiv(st_filtered[5](x,y,t) + Mdefdivang(xt_xy(x,y,t),xt_xt(x,y,t),pbxyd(x,y,t),divisionthreshold2)*st_filtered[0](x,y,t)*kill,st_filtered[2](x,y,t),divisionthreshold); Oyx.compute_root(); Func C0; C0(x,y,t) = st_filtered[3](x,y,t) * Mdefdivang(Expr(-1.0f)*xt_yt(x,y,t),yt_yt(x,y,t),pbxyd(x,y,t),divisionthreshold2)*kill; C0.compute_root(); Func M0; M0(x,y,t) = Mdefdiv(st_filtered[0](x,y,t) + C0(x,y,t), st_filtered[1](x,y,t)*pow(Mdefdivang(xt_yt(x,y,t),yt_yt(x,y,t),pbxyd(x,y,t),divisionthreshold2),Expr(2.0f)),divisionthreshold); M0.compute_root(); Func C1; C1(x,y,t) = st_filtered[5](x,y,t) * Mdefdivang(Expr(-1.0f)*xt_xy(x,y,t),xy_xy(x,y,t),pbxyd(x,y,t),divisionthreshold2)*kill; C1.compute_root(); Func P1; P1(x,y,t) = pow(Mdefdivang(xt_yt(x,y,t),xt_xt(x,y,t),pbxyd(x,y,t),divisionthreshold2),Expr(2.0f))*kill + 1.0f; P1.compute_root(); // 4 debug // Func tmpOut("tmpOut"); tmpOut(x,y,t) = Tuple(Oxy(x,y,t),Oyx(x,y,t),C0(x,y,t),M0(x,y,t),C1(x,y,t),P1(x,y,t)); // return tmpOut; Func Q1; Q1(x,y,t) = st_filtered[2](x,y,t) * (pow(Oyx(x,y,t),Expr(2.0f))+Expr(1.0f)); Q1.compute_root(); Func M1; M1(x,y,t) = Mdefdiv(((st_filtered[0](x,y,t)-C1(x,y,t))*P1(x,y,t)),Q1(x,y,t),divisionthreshold); M1.compute_root(); Func C2; C2(x,y,t) = st_filtered[0](x,y,t) * Mdefdivang(Expr(-1.0f)*xt_yt(x,y,t),xt_xt(x,y,t),pbxyd(x,y,t),divisionthreshold2)*kill; C2.compute_root(); Func M2; M2(x,y,t) = Mdefdiv(st_filtered[3](x,y,t)+C2(x,y,t),st_filtered[1](x,y,t)*(pow(Mdefdivang(xt_yt(x,y,t),xt_xt(x,y,t),pbxyd(x,y,t),divisionthreshold2),Expr(2.0f))*kill+Expr(1.0f)),divisionthreshold); M2.compute_root(); Func C3; C3(x,y,t) = st_filtered[5](x,y,t) * Mdefdivang(yt_xy(x,y,t),xy_xy(x,y,t),pbxyd(x,y,t),divisionthreshold2)*kill; C3.compute_root(); Func P3; P3(x,y,t) = pow(Mdefdivang(xt_yt(x,y,t),yt_yt(x,y,t),pbxyd(x,y,t),divisionthreshold2),Expr(2.0f))*kill + Expr(1.0f); P3.compute_root(); Func Q3; Q3(x,y,t) = st_filtered[4](x,y,t) * (pow(Oxy(x,y,t),Expr(2.0f))+Expr(1.0f)); Q3.compute_root(); Func M3; M3(x,y,t) = Mdefdiv(((st_filtered[3](x,y,t)-C3(x,y,t))*P3(x,y,t)),Q3(x,y,t),divisionthreshold); M3.compute_root(); Func basisAtAngle; basisAtAngle(x,y,t) = Tuple(M0(x,y,t),M1(x,y,t),M2(x,y,t),M3(x,y,t),Tkd(x,y,t)); return basisAtAngle; // Func hsv2rgb(Func colorImage) { // Took this function // Var x, y, c, t; // Func output; // output(x,y,c,t) = cast <float> (0.0f); // Expr fR, fG, fB; // R,G & B values // Expr fH = (colorImage(x,y,0,t)); //H value [0-360) // Expr fS = (colorImage(x,y,1,t)); //S value // Expr fV = (colorImage(x,y,2,t)); //V value // //Conversion (I took the one on Wikipedia) // // https://fr.wikipedia.org/wiki/Teinte_Saturation_Valeur#Conversion_de_TSV_vers_RVB // Expr fHi = floor(fH / Expr(60.0f)); // Expr fF = fH / 60.0f - fHi; // Expr fL = fV * (1 - fS); // Expr fM = fV * (1 - fF * fS) ; // Expr fN = fV * (1 - (1 - fF) * fS); // fR = select((0 == fHi),fV, // (1 == fHi),fM, // (2 == fHi),fL, // (3 == fHi),fL, // (4 == fHi),fN, // (5 == fHi),fV, // 0.0f); // fG = select((0 == fHi),fN, // (1 == fHi),fV, // (2 == fHi),fV, // (3 == fHi),fM, // (4 == fHi),fL, // (5 == fHi),fL, // 0.0f); // fB = select((0 == fHi),fL, // (1 == fHi),fL, // (2 == fHi),fN, // (3 == fHi),fV, // (4 == fHi),fV, // (5 == fHi),fM, // 0.0f); // output(x,y,0,t) = fR; // output(x,y,1,t) = fG; // output(x,y,2,t) = fB; // return output; // } // Func angle2rgb (Func v) { // Var x, y, c, t; // Func ov, a; // ov(x,y,c,t) = cast <float> (0.0f); // Expr pi2(2*M_PI); // a(x,y,c,t) = v(x,y,c,t) / pi2; // ov(x,y,0,t) = a(x,y,c,t); // ov(x,y,1,t) = 1; // ov(x,y,2,t) = 1; // return ov; // } // Func outputvelocity(Func Blur, Func Speed, Func Angle, int border, Expr speedthreshold, Expr filterthreshold) { // extern Expr width; // extern Expr height; // Func Blur3, Speed3; // Blur3(x,y,c,t) = cast <float> (0.0f); // Speed3(x,y,c,t) = cast <float> (0.0f); // //Scale the grey level images // Blur(x,y,0,t) = (Blur(x,y,0,t) - minimum(Blur(x,y,0,t))) / (maximum(Blur(x,y,0,t)) - minimum(Blur(x,y,0,t))); // //Concatenation along the third dimension // Blur3(x,y,0,t) = Blur(x,y,0,t); // Blur3(x,y,1,t) = Blur(x,y,0,t); // Blur3(x,y,2,t) = Blur(x,y,0,t); // //Speed scaled to 1 // //Concatenation along the third dimension // Speed3(x,y,1,t) = Speed(x,y,0,t); // Speed3(x,y,2,t) = Speed(x,y,0,t); // //Use the log speed to visualise speed // Func LogSpeed; // LogSpeed(x,y,c,t) = fast_log(Speed3(x,y,c,t) + Expr(0.0000001f))/fast_log(Expr(10.0f)); // LogSpeed(x,y,c,t) = (LogSpeed(x,y,c,t) - minimum(LogSpeed(x,y,c,t))) / (maximum(LogSpeed(x,y,c,t)) - minimum(LogSpeed(x,y,c,t))); // //Make a colour image // // uint16_t rows = height; // // uint16_t cols = width; // // int depth = Angle.channels(); // //Do it the HSV way // Func colorImage; // colorImage(x,y,0,t) = Angle(x,y,0,t); // //Do hsv to rgb // Func colorImage1; // colorImage1 = hsv2rgb(colorImage); // // Assume the border equals to the size of spatial filter // //Make the border // // int bir = rows + 2 * border; // // int bic = cols + 2 * border; // Expr orows = height / Expr(2); // Expr ocols = width / Expr(2); // //Rotation matrix // int ph = 0; // Func mb, sb; // // if (rx < border - 1 || rx >= rows+border -1 || ry < border - 1 || ry >= cols+border - 1) { // Expr co1 = x - orows; // Expr co2 = - (y - ocols); // Expr cosPh(cos(ph)); // Expr sinPh(sin(ph)); // Expr rco1 = cosPh * co1 - sinPh * co2; //Using rotation matrix // Expr rco2 = sinPh * co1 + cosPh * co2; // // Expr justPi (M_PI); // mb(x,y,c,t) = // select (((x < (border - 1)) || // (x >= (height+border -1)) || // (y < (border - 1)) || // (y >= (width+border - 1))), // atan2(rco1,rco2) + Expr(M_PI),mb(x,y,c,t)); // sb(x,y,c,t) = // select (((x < (border - 1)) || // (x >= (height+border -1)) || // (y < (border - 1) ) || // (y >= (width+border - 1))), // 1, sb (x,y,c,t)); // Func cb; // cb = angle2rgb(mb); // //Get the old data // // Expr pi2(2*M_PI); // colorImage1(x,y,0,t)=colorImage(x,y,0,t) * Expr(2*M_PI); // colorImage1=angle2rgb(colorImage1); // colorImage1(x,y,c,t)=select(abs(Speed3(x,y,c,t))<speedthreshold,Expr(0.0f),colorImage1(x,y,c,t)); // Func colorImage2; // colorImage2(x,y,c,t) = colorImage1(x,y,c,t) * Speed(x,y,c,t); // //Put the data in the border // RDom bordx (border,rows + border); // RDom bordy (border,cols + border); // Func ang1, ang2; // ang1 (x,y,c,t) = cast <float> (0.0f); // ang2 (x,y,c,t) = cast <float> (0.0f); // cb(bordx, bordy,c,t) = colorImage1(x,y,c,t); // ang1 = cb; // cb(bordx, bordy,c,t) = colorImage2(x,y,c,t); // ang2 = cb; // sb(bordx, bordy,c,t) = Speed3(x,y,c,t); // Speed3 = sb; // sb(bordx, bordy,c,t) = Blur3(x,y,c,t); // Blur3 = sb; // // Func I; // // I (x,y,c,t) = Blur3(x,y,c,t) + Speed3(x,y - height,c,t) + ang1(x - width,y,c,t) + ang2(x - width,y - height,c,t); // //I = cat(2,cat(1,Blur,Speed),cat(1,ang1,ang2)); // return I; // } }
void main() //main code { double Rs = Y*((7.72*pow(10,8))/(6.95*pow(10,10))); double Ms = Y*Y*((5.67*pow(10,33))/(1.98*pow(10,33))); double c = 82; //the parameter rho(c) printf("\nSIRIUS B\n"); printf("\nRunge-Kutta Method\nMs (solar masses) Rs (solar radii) Rho(c) (solar densities) Y(e)\n"); //printing titles for values displayed int n; //the integer steps, n //declare arrays float x[N]; float y[N]; float z[N]; float x2[N]; float y2[N]; float z2[N]; //r,m,p as the radius, mass and density double r,m,p,r2,m2,p2; //declare initial conditons for arrays x[0] = h; //first array is for r=h y[0] = (h*h*h/3)*c; //initial conditon for scaled mass (m) z[0] = c*(1-((h*h*c)/(6*gamma(c)))); //initial conditon for rho //for loop for n=0,1,...,N for(n=0;n<N;n++) { //declared how x(n+1) relates to x(n), y(n+1) relates to y(n), z(n+1) relates to z(n) x[n+1] = x[n]+h; y[n+1] = y[n]+(h/6)*(M(x[n],y[n],z[n])+2*M2(x[n],y[n],z[n])+2*M3(x[n],y[n],z[n])+M4(x[n],y[n],z[n])); z[n+1] = z[n]+(h/6)*(rho(x[n],y[n],z[n])+2*rho2(x[n],y[n],z[n])+2*rho3(x[n],y[n],z[n])+rho4(x[n],y[n],z[n])); if(isnan(z[n+1])) { break; } //r,m,p will be declared in pg-plot r = x[n+1]; m = y[n+1]; p = z[n+1]; } printf("%.3e %.3e %.2f %.3f\n",y[n]*Ms,x[n]*Rs,c,Y); //printed values for x and y respectively printf("\nEuler Method\nMs (solar masses) Rs (solar radii) Rho(c) (solar densities) Y(e)\n"); //printing titles for values displayed //declare initial conditons for arrays x2[0] = h; //first array is for r=h y2[0] = (h*h*h/3)*c; //initial conditon for scaled mass (m) z2[0] = c*(1-((h*h*c)/(6*gamma(c)))); //initial conditon for rho //for loop for n=0,1,...,200 for(n=0;n<N;n++) { //declared how x2(n+1) relates to x2(n), y2(n+1) relates to y2(n), z2(n+1) relates to z2(n) x2[n+1] = x2[n]+h; y2[n+1] = y2[n]+h*(M(x2[n],y2[n],z2[n])); z2[n+1] = z2[n]+h*(rho(x2[n],y2[n],z2[n])); if(z2[n+1]<0) { break; } //r2,m2,p2 will be declared in pg-plot r2 = x2[n+1]; m2 = y2[n+1]; p2 = z2[n+1]; } //printed values for x and y respectively printf("%.3e %.3e %.2f %.3f\n",y2[n]*Ms,x2[n]*Rs,c,Y); }
void TestMatrix(ostream& os) { // display a headline os << "Matrix test\r\n===========\r\n"; Matrix<int> A(3,3), B(3,3), C(3,3), D(3,3); A(0,0) = 1; A(0,1) = 3; A(0,2) = -4; A(1,0) = 1; A(1,1) = 1; A(1,2) = -2; A(2,0) = -1; A(2,1) = -2; A(2,2) = 5; B(0,0) = 8; B(0,1) = 3; B(0,2) = 0; B(1,0) = 3; B(1,1) = 10; B(1,2) = 2; B(2,0) = 0; B(2,1) = 2; B(2,2) = 6; D(0,0) = 1; D(0,1) = 2; D(0,2) = -1; D(1,0) = 2; D(1,1) = -1; D(1,2) = -3; D(2,0) = 0; D(2,1) = -2; D(2,2) = 4; os << "\r\nMatrix A = \r\n"; ShowMatrix(os,A); os << "\r\nMatrix B = \r\n"; ShowMatrix(os,B); C = A % B; os << "\r\nMatrix C (A % B) = \r\n"; ShowMatrix(os,C); C = A + B; os << "\r\nMatrix C (A + B) = \r\n"; ShowMatrix(os,C); C = A; C += B; os << "\r\nMatrix C (= A, += B) =\r\n"; ShowMatrix(os,C); C = A + 1; os << "\r\nMatrix C (= A + 1) =\r\n"; ShowMatrix(os,C); C += 1; os << "\r\nMatrix C (+= 1) =\r\n"; ShowMatrix(os,C); C = A - B; os << "\r\nMatrix C (A - B) = \r\n"; ShowMatrix(os,C); C = A; C -= B; os << "\r\nMatrix C (= A, -= B) =\r\n"; ShowMatrix(os,C); C = A - 1; os << "\r\nMatrix C (= A - 1) =\r\n"; ShowMatrix(os,C); C -= 1; os << "\r\nMatrix C (-= 1) =\r\n"; ShowMatrix(os,C); C = A * B; os << "\r\nMatrix C (A * B) = \r\n"; ShowMatrix(os,C); C = A; C *= B; os << "\r\nMatrix C (= A, *= B) =\r\n"; ShowMatrix(os,C); C = A * 2; os << "\r\nMatrix C (= A * 2) =\r\n"; ShowMatrix(os,C); C *= 2; os << "\r\nMatrix C (*= 2) =\r\n"; ShowMatrix(os,C); C = B / A; os << "\r\nMatrix C (B / A) = \r\n"; ShowMatrix(os,C); C = B; C /= A; os << "\r\nMatrix C (= B, /= A) =\r\n"; ShowMatrix(os,C); C = A / 2; os << "\r\nMatrix C (= A / 2) =\r\n"; ShowMatrix(os,C); C /= 2; os << "\r\nMatrix C (/= 2) =\r\n"; ShowMatrix(os,C); C = -A; os << "\r\nMatrix C (-A) = \r\n"; ShowMatrix(os,C); // test comparisons os << "\r\nMatrix A = \r\n"; ShowMatrix(os,A); os << "\r\nMatrix D = \r\n"; ShowMatrix(os,D); if (A.Equals(D)) os << "\r\nERROR: A should not equal D"; else os << "\r\nOKAY: A not equal D"; C = A; if (A.Equals(C)) os << "\r\nOKAY: A equals C\r\n"; else os << "\r\nERROR: A should equal C\r\n"; Matrix<bool> I(3,3); I = (A == D); os << "\r\nMatrix I = (A == D)\r\n"; ShowMatrix(os,I); I = (A != D); os << "\r\nMatrix I = (A != D)\r\n"; ShowMatrix(os,I); I = (A < D); os << "\r\nMatrix I = (A < D)\r\n"; ShowMatrix(os,I); I = (A <= D); os << "\r\nMatrix I = (A <= D)\r\n"; ShowMatrix(os,I); I = (A > D); os << "\r\nMatrix I = (A > D)\r\n"; ShowMatrix(os,I); I = (A >= D); os << "\r\nMatrix I = (A >= D)\r\n"; ShowMatrix(os,I); // check fill function C.Fill(9); os << "\r\nC filled with 9 =\r\n"; ShowMatrix(os,C); // check Apply functions C = Apply(A, Times2); os << "\r\nC = A.Apply(Times2)\r\n"; ShowMatrix(os,C); C.Apply(Times2); os << "\r\nApply(C,Times2)\r\n"; ShowMatrix(os,C); // check row and column vector functions Matrix<int> S(1,1); Matrix<int> r1A(3,1); Matrix<int> c0B(1,3); r1A = A.VectorRow(1); c0B = B.VectorCol(0); os << "\r\nMatrix S = \r\n"; ShowMatrix(os,S); os << "\r\nMatrix R1A = \r\n"; ShowMatrix(os,r1A); os << "\r\nMatrix C0B = \r\n"; ShowMatrix(os,c0B); if (r1A.IsRowVector()) os << "\r\nOKAY: R1A is row vector"; else os << "\r\nERROR: R1A should be a row vector"; if (!r1A.IsColVector()) os << "\r\nOKAY: R1A is not a column vector"; else os << "\r\nERROR: R1A should not be a column vector"; if (!c0B.IsRowVector()) os << "\r\nOKAY: C0B is not a row vector"; else os << "\r\nERROR: C0B should not be a row vector"; if (c0B.IsColVector()) os << "\r\nOKAY: C0B is column vector"; else os << "\r\nERROR: C0B should be a column vector"; if (c0B.IsVector()) os << "\r\nOKAY: C0B is a vector"; else os << "\r\nERROR: C0B should be a vector"; if (!A.IsVector()) os << "\r\nOKAY: A is not a vector"; else os << "\r\nERROR: A should not be a vector"; if (!c0B.IsSquare()) os << "\r\nOKAY: C0B is not square"; else os << "\r\nERROR: C0B should not be square"; if (A.IsSquare()) os << "\r\nOKAY: A is square"; else os << "\r\nERROR: A should be square"; B.Fill(0); if (B.IsZero()) os << "\r\nOKAY: B is zero"; else os << "\r\nERROR: B should be zero"; if (!A.IsZero()) os << "\r\nOKAY: A is not zero"; else os << "\r\nERROR: A should not be zero"; // test inner product int ip = r1A.InnerProduct(c0B); os << "\r\n\r\ninner product of R1A and C0B = " << ip << "\r\n"; // make some bigger matrices Matrix<int> M1(5,5), M2(5,5,3), M3(5,5), M4(5,5); const int junk[] = { 1, 5, 3, 0, 1, 0, 2, 0, 4, 5, 1, 0, 0, 2, 3, 7, 1, 3, 0, 0, 2, 1, 0, 4, 6 }; const int ident[] = { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 }; const int tridi[] = { 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1 }; const int utri[] = { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1 }; const int ltri[] = { 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1 }; const int perm[] = { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 }; const int det[] = { 3, 5, 3, 8, 1, 2, 6, 3, 4, 5, 1, 4, 5, 2, 3, 7, 1, 3, 6, 8, 2, 4, 1, 4, 9 }; M1 = ident; M3 = M1 * 2; M4 = junk; os << "\r\nmatrix M1 = \r\n"; ShowMatrix(os,M1); os << "\r\nmatrix M2 = \r\n"; ShowMatrix(os,M2); os << "\r\nmatrix M3 = \r\n"; ShowMatrix(os,M3); os << "\r\nmatrix M4 = \r\n"; ShowMatrix(os,M4); if (M1.IsDiagonal()) os << "\r\nOKAY: M1 is diagonal"; else os << "\r\nERROR: M1 should be diagonal"; if (M1.IsIdentity()) os << "\r\nOKAY: M1 is an identity matrix"; else os << "\r\nERROR: M1 should be an identity matrix"; if (!M2.IsDiagonal()) os << "\r\nOKAY: M2 is not diagonal"; else os << "\r\nERROR: M2 should not be diagonal"; if (!M2.IsIdentity()) os << "\r\nOKAY: M2 is not an identity matrix"; else os << "\r\nERROR: M2 should not be an identity matrix"; if (M3.IsDiagonal()) os << "\r\nOKAY: M3 is diagonal"; else os << "\r\nERROR: M3 should be diagonal"; if (!M3.IsIdentity()) os << "\r\nOKAY: M3 is not an identity matrix"; else os << "\r\nERROR: M3 should not be an identity matrix"; if (!M4.IsDiagonal()) os << "\r\nOKAY: M4 is not diagonal"; else os << "\r\nERROR: M4 should not be diagonal"; if (!M4.IsIdentity()) os << "\r\nOKAY: M4 is not an identity matrix"; else os << "\r\nERROR: M4 should not be an identity matrix"; // tridiagonal tests M1 = tridi; os << "\r\n\r\nmatrix M1 = \r\n"; ShowMatrix(os,M1); if (M1.IsTridiagonal()) os << "\r\nOKAY: M1 is tridiagonal"; else os << "\r\nERROR: M1 should be tridiagonal"; if (!M4.IsTridiagonal()) os << "\r\nOKAY: M4 is not tridiagonal"; else os << "\r\nERROR: M1 should not be tridiagonal"; // upper triangular tests M1 = utri; os << "\r\n\r\nmatrix M1 = \r\n"; ShowMatrix(os,M1); if (M1.IsUpperTriangular()) os << "\r\nOKAY: M1 is upper-triangular"; else os << "\r\nERROR: M1 should be upper-triangular"; if (!M4.IsUpperTriangular()) os << "\r\nOKAY: M4 is not upper-triangular"; else os << "\r\nERROR: M4 should not be upper-triangular"; // lower triangular tests M1 = ltri; os << "\r\n\r\nmatrix M1 = \r\n"; ShowMatrix(os,M1); if (M1.IsLowerTriangular()) os << "\r\nOKAY: M1 is lower-triangular"; else os << "\r\nERROR: M1 should be lower-triangular"; if (!M4.IsLowerTriangular()) os << "\r\nOKAY: M4 is not lower-triangular"; else os << "\r\nERROR: M4 should not be lower-triangular"; // permutation tests M1 = perm; os << "\r\n\r\nmatrix M1 = \r\n"; ShowMatrix(os,M1); M2 = ident; os << "\r\n\r\nmatrix M2 = \r\n"; ShowMatrix(os,M2); if (M1.IsPermutation()) os << "\r\nOKAY: M1 is permutation matrix"; else os << "\r\nERROR: M1 should be permutation"; if (M2.IsPermutation()) os << "\r\nOKAY: M2 is permutation matrix"; else os << "\r\nERROR: M2 should be permutation"; if (!M4.IsPermutation()) os << "\r\nOKAY: M4 is not permutation"; else os << "\r\nERROR: M4 should not be permutation"; // check singularity function M1(0,1) = 0; os << "\r\n\r\nmatrix M1 = \r\n"; ShowMatrix(os,M1); if (M1.IsSingular()) os << "\r\nOKAY: M1 is singular"; else os << "\r\nERROR: M1 should be singular"; if (!M2.IsSingular()) os << "\r\nOKAY: M2 is not singular"; else os << "\r\nERROR: M2 should not be singular"; if (!M4.IsSingular()) os << "\r\nOKAY: M4 is not singular"; else os << "\r\nERROR: M4 should not be singular"; // change main window heading os <<endl <<"Matrix Tests (manipulations)" <<endl <<"============================" <<endl; // test minors and determinants os << "\r\n\r\nmatrix M4 = \r\n"; ShowMatrix(os,M4); os << "\r\nminor M4(1,1) = \r\n"; ShowMatrix(os,M4.Minor(1,1)); os << "\r\nminor M4(0,4) = \r\n"; ShowMatrix(os,M4.Minor(0,4)); Matrix<int> M5(2,2), M6(3,3); M5(0,0) = 1; M5(0,1) = 2; M5(1,0) = 3; M5(1,1) = 4; M6(0,0) = 1; M6(0,1) = 3; M6(0,2) = 2; M6(1,0) = 5; M6(1,1) = 4; M6(1,2) = 7; M6(2,0) = 6; M6(2,1) = 9; M6(2,2) = 8; M4 = det; Matrix<int> T4(5,5), T5(2,2), T6(3,3); T4 = M4.Transpose(); T5 = M5.Transpose(); T6 = M6.Transpose(); os << "\r\nmatrix M5 = \r\n"; ShowMatrix(os,M5); os << "\r\ndeterminant of M5 = " << M5.Determinant() << "\r\n"; os << "\r\nmatrix T5 = \r\n"; ShowMatrix(os,T5); os << "\r\ndeterminant of T5 = " << T5.Determinant() << "\r\n"; os << "\r\nmatrix M6 = \r\n"; ShowMatrix(os,M6); os << "\r\ndeterminant of M6 = " << M6.Determinant() << "\r\n"; os << "\r\nmatrix T6 = \r\n"; ShowMatrix(os,T6); os << "\r\ndeterminant of T6 = " << T6.Determinant() << "\r\n"; os << "\r\nmatrix M4 = \r\n"; ShowMatrix(os,M4); os << "\r\ndeterminant of M4 = " << M4.Determinant() << "\r\n"; os << "\r\nmatrix T4 = \r\n"; ShowMatrix(os,T4); os << "\r\ndeterminant of T4 = " << T4.Determinant() << "\r\n"; Matrix<int> R; os << "\r\nMatrix R (def. constr.) = \r\n"; ShowMatrix(os,R); R.Resize(10,10); os << "\r\nMatrix R (now 10x10) = \r\n"; ShowMatrix(os,R); // change main window heading os <<endl <<"Matrix Tests (double)" <<endl <<"=====================" <<endl; // check <double> Matrix os << "\r\nFLOATING POINT!"; Matrix<double> X(3,4), Y(4,3), Z(3,3); X(0,0) = 1.0; X(1,0) = 5.0; X(2,0) = 2.0; X(0,1) = 2.0; X(1,1) = 2.0; X(2,1) = 4.0; X(0,2) = 0.0; X(1,2) = 3.0; X(2,2) = 3.0; X(0,3) = 1.0; X(1,3) = 2.0; X(2,3) = 1.0; Y(0,0) = 0.0; Y(2,0) = 1.0; Y(0,1) = 1.0; Y(2,1) = 0.0; Y(0,2) = 2.0; Y(2,2) = 5.0; Y(1,0) = 1.0; Y(3,0) = 3.0; Y(1,1) = 3.0; Y(3,1) = 1.0; Y(1,2) = 2.0; Y(3,2) = 2.0; os << "\r\nMatrix X = \r\n"; ShowMatrix(os,X); os << "\r\nMatrix Y = \r\n"; ShowMatrix(os,Y); Z = X % Y; os << "\r\nMatrix Z (X % Y) = \r\n"; ShowMatrix(os,Z); // check transposition Matrix<double> tX; tX = X.Transpose(); os << "\r\nOriginal X =\r\n"; ShowMatrix(os,X); os << "\r\nTranspose X =\r\n"; ShowMatrix(os,tX); X(0,0) = 1; X(0,1) = 3; X(0,2) = -4; X(0,3) = 8; X(1,0) = 1; X(1,1) = 1; X(1,2) = -2; X(1,3) = 2; X(2,0) = -1; X(2,1) = -2; X(2,2) = 5; X(2,3) = -1; os << "\r\nOriginal X =\r\n"; ShowMatrix(os,X); Matrix<double> lX(X.LinSolve()); os << "\r\nX after elimination =\r\n"; ShowMatrix(os,X); os << "\r\nlinear equation solution =\r\n"; ShowMatrix(os,lX); X(0,0) = 1.0; X(1,0) = 3.0; X(2,0) = 5.0; X(0,1) = 2.0; X(1,1) = 5.0; X(2,1) = 6.0; X(0,2) = 0.0; X(1,2) = 4.0; X(2,2) = 3.0; X(0,3) = 0.1; X(1,3) = 12.5; X(2,3) = 10.3; os << "\r\nOriginal X =\r\n"; ShowMatrix(os,X); lX = X.LinSolve(); os << "\r\nX after elimination =\r\n"; ShowMatrix(os,X); os << "\r\nlinear equation solution =\r\n"; ShowMatrix(os,lX); Matrix<double> Adbl(3,3), Bdbl(3,1); Adbl(0,0) = 1.0; Adbl(0,1) = 2.0; Adbl(0,2) = 0.0; Adbl(1,0) = 3.0; Adbl(1,1) = 5.0; Adbl(1,2) = 4.0; Adbl(2,0) = 5.0; Adbl(2,1) = 6.0; Adbl(2,2) = 3.0; Bdbl(0,0) = 0.1; Bdbl(1,0) = 12.5; Bdbl(2,0) = 10.3; os << "\r\n\r\nmatrix Adbl = \r\n"; ShowMatrix(os,Adbl); os << "\r\nmatrix Bdbl = \r\n"; ShowMatrix(os,Bdbl); Matrix<double> alup(Adbl); // copy Adbl before LUP decomp os << "\r\nLU decomp of Adbl (before) = \r\n"; ShowMatrix(os,alup); Matrix<size_t> aperm = alup.LUPDecompose(); os << "\r\nLU decomp of Adbl (after) = \r\n"; ShowMatrix(os,alup); os << "\r\nPermutation of Adbl = \r\n"; ShowMatrix(os,aperm); Matrix<double> asol = alup.LUPSolve(aperm,Bdbl); os << "\r\nlinear solution of Adbl and Bdbl = \r\n"; ShowMatrix(os,asol); Matrix<double> ainv = alup.LUPInvert(aperm); os << "\r\ninverse of Adbl and Bdbl = \r\n"; ShowMatrix(os,ainv); Matrix<double> aid = Adbl % ainv; os << "\r\ninverse dot Adbl = \r\n"; ShowMatrix(os,aid); Grid<size_t> iperm = ainv.LUPDecompose(); Matrix<double> invinv = ainv.LUPInvert(iperm); os << "\r\ninverse of inverse =\r\n"; ShowMatrix(os,invinv); }