Join 136,095 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,624 people online right now. Registration is fast and FREE... Join Now!
hi guys im a beginner here, can someone help me out.. i need a guide in solving guass-jordan in using arrays and pointers only..
1. the program must have at least four functions aside from the main(): input function, function that forms the matrix, function that performs the elimination process, and function that computes for the values of the variables. 2. the program must display the original matrix and the matrices generated at different stages of the elimination process. it must display also the resulting values of the variables used in the linear equations. 3. do not declare global variables. 4. function parameters should be limited to arrays and pointers only. i really need your help and i would appreciate it very much..thank you very much!!! please reply!!!
here is a program in C i made. but it only runs in 2 inputted values.. can somone give me some pointers... sorry for the messy formatting im new in programming...
you need to use floating point numbers for variables that you're going to be using in floating point operations. specifically, your h variable in eliminate() needs to be floating point, because you use it later in a couple of steps. if you try to assign a floating point value to an int, the decimals will get truncated, giving you incorrect results (at least in this case - there may be scenarios in which this truncation is desirable).
you assign x=0 within the control structure of a for-loop...move it either into or outside of the loop, depending on where you actually want it. let the control structures be just that; don't make the code any more obfuscated than is absolutely necessary.
i believe that you are reading past the boundaries of the valid data in all of your functions, specifically anywhere that has the form:
h=d[l+i] [l]/ d[l][l]
or something similar. since your ranges for l and i are 0...k-1, this means that you are accessing row 2*k-2, which is outside of the limits of your input arrays. this will result in divide by zeros at several points, which is why you are seeing indeterminate numbers in your output array for n>2.
you are also passing float* for your first arguments to all of the functions, when they've been defined as accepting int*.
and the code doesn't work for 2-variable systems...the output is always {0,0}, regardless of the input. i have a feeling that correcting your array boundaries may help fix this problem.
you should also be specifying a return value for main, and using int main().
and finally, you need to comment your code. i am familiar with gauss-jordan elimination, so some of it makes sense, but you need to explain, at the very least, the steps take in each of your functions.
if you continue to experience problems with the output, search of go back through this forum - a number of recent threads have covered gj elimination.
-jjh
This post has been edited by jjhaag: 2 Oct, 2007 - 10:21 PM
no worries...as for references, i'd take a look at numerical recipes, which is available online (in pdf) here. it's a great reference for numerical computation, although the version available is fairly outdated.
Please post your code within the CODE tag. Before posting the query do read the rules of the forum.
QUOTE(nebross000 @ 2 Oct, 2007 - 09:41 PM)
hi guys im a beginner here, can someone help me out.. i need a guide in solving guass-jordan in using arrays and pointers only..
1. the program must have at least four functions aside from the main(): input function, function that forms the matrix, function that performs the elimination process, and function that computes for the values of the variables. 2. the program must display the original matrix and the matrices generated at different stages of the elimination process. it must display also the resulting values of the variables used in the linear equations. 3. do not declare global variables. 4. function parameters should be limited to arrays and pointers only. i really need your help and i would appreciate it very much..thank you very much!!! please reply!!!
here is a program in C i made. but it only runs in 2 inputted values.. can somone give me some pointers... sorry for the messy formatting im new in programming...