Simple C programming for gaussian

Click For Summary

Discussion Overview

The discussion revolves around implementing Gaussian elimination in C programming, specifically for solving a 3x3 matrix system. Participants explore coding issues, syntax errors, and the expected output of the program.

Discussion Character

  • Homework-related, Technical explanation

Main Points Raised

  • The initial code provided by the user contains several syntax errors, particularly with the use of semicolons after control statements like for and if.
  • One participant suggests using code tags for better formatting of the posted code.
  • Another participant clarifies the specific method being implemented, which is Gaussian elimination for matrices.
  • A later reply indicates that the issue was resolved by removing unnecessary semicolons, which were causing logical errors in the code execution.

Areas of Agreement / Disagreement

Participants generally agree on the identification of syntax errors in the code. However, there is no consensus on the initial clarity of the problem statement, as some found it vague.

Contextual Notes

The discussion highlights limitations in code formatting and clarity of the problem statement, which may have contributed to initial misunderstandings.

darwinharianto
Messages
42
Reaction score
0

Homework Statement



make a gaussian elimination in C
the one we used on matrix to find x1 x2 and x3
if the matrix is 3x3

Homework Equations

The Attempt at a Solution



Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int i,j,k,n;
    float A[3][4]={{3,0,6,1},{4,1,3,2},{6,3,0,3}};
    float x[3],c,sum=0;
    n=2;
    for(i=0; i<=n; i++);
    {
        for(j=0; j<=n+1; j++);
        {
            if(i>j);
            {
                c=A[i][j]/A[j][j];
                for(k=0; k<=n+1; k++);
                {
                    A[i][k]=A[i][k]-A[j][k]*c;
                }
            }
        }
    }
    x[n]=A[n][n+1]/A[n][n];
    for(i=n-1; i>=0; i--);
    {
        sum=0;
        for(j=i+1; j<=n; j++);
        {
            sum=sum+A[i][j]*x[j];
        }
        x[i]=(A[i][n+1]-sum)/A[i][i];
    }
    printf("\nThe solution is: \n");
        for(i=0; i<=n; i++);
        {
            printf("\nx%d=%f\t",i,x[i]);
      }
    return(0);
}
at the end, only x0 and x1 displayed as the solution
should be x0 x1 and x2 right?
and the result

x0=-784.191895

x1=0.000000

seems to be incorrect
anything that i did wrong?
thx for reply
[/I][/I][/I][/I][/I][/I][/I][/I][/I]
 
Last edited:
Physics news on Phys.org
Can you edit your post to use the [ code ] tags?

They will preserve your code indentation without the need for an attachment.
 
jedishrfu said:
Can you edit your post to use the [ code ] tags?

They will preserve your code indentation without the need for an attachment.
how do i do that?
still new in this area
 
darwinharianto said:
how do i do that?
still new in this area

put [C O D E] in front of your code and [/ C O D E] after it (but do NOT include the spaces in the tags. I had to insert them to keep this post from looking like code and hiding the tags.
 
phinds said:
put [C O D E] in front of your code and [/ C O D E] after it (but do NOT include the spaces in the tags. I had to insert them to keep this post from looking like code and hiding the tags.
ok
thanks
just like that right?
 
Make a 'gaussian' what in C? Your problem statement is a little vague.
 
SteamKing said:
Make a 'gaussian' what in C? Your problem statement is a little vague.
gaussian elimination in matrix
sorry its not so clear
 
problem solved
by removing ; after for and if
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 21 ·
Replies
21
Views
4K
Replies
14
Views
2K