Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » sci.math.* » sci.math.independent

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
KBH

Posts: 106
Registered: 3/14/10
Re: Three Equations with Three Unknowns
Posted: Jul 24, 2013 2:05 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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
WriteLn(' [ Solution not found ]');
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: ');
ReadLn(p);
Write(' Input a12: ');
ReadLn(q);
Write(' Input a13: ');
ReadLn(r);
Write(' Input b1 : ');
ReadLn(s);
Write(' Input a21: ');
ReadLn(pp);
Write(' Input a22: ');
ReadLn(qq);
Write(' Input a23: ');
ReadLn(rr);
Write(' Input b2 : ');
ReadLn(ss);
Write(' Input a31: ');
ReadLn(ppp);
Write(' Input a32: ');
ReadLn(qqq);
Write(' Input a33: ');
ReadLn(rrr);
Write(' Input b3 : ');
ReadLn(sss);
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;
ReadLn;
end.




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.