Sharp MZ-80A Owner's Manual page 87

Hide thumbs Also See for MZ-80A:
Table of Contents

Advertisement

Programming
Let's formulate an algorithm
for solving systems
of simultaneous linear equations.
97
LU
Assign the
number of unknowns
to
variable
N.
Prepare a
1 -dimensional array X(N)
to
store the
value of the unknowns.
Prepare
a
2-dimensional array A(N, N+l) and
to it assign
the coefficients
of the equations in
(1).
a
Call the subroutine for solving systems of simultaneous linear equations.
0
Print the values of the unknowns (that
is,
the contents of X(l)
to
X(N)) on the CRT display
unit.
Subroutine
(for
solving
systems
of simultaneous linear equations)
S
Perform the elimination process N-l
times to
change the
contents
of array
A to the
coefficients
of the equations in (4).
E
Find the values of the
unknowns in
sequence and assign them to X(N) through X(l).
In this
manner,
we can
clearly identify the subroutine (for solving
systems
of simultaneous linear equations) as
3
basic module which takes
the
value of variable N as the number of unknowns and the
contents
of 2-dimensional array
A(N.N+1)
as
the coefficients of the equations
in (1),
finds
values of the
unknowns,
and assign them to array
X(N)
from X(N) to X(l).
First,
let's consider
step
3]
whkh
is the most important
elimination
step. As
seen
from the equations in (2), the
kth
(k
=
1
to
N
1) elimination process
is
carried
out
basically by repetitions of
assignment
a,,
-
ak,
a
,,
-
(—
denotes
assignment.)
aa
for coefficient
This can be accomplished by executing the 2-level loop
51
FOR
i
=
k + 1
TO N
FOR
j=k+ 1 TO
N+ 1
akk
t
in
(ik
)
a.,
a.k
NEXT
j
NEXT
;
Loop for
one
row
Loop for rows k through N
Step
[T|
can be programmed
in
this way
using
variables
K.
I,
and
J as follows:
FOR K
=
1
TO N— 1
FOR I
=K-<-l
TO N
FOR
J=K FJ TO
A(I
. J
)
=
A
(
K
. J
)
A(
I
.
J)*A(K
.
K)/A(I
.
K)
NEXT
J
NEXT I
These
statements
can be
combined
to
one as NEXT
J.
I,
K.
NEXT K
Now proceed to
step
[3]
.
where the values of the unknowns
are found
in
sequence. To find
the value of unknown
jc(,
all that is required is
to assign
xÿx
through
xn
to the set of equations in (5). Consequently,
we obtain
FOR
j
i+ 1 TO N
a.
.v
-
1
*
-
a,
v
-
1
"
a.
j
x,
NEXT
j
Xj
a,
x
-
1
a.,

Advertisement

Table of Contents
loading

Table of Contents