Solve equations with substitution method: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 87:
<pre>
x = -2, y = 5
</pre>
 
=={{header|XPL0}}==
This shows the vector routines from xpllib.xpl.
<lang XPL0>func real VSub(A, B, C); \Subtract two 3D vectors
real A, B, C; \A:= B - C
[A(0):= B(0) - C(0); \VSub(A, A, C) => A:= A - C
A(1):= B(1) - C(1);
A(2):= B(2) - C(2);
return A;
]; \VSub
 
func real VMul(A, B, S); \Multiply 3D vector by a scalar
real A, B, S; \A:= B * S
[A(0):= B(0) * S; \VMul(A, A, S) => A:= A * S
A(1):= B(1) * S;
A(2):= B(2) * S;
return A;
]; \VMul
 
real E1, E2, X1, X2, X, Y;
[E1:= [3., 1., -1.];
E2:= [2., -3., -19.];
X1:= E1(0);
X2:= E2(0);
VMul(E1, E1, X2);
VMul(E2, E2, X1);
VSub(E1, E1, E2);
Y:= E1(2)/E1(1);
E2(1):= E2(1)*Y;
E2(2):= E2(2)-E2(1);
X:= E2(2)/E2(0);
Text(0, "x = "); RlOut(0, X); CrLf(0);
Text(0, "y = "); RlOut(0, Y); CrLf(0);
]</lang>
 
{{out}}
<pre>
x = -2.00000
y = 5.00000
</pre>
772

edits