Find answers, ask questions, and connect with our <br>community around the world.

Home Forums CPP scientific computing discussion Assignment in Linear System calculations in c++

  • Assignment in Linear System calculations in c++

    Posted by Yagna Murthy on January 7, 2024 at 4:10 pm

    Hi, sir; I am creating a Linear system class. could you please be more precise about the task? Is it complete pivoting or partial? I addition to that I didn’t get this paragraph

    We suggest only allowing the user to set up a linear system through the use of a constructor that requires specifcation of the matrix and vector: the member mSize may then be determined from these two members.

    Is that mean a method like

    public :

    int LinearSystem(const double *mpA, const double *mpb);

    or

    Just a constructor which LinearSystem( ) and the user should mention the size and give the coefficient matrix and constant vector during compilation time?

    If you do not wish to provide a copy constructor, then the automatically generated copy constructor should be overridden and made private to prevent its use. As with the class of vectors, we recommend the use of the automatically generated default constructor, which is prevented by providing a specialized constructor but no default constructor.

    private :

    LinearSystem( )

    I didn’t get these lines. Could you please explain it more? Also, Can we use the inheritance concept and include the matrix class, which is mentioned in the previous task, and just the Gauss elimination method by passing two matrices and expecting a return type as matrix nx1? or should I separate the tasks and do it from the scratch like matrix allocation and assigning the values and then solving the matrix.

    Yagna Murthy replied 3 months, 1 week ago 3 Members · 4 Replies
  • 4 Replies
  • Nishant

    Member
    January 8, 2024 at 11:57 am

    Hello Yagna Murthy,

    I am pleased to see that you have been able to come this far in the course and spending time doing the assignments. I will try to clarify your queries one by one.

    1. We suggest only allowing the user to set up a linear system through the use of a constructor that requires specification of the matrix and vector: the member mSize may then be determined from these two members.

    The above line implies that the constructor will have a syntax like,

    LinearSystem(const Matrix& A, const Vector& b);

    Inside the constructor implementation first, you can check that the matrix and vector are of compatible sizes.

    You will need to think about how to determine the member mSize from A and b. Please note that the constructor method will not return any value.

    2. If you do not wish to provide a copy constructor, then the automatically generated copy constructor should be overridden and made private to prevent its use. As with the class of vectors, we recommend that the use of the automatically generated default constructor is prevented by providing a specialised constructor but no default constructor.

    The above implies that you should not have a default constructor of the form, LinearSystem(). Recall that a default constructor does not take any arguments. The copy constructor should be a private member method of the class. The syntax would be,

    LinearSystem(const LinearSystem& otherLinearSystem){};

    3. I will recommend including the matrix and vector header files in the header file of your LinearSystem class implementation.

    #include “Matrix.hpp”

    #include “Vector.hpp”

    Many experts in the field of Scientific Computing do not recommend the use of inheritance for developing libraries for numerical applications. You can write a member method,

    virtual Vector Solve();,

    for solving the LinearSystem within your LinearSystem class using Gauss Elimination. You will need to perform pivoting wherever necessary to prevent overflow errors.

    Hope that helps. Please let me know if you have any further questions.

    Happy Learning. Cheers!

  • Yagna Murthy

    Member
    January 8, 2024 at 9:10 pm

    Hi, sir; thanks for your support. I am attaching a screenshot of my code here. I need support again. I couldn’t create an operator[]. I am getting some errors when trying to develop in the matrix header file, like too many arguments, and I changed the access of pointer member in the matrix and vector header. To use its linear functions.

    I am passing the augmented matrix into the solve method. I initially tried to pass the matrix and constant vector and create an augmented matrix in the function but faced some difficulty. Could you please help me out with that?

    Thanks in advance

    • Rahul

      Member
      January 10, 2024 at 10:55 am

      Hi Yagna,
      Were you able to resolve these issues yourself or does it persist? Please let us know.
      Best regards
      Rahul
      Flowthermolab support

      • Yagna Murthy

        Member
        January 10, 2024 at 10:58 am

        Yeah I resolved it by myself.

Log in to reply.

error: Content is protected !!