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

Home Forums CFD foundation course: Forum Assignment 6: Linear equation

  • Assignment 6: Linear equation

    Posted by SIVARAMAN on December 20, 2023 at 12:41 am

    Hi,

    In matlab programming, I have doubt on the following areas,

    (1) nb=n+1. could you please tell me why we use this term.

    (2) Also, Aug(j,i:nb)=Aug(j,i:nb)-factor*Aug(i,i:nb) – i do not understand this also.

    (3) I wrote the program as below, but i got error on AB(j,:)=AB(j,:)-fac*AB(i;j);

    (4) i=1:n-1 (It means, we are eliminating the last column of augmented matrix, am i correct)

    AB = [A B];

    [m,n]=size(AB);

    for i=1:n-1

    for j=i+1:n

    fac=AB(j,i)/AB(ii);

    AB(j,:)=AB(j,:)-fac*AB(i;j);

    end

    end

    Please clarify.
    Thank you.

    Rahul replied 3 months, 4 weeks ago 3 Members · 4 Replies
  • 4 Replies
  • SIVARAMAN

    Member
    December 20, 2023 at 1:12 am

    Sorry, This is Lesson 7 Assignment. Liner equation Gauss elimination program

  • Sujith FTL

    Member
    December 20, 2023 at 7:51 am

    Hello Sivaraman,

    (1) nb=n+1; (nb represents the total number of columns in the augmented matrix, including the constants column.)

    (2) Aug(j,i:nb)=Aug(j,i:nb)-factor*Aug(i,i:nb); (This updates row j to eliminate the variable in column i.)

    (3) AB(j,:)=AB(j,:)-fac*AB(i, :); (Correcting the typo in indexing.)

    (4) i=1:n-1 (The loop eliminates variables up to the second-to-last column.)

  • SIVARAMAN

    Member
    December 20, 2023 at 10:03 pm

    Hi,

    nb=n+1 (Please help me to understand the reason for writing n+1)
    Shall we write [m,n]=size(Aug) (instead of writing nb=n+1)

    Aug(j,i:nb)=Aug(j,i:nb)-factor*Aug(i,i:nb) instead of this, can I write AB(j,:)=AB(j,:)-fac*AB(i,:).

    • Rahul

      Member
      December 21, 2023 at 2:19 am

      Hi Sivaraman,

      The reason for using n+1 is precisely as suggested by Sujith. Since the augmented matrix will have 1 more column than the matrix A, which is an nxn matrix, based on the number of equations. Your implementation using (m,nb)=size(Aug) should also work out similarly. I suggest you to try it out, as it is a coding assignment and there is no compulsion to write the code exactly as discussed in the assignment lectures. You are free to make changes in implementation as long as the methodology and results are correct.

      For the second part of the question, again, as I mentioned, since it is a coding assignment please feel free to try it out and you can also post the result of your experimentation here so that others may also try it out. There’s definitely no harm in testing it. It should work out similarly. The code discussed in the videos is made considering readability and to make it easily understandable to people who may not be very familiar with programming as well. So it may have a couple of extra lines too for this, especially since it is not a programming course and aims to give an idea of the process.

      Best regards
      Rahul
      Flowthermolab support

Log in to reply.

error: Content is protected !!