matrices
I just had a question about a project I am working on. I am supposed to design a program that will solve up to fifty simultaneous equations using gauss jordan.
I just was wondering what would be the best way to find the "PIVOT"(the largest absolute value number in the first column). Once you have found the "pivot" I then need to interchange that row with row 1. Any suggestions? Code:
#include<iostream> 
Re: matrices
best way = probably the only way: start at the first row, record the value, see if the value in the second row is higher, then the 3rd, and repeat until you get to the end of the column. When the value you're looking at exceeds the value stored, update the value stored and where you found the new value.

Re: matrices
Quote:

Re: matrices
Something like this would do the trick:
Code:
max <= a[0][0] So your loop above starting from 1 and ending at n will not work (actually it will work for all n<=1<=49 but at n=50 there will be undefined behaviour because a[50] doesn't exist). Code:
for (i=1;i<=n;i++) 
Re: matrices
Quote:
Yes I knew about the 0...49 but thanks for reminding me. Hmm, at n=50 that will be 2500 values. This will be spectacularly tedious. Yes this will be very very tedious if you would ever have to enter a 50x50 matrix :cuss: and even a 10x10 takes some time. The instructions were to allow the user to tell how many variables they desire and allow them to enter all of the values into the program and then use gauss jordan to solve the simultaneous system. Are the array values in a file anywhere? No the array values aren't in a file because they aren't predetermined values as mentioned above. The user will have to enter their own values. This would however be a good test I think to check to see if the program would compute the matrices correctly without having to type in values over and over. I definately don't want to be the one to type in all of those values. 
Re: matrices
Quote:

Re: matrices
> Is there any way to check to determine the greatest value that is chosen to be the pivot using this sample code you provided?
I don't understand the question. The code does both; it tells you what the maximum value is (max) and what row it is on (loc). > How would you swap the rows? Same way I would swap the values of two variables, but done with arrays in a loop. This is one way to swap two variables; it uses a 3rd for temporary storage: Code:
int a=10, b=20, c; 
Re: matrices
Quote:

Re: matrices
That one wasn't worded correctly either, I guess. Presumably you've tried cout << value; ?
If so how is that not what you want? But I don't see how "how would you use cout to check a value" can be an explanation for "how do you swap the rows" when an answer to "how do you swap the rows" makes you realise that "how do you swap the rows" isn't what you meant. I'm confused... 
Re: matrices
Quote:
Yes I have tried to do cout<<value; for example.. The program asks how many variables do I want to solve for and I type 2. It is going to then ask me for Row 1 column 1 etc.... If I type in 5 9 = 12 8 7 = 15 Obviously the largest value in the first column is 8. Since this value is being used as my pivot. The row that the pivot is in, now needs to be interchanged with row 1. All I wanted to do was use a cout<< statement to make 100% sure that the program is selecting the correct value. I am just not sure what that "value" needs to be. It's going to be a single value from the first column of the matrix obviously in this case 8, but without a variable actually assigned to that value. How would you use a cout<< statement? I really hope that made more sense. Sorry for the confusion. 
All times are GMT +5.5. The time now is 11:23. 