Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: Three Equations with Three Unknowns
Replies: 15   Last Post: Jul 30, 2013 5:44 PM

 Messages: [ Previous | Next ]
 KBH Posts: 178 Registered: 3/14/10
Re: Three Equations with Three Unknowns
Posted: Jul 24, 2013 2:05 AM

Here is the KBH code with an additonal historical note:

Var
p, q, r, pp, qq, rr, ppp, qqq, rrr, s, ss, sss, ssss, pppp, qqqq, rrrr: double;
clc: double;
a, b, c: double;
flg: shortint;

Procedure Wrt;
Begin
WriteLn(p:14:4, q:14:4, r:14:4, s:14:4);
WriteLn(pp:14:4, qq:14:4, rr:14:4, ss:14:4);
WriteLn(ppp:14:4, qqq:14:4, rrr:14:4, sss:14:4);
WriteLn;
End;

Procedure Noso;
Begin
flg:= 1;
End;

Procedure Frstsec;
Begin
pppp:= p;
qqqq:= q;
rrrr:= r;
ssss:= s;
p:= pp;
q:= qq;
r:= rr;
s:= ss;
pp:= pppp;
qq:= qqqq;
rr:= rrrr;
ss:= ssss;
End;

Procedure Secthrd;
Begin
pppp:= ppp;
qqqq:= qqq;
rrrr:= rrr;
ssss:= sss;
ppp:= pp;
qqq:= qq;
rrr:= rr;
sss:= ss;
pp:= pppp;
qq:= qqqq;
rr:= rrrr;
ss:= ssss;
End;

begin
{KBH code}
WriteLn;
flg:= 0;
Write(' Input a11: ');
Write(' Input a12: ');
Write(' Input a13: ');
Write(' Input b1 : ');
Write(' Input a21: ');
Write(' Input a22: ');
Write(' Input a23: ');
Write(' Input b2 : ');
Write(' Input a31: ');
Write(' Input a32: ');
Write(' Input a33: ');
Write(' Input b3 : ');
WriteLn;
Wrt;

{Begin 3x3 Gaussian Elimination}

If (p = 0) And (pp = 0) And (ppp = 0) Then Noso; {5/16/05}

If (flg = 0) Then
Begin
If (p = 0) And (pp <> 0) Then Frstsec; {5/16/05}
If (p = 0) And (pp = 0) Then {5/16/05}
Begin
Secthrd;
Frstsec;
End;
{If (ppp = 0) Or (rrr = 0) Then Secthrd;} {Out 5/15/05}
If (pp <> 0) Then
Begin
clc:= -(pp / p);
pp:= pp + (p * clc);
qq:= qq + (q * clc);
rr:= rr + (r * clc);
ss:= ss + (s * clc);
Wrt;
End;
If (ppp <> 0) Then
Begin
clc:= -(ppp / p);
ppp:= ppp + (p * clc);
qqq:= qqq + (q * clc);
rrr:= rrr + (r * clc);
sss:= sss + (s * clc);
Wrt;
End;
End;

If (qq = 0) And (qqq = 0) Then Noso;

If (flg = 0) Then
Begin
If (qq = 0) Then Secthrd;
If (qqq <> 0) Then
Begin
clc:= -(qqq / qq);
qqq:= qqq + (qq * clc);
rrr:= rrr + (rr * clc);
sss:= sss + (ss * clc);
Wrt;
End;
End;

If (rrr = 0) And (sss <> 0) Then Noso; {sss <> 0 07/23/2013}

If (flg = 0) Then
Begin
If (rrr <> 0) Then {If rrr <> 0 07/23/2013}
Begin
sss:= sss / rrr;
rrr:= rrr / rrr;
End;
Wrt;
{End 3x3 Gaussian Elimination}
{Begin substitution}
c:= sss;
If (qq <> 0) Then b:= (ss - (rr * c)) / qq Else b:= 0;
a:= (s - (q * b) - (r * c)) / p;
WriteLn(a:14:8);
WriteLn(b:14:8);
WriteLn(c:14:8);
{End substitution}
End;
end.

Date Subject Author
7/24/13 KBH
7/24/13 KBH
7/24/13 William Elliot
7/24/13 KBH
7/24/13 service1588@gmail.com
7/24/13 Peter Percival
7/24/13 quasi
7/24/13 KBH
7/25/13 Ken.Pledger@vuw.ac.nz
7/25/13 Virgil
7/25/13 fom
7/26/13 KBH
7/26/13 Waldek Hebisch
7/26/13 KBH
7/30/13 Ken.Pledger@vuw.ac.nz
7/26/13 KBH