Changeset 3dd9c7
- Timestamp:
- Dec 4, 2010, 11:56:27 PM (14 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 694eae
- Parents:
- 40be55
- git-author:
- Frederik Heber <heber@…> (11/18/10 14:50:54)
- git-committer:
- Frederik Heber <heber@…> (12/04/10 23:56:27)
- Location:
- src/LinearAlgebra
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/LinearAlgebra/VectorContent.cpp
r40be55 r3dd9c7 380 380 }; 381 381 382 /* ========================== Norm =============================== */ 383 /** Calculates norm of this vector. 384 * \return \f$|x|\f$ 385 */ 386 double VectorContent::Norm() const 387 { 388 return (sqrt(NormSquared())); 389 }; 390 391 /** Calculates squared norm of this vector. 392 * \return \f$|x|^2\f$ 393 */ 394 double VectorContent::NormSquared() const 395 { 396 return (ScalarProduct(*this)); 397 }; 398 399 /** Normalizes this vector. 400 */ 401 void VectorContent::Normalize() 402 { 403 double factor = Norm(); 404 (*this) *= 1/factor; 405 }; 406 407 VectorContent VectorContent::getNormalized() const{ 408 VectorContent res= *this; 409 res.Normalize(); 410 return res; 411 } 412 413 /* ======================== Properties ============================= */ 414 /** Calculates the squared distance to some other vector. 415 * @param y other vector 416 * @return \f$|(\text{*this})-y|^2\f$ 417 */ 418 double VectorContent::DistanceSquared(const VectorContent &y) const 419 { 420 double res = 0.; 421 for (int i=dimension;i--;) 422 res += (at(i)-y[i])*(at(i)-y[i]); 423 return (res); 424 } 425 426 /** Calculates scalar product between \a *this and \a b. 427 * @param b other vector 428 * @return \f$| (*this) \cdot (b)|^2\f$ 429 */ 430 double VectorContent::ScalarProduct(const VectorContent &y) const 431 { 432 return ((*this)*y); 433 } 434 435 /** Calculates the angle between \a *this and \a y. 436 * 437 * @param y other vector 438 * @return \f$\acos\bigl(frac{\langle \text{*this}, y \rangle}{|\text{*this}||y|}\bigr)\f$ 439 */ 440 double VectorContent::Angle(const VectorContent &y) const 441 { 442 double norm1 = Norm(), norm2 = y.Norm(); 443 double angle = -1; 444 if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON)) 445 angle = this->ScalarProduct(y)/norm1/norm2; 446 // -1-MYEPSILON occured due to numerical imprecision, catch ... 447 //Log() << Verbose(2) << "INFO: acos(-1) = " << acos(-1) << ", acos(-1+MYEPSILON) = " << acos(-1+MYEPSILON) << ", acos(-1-MYEPSILON) = " << acos(-1-MYEPSILON) << "." << endl; 448 if (angle < -1) 449 angle = -1; 450 if (angle > 1) 451 angle = 1; 452 return acos(angle); 453 } 454 382 455 /* ======================== Properties ============================= */ 383 456 /** Calculates scalar product between \a *this and \a b. … … 385 458 * @return \f$| (*this) \cdot (b)|^2\f$ 386 459 */ 387 const double VectorContent::operator*(const VectorContent& b) 460 const double VectorContent::operator*(const VectorContent& b) const 388 461 { 389 462 double res = 0.; -
src/LinearAlgebra/VectorContent.hpp
r40be55 r3dd9c7 71 71 72 72 // properties 73 bool IsNormalTo(const Vector &normal) const; 74 bool IsEqualTo(const Vector &a) const; 73 //bool IsNormalTo(const VectorContent &normal) const; 74 //bool IsEqualTo(const VectorContent &a) const; 75 76 // Norms 77 double Norm() const; 78 double NormSquared() const; 79 void Normalize(); 80 VectorContent getNormalized() const; 75 81 76 82 // properties relative to another VectorContent … … 84 90 const VectorContent& operator-=(const VectorContent& b); 85 91 const VectorContent& operator*=(const double m); 86 const double operator*(const VectorContent& b) ;92 const double operator*(const VectorContent& b) const; 87 93 88 94 size_t dimension;
Note:
See TracChangeset
for help on using the changeset viewer.