Skip to content

Petertuong/tinyproject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

In this project, we've embarked on building a foundational C++ library for linear algebra, a critical component in countless scientific and engineering applications. Our work centers around three core classes: Vector, Matrix, and a LinearSystem hierarchy, each meticulously designed to handle the complexities of numerical computation.

The motivation behind this endeavor is multifaceted. Beyond demonstrating proficiency in C++ object-oriented principles—like dynamic memory management, operator overloading for intuitive syntax, and the power of inheritance and polymorphism—this project has been a deep dive into the practical application of linear algebra theory. It's about translating abstract mathematical concepts into robust, executable code. This journey has sharpened our algorithmic thinking, pushing us to consider not just what operations are needed, but how to implement them efficiently and numerically stably, especially when dealing with challenging scenarios like overdetermined systems or ensuring proper memory handling.

Our approach has been systematic, leveraging C++'s strengths to build a robust and extensible system. The Vector and Matrix classes are constructed with paramount attention to dynamic memory management; this means carefully orchestrating new and delete calls within constructors, destructors, copy constructors, and assignment operators to prevent insidious memory leaks and ensure proper deep copying of data. This adherence to the Rule of Three/Five is fundamental for stable, long-running applications. Furthermore, operator overloading (+, -, *, =, (), ++, --, []) isn't merely a syntactic convenience; it's a design choice that allows our code to mirror mathematical notation directly, enhancing readability and reducing the cognitive load for anyone working with these linear algebra objects. This makes the code not just functional, but inherently more expressive.

The LinearSystem base class, with its virtual solve() method, is a prime example of polymorphism in action. This design allows us to define a common interface for solving linear systems while deferring the specific implementation to derived classes. For instance, PosSymLinSystem would internally employ highly optimized algorithms like Cholesky decomposition, chosen specifically for their efficiency and numerical stability when dealing with positive symmetric matrices. Conversely, OverDeterminedLinSystem tackles the inherent instability of overdetermined systems by integrating Tikhonov regularization. This involves transforming the original problem into a more well-conditioned one, often leading to a positive definite system that can then be solved robustly. The decision to use these specific algorithms isn't arbitrary; it reflects a deep understanding of the numerical properties of different matrix types and the trade-offs between computational cost and solution accuracy. Throughout the coding process, we've remained vigilant about potential pitfalls such as dimension mismatches or singular matrices, implicitly building in checks to ensure the integrity and reliability of operations.

The successful implementation of this library signifies more than just functional code; it represents a profound insight into the interplay between theoretical mathematics and practical computation. The Vector and Matrix classes provide a reliable, intuitive toolkit for basic operations, confirming a solid grasp of C++ features and underlying algorithms. More importantly, the LinearSystem components highlight an understanding of how to approach and solve different classes of linear equations, recognizing the critical importance of numerical stability and error assessment (as seen with computeResidualNorm). This project is a testament to our ability to apply abstract knowledge to build tangible, functional solutions, laying a strong groundwork for future work in computational science and data analysis.

About

Define Vector, Matrix and Linear System

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages