Roblikescmptrs
Technical User
Can anyone help me set-up and solve a 3 equation set of linear simultaneous equations using Visual C++. I am working on a project at work, and have taken both C++ and C, but have not written programs in a couple of years, so I am a little out of practice. The problem is this:
(A) 3X + 5Y +7Z = 10
(B) X - 2Y + Z = 0
(C) 2X + 7Y - 4Z = -5
Solving by hand I come up with;
-2*(B) -2X + 4Y -2Z = 0
add to (C) (C); 2X + 7Y - 4Z = -5
(D); 0 + 11Y - 6Z = -5
add -3*(B) (A); 3X + 5Y + 7Z = 10
to (A) -3*(B); -3X + 6Y - 3Z = 0
(E); 0 11Y + 4Z = 10
add -1*(E) (D); 11Y - 6Z = -5
to (D) -1*(E); -11Y - 4Z = -10
(F); 0 - 10Z = -15
solving for Z = 3/2
substituting 3/2 for Z in (E)
11Y + 4*(3/2) = 10
11Y + 6 = 10
11Y = 4
Y = 4/11
substituting values for y and z in (B) to obtain x;
X - 2*(4/11) + 3/2 = 0
X - 8/11 + 3/2 = 0
X = 8/11 - 3/2
X = -17/11
I checked these answers on my calculator using reduced row echelon form--rref--and they came out the same. I was going to define X, Y, and Z to be floats. I was going to somehow use A, B, and C for the three given equation, respectively, but I don't think I can do this. Can anywone help me get going on this?
(A) 3X + 5Y +7Z = 10
(B) X - 2Y + Z = 0
(C) 2X + 7Y - 4Z = -5
Solving by hand I come up with;
-2*(B) -2X + 4Y -2Z = 0
add to (C) (C); 2X + 7Y - 4Z = -5
(D); 0 + 11Y - 6Z = -5
add -3*(B) (A); 3X + 5Y + 7Z = 10
to (A) -3*(B); -3X + 6Y - 3Z = 0
(E); 0 11Y + 4Z = 10
add -1*(E) (D); 11Y - 6Z = -5
to (D) -1*(E); -11Y - 4Z = -10
(F); 0 - 10Z = -15
solving for Z = 3/2
substituting 3/2 for Z in (E)
11Y + 4*(3/2) = 10
11Y + 6 = 10
11Y = 4
Y = 4/11
substituting values for y and z in (B) to obtain x;
X - 2*(4/11) + 3/2 = 0
X - 8/11 + 3/2 = 0
X = 8/11 - 3/2
X = -17/11
I checked these answers on my calculator using reduced row echelon form--rref--and they came out the same. I was going to define X, Y, and Z to be floats. I was going to somehow use A, B, and C for the three given equation, respectively, but I don't think I can do this. Can anywone help me get going on this?