-
Notifications
You must be signed in to change notification settings - Fork 0
/
cas.tex
422 lines (414 loc) · 13.6 KB
/
cas.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
% Chapter 1, Topic from _Linear Algebra_ Jim Hefferon
% http://joshua.smcvt.edu/linalg.html
% 2001-Jun-09
\topic{Computer Algebra Systems}
\index{computer algebra systems|(}
The linear systems in this chapter are small enough that their
solution by hand is easy.
For large systems, including those involving thousands of equations,
we need a computer.
There are special purpose programs such as LINPACK\index{LINPACK} for this.
Also popular are general purpose computer algebra systems
including \Maple,\index{Maple}
\textit{Mathematica},\index{Mathematica} or \textit{MATLAB},\index{MATLAB}
and \Sage\index{Sage}.
For example, in the Topic on Networks, we need to solve this.
\begin{equation*}
\begin{linsys}{7}
i_0 &- &i_1 &- &i_2 & & & & & & & & &= &0 \\
& &i_1 & & &- &i_3 & & &- &i_5 & & &= &0 \\
& & & &i_2 & & &- &i_4 &+ &i_5 & & &= &0 \\
& & & & & &i_3 &+ &i_4 & & &- &i_6 &= &0 \\
& &5i_1 & & &+ &10i_3 & & & & & & &= &10 \\
& & & &2i_2 & & &+ &4i_4 & & & & &= &10 \\
& &5i_1 &- &2i_2 & & & & &+ &50i_5 && &= &0
\end{linsys}
\end{equation*}
Doing this by hand would take time and be error-prone.
A computer is better.
Here is that system solved with \textit{Sage}.
(There are many ways to do this; the one here has the advantage of simplicity.)
\begin{lstlisting}
sage: var('i0,i1,i2,i3,i4,i5,i6')
(i0, i1, i2, i3, i4, i5, i6)
sage: network_system=[i0-i1-i2==0, i1-i3-i5==0,
....: i2-i4+i5==0, i3+i4-i6==0, 5*i1+10*i3==10,
....: 2*i2+4*i4==10, 5*i1-2*i2+50*i5==0]
sage: solve(network_system, i0,i1,i2,i3,i4,i5,i6)
[[i0 == (7/3), i1 == (2/3), i2 == (5/3), i3 == (2/3),
i4 == (5/3), i5 == 0, i6 == (7/3)]]
\end{lstlisting}
Magic.
Here is the same system solved under Maple.
We enter the array of coefficients
and the vector of constants,
and then we get the solution.
\begin{lstlisting}
> A:=array( [[1,-1,-1,0,0,0,0],
[0,1,0,-1,0,-1,0],
[0,0,1,0,-1,1,0],
[0,0,0,1,1,0,-1],
[0,5,0,10,0,0,0],
[0,0,2,0,4,0,0],
[0,5,-2,0,0,50,0]] );
> u:=array( [0,0,0,0,10,10,0] );
> linsolve(A,u);
7 2 5 2 5 7
[ -, -, -, -, -, 0, - ]
3 3 3 3 3 3
\end{lstlisting}
If a system has infinitely many solutions then
the program will return a parametrization.
\begin{exercises}
\item
Use the computer to solve the two problems that opened this
chapter.
\begin{exparts}
\partsitem This is the Statics problem.
\begin{align*}
40h+15c &= 100 \\
25c &= 50+50h
\end{align*}
\partsitem This is the Chemistry problem.
\begin{align*}
7h &= 7j \\
8h +1i &= 5j+2k \\
1i &= 3j \\
3i &= 6j+1k
\end{align*}
\end{exparts}
\begin{answer}
\begin{exparts}
\partsitem
\Sage{} does this.
\begin{lstlisting}
sage: var('h,c')
(h, c)
sage: statics = [40*h + 15*c == 100,
....: 25*c == 50 + 50*h]
sage: solve(statics, h,c)
[[h == 1, c == 4]]
\end{lstlisting}
Other Computer Algebra Systems have similar commands.
These \Maple{} commands
\begin{lstlisting}
> A:=array( [[40,15],
[-50,25]] );
> u:=array([100,50]);
> linsolve(A,u);
\end{lstlisting}
get the answer \lstinline![1,4]!.
\partsitem Here there is a free variable.
\Sage{} gives this.
\begin{lstlisting}
sage: var('h,i,j,k')
(h, i, j, k)
sage: chemistry = [7*h == 7*j,
....: 8*h + 1*i == 5*j + 2*k,
....: 1*i == 3*j,
....: 3*i == 6*j + 1*k]
sage: solve(chemistry, h,i,j,k)
[[h == 1/3*r1, i == r1, j == 1/3*r1, k == r1]]
\end{lstlisting}
Similarly, this \Maple{} session
\begin{lstlisting}
> A:=array( [[7,0,-7,0],
[8,1,-5,2],
[0,1,-3,0],
[0,3,-6,-1]] );
> u:=array([0,0,0,0]);
> linsolve(A,u);
\end{lstlisting}
prompts the same reply (but with parameter $t_1$).
\end{exparts}
\end{answer}
\item
Use the computer to solve these systems from the
first subsection,
or conclude `many solutions' or `no solutions'.
\begin{exparts*}
\partsitem \(
\begin{linsys}[t]{2}
2x &+ &2y &= &5 \\
x &- &4y &= &0
\end{linsys}
\)
\partsitem \(
\begin{linsys}[t]{2}
-x &+ &y &= &1 \\
x &+ &y &= &2
\end{linsys}
\)
\partsitem \(
\begin{linsys}[t]{3}
x &- &3y &+ &z &= &1 \\
x &+ &y &+ &2z &= &14
\end{linsys}
\)
\partsitem \(
\begin{linsys}[t]{2}
-x &- &y &= &1 \\
-3x &- &3y &= &2
\end{linsys}
\)
\partsitem \(
\begin{linsys}[t]{3}
& &4y &+ &z &= &20 \\
2x &- &2y &+ &z &= &0 \\
x & & &+ &z &= &5 \\
x &+ &y &- &z &= &10
\end{linsys}
\)
\partsitem \( \begin{linsys}[t]{4}
2x & & &+ &z &+ &w &= &5 \\
& &y & & &- &w &= &-1 \\
3x & & &- &z &- &w &= &0 \\
4x &+ &y &+ &2z &+ &w &= &9
\end{linsys}
\)
\end{exparts*}
\begin{answer}
\begin{exparts}
\partsitem The answer is \( x=2 \) and \( y=1/2 \).
A \Sage{} session does this.
\begin{lstlisting}
sage: var('x,y')
(x, y)
sage: system = [2*x + 2*y == 5,
....: x - 4*y == 0]
sage: solve(system, x,y)
[[x == 2, y == (1/2)]]
\end{lstlisting}
A \Maple{} session
\begin{lstlisting}
> A:=array( [[2,2],
[1,-4]] );
> u:=array([5,0]);
> linsolve(A,u);
\end{lstlisting}
gets the same answer, of course.
\partsitem The answer is \( x=1/2 \) and \( y=3/2 \).
\begin{lstlisting}
sage: var('x,y')
(x, y)
sage: system = [-1*x + y == 1,
....: x + y == 2]
sage: solve(system, x,y)
[[x == (1/2), y == (3/2)]]
\end{lstlisting}
\partsitem This system has infinitely many solutions.
In the first subsection, with $z$ as a parameter,
we got $x=(43-7z)/4$ and $y=(13-z)/4$.
\Sage{} gets the same.
\begin{lstlisting}
sage: var('x,y,z')
(x, y, z)
sage: system = [x - 3*y + z == 1,
....: x + y + 2*z == 14]
sage: solve(system, x,y)
[[x == -7/4*z + 43/4, y == -1/4*z + 13/4]]
\end{lstlisting}
\Maple{} responds with $(-12+7t_1, t_1, 13-4t_1)$,
preferring $y$ as a parameter.
\partsitem There is no solution to this system.
\Sage{} gives an empty list.
\begin{lstlisting}
sage: var('x,y')
(x, y)
sage: system = [-1*x - y == 1,
....: -3*x - 3*y == 2]
sage: solve(system, x,y)
[]
\end{lstlisting}
Similarly,
When the array $A$ and vector $u$ are given to \Maple{}
and it is asked to \lstinline!linsolve(A,u)!,
it returns no result at all; that is, it responds with
no solutions.
\partsitem \Sage{} finds
\begin{lstlisting}
sage: var('x,y,z')
(x, y, z)
sage: system = [ 4*y + z == 20,
....: 2*x - 2*y + z == 0,
....: x + z == 5,
....: x + y - z == 10]
sage: solve(system, x,y,z)
[[x == 5, y == 5, z == 0]]
\end{lstlisting}
that the solutions is \( (x,y,z)=(5,5,0) \).
\partsitem There are infinitely many solutions.
\Sage{} does this.
\begin{lstlisting}
sage: var('x,y,z,w')
(x, y, z, w)
sage: system = [ 2*x + z + w == 5,
....: y - w == -1,
....: 3*x - z - w == 0,
....: 4*x + y + 2*z + w == 9]
sage: solve(system, x,y,z,w)
[[x == 1, y == r2 - 1, z == -r2 + 3, w == r2]]
\end{lstlisting}
\Maple{} gives $(1, -1+t_1, 3-t_1, t_1)$.
\end{exparts}
\end{answer}
\item
Use the computer to solve these systems from the second subsection.
\begin{exparts*}
\partsitem \( \begin{linsys}[t]{2}
3x &+ &6y &= &18 \\
x &+ &2y &= &6
\end{linsys} \)
\partsitem \( \begin{linsys}[t]{2}
x &+ &y &= &1 \\
x &- &y &= &-1
\end{linsys} \)
\partsitem \( \begin{linsys}[t]{3}
x_1 & & &+ &x_3 &= &4 \\
x_1 &- &x_2 &+ &2x_3 &= &5 \\
4x_1 &- &x_2 &+ &5x_3 &= &17
\end{linsys} \)
\partsitem \( \begin{linsys}[t]{3}
2a &+ &b &- &c &= &2 \\
2a & & &+ &c &= &3 \\
a &- &b & & &= &0
\end{linsys} \)
\partsitem \( \begin{linsys}[t]{4}
x &+ &2y &- &z & & &= &3 \\
2x &+ &y & & &+ &w &= &4 \\
x &- &y &+ &z &+ &w &= &1
\end{linsys} \)
\partsitem \( \begin{linsys}[t]{4}
x & & &+ &z &+ &w &= &4 \\
2x &+ &y & & &- &w &= &2 \\
3x &+ &y &+ &z & & &= &7
\end{linsys} \)
\end{exparts*}
\begin{answer}
\begin{exparts}
\partsitem This system has infinitely many solutions.
In the second subsection we gave the solution set as
\begin{equation*}
\set{\colvec{6 \\ 0}+\colvec{-2 \\ 1}y
\suchthat y\in\Re}
\end{equation*}
and \Sage{} finds
\begin{lstlisting}
sage: var('x,y')
(x, y)
sage: system = [ 3*x + 6*y == 18,
....: x + 2*y == 6]
sage: solve(system, x,y)
[[x == -2*r3 + 6, y == r3]]
\end{lstlisting}
while \Maple{} responds with $(6-2t_1,t_1)$.
\partsitem The solution set has only one member.
\begin{equation*}
\set{\colvec{0 \\ 1} }
\end{equation*}
\Sage{} gives this.
\begin{lstlisting}
sage: var('x,y')
(x, y)
sage: system = [ x + y == 1,
....: x - y == -1]
sage: solve(system, x,y)
[[x == 0, y == 1]]
\end{lstlisting}
\partsitem This system's solution set is infinite
\begin{equation*}
\set{\colvec{4 \\ -1 \\ 0}+\colvec{-1 \\ 1 \\ 1}x_3
\suchthat x_3\in\Re}
\end{equation*}
\Sage{} gives this
\begin{lstlisting}
sage: var('x1,x2,x3')
(x1, x2, x3)
sage: system = [ x1 + x3 == 4,
....: x1 - x2 + 2*x3 == 5,
....: 4*x1 - x2 + 5*x3 == 17]
sage: solve(system, x1,x2,x3)
[[x1 == -r4 + 4, x2 == r4 - 1, x3 == r4]]
\end{lstlisting}
and Maple gives $(t_1,-t_1+3,-t_1+4)$.
\partsitem There is a unique solution
\begin{equation*}
\set{\colvec{1 \\ 1 \\ 1}}
\end{equation*}
and \Sage{} finds it.
\begin{lstlisting}
sage: var('a,b,c')
(a, b, c)
sage: system = [ 2*a + b - c == 2,
....: 2*a + c == 3,
....: a - b == 0]
sage: solve(system, a,b,c)
[[a == 1, b == 1, c == 1]]
\end{lstlisting}
\partsitem This system has infinitely many solutions; in the
second subsection we described the solution set with
two parameters.
\begin{equation*}
\set{\colvec{5/3 \\ 2/3 \\ 0 \\ 0}
+\colvec{-1/3 \\ 2/3 \\ 1 \\ 0}z
+\colvec{-2/3 \\ 1/3 \\ 0 \\ 1}w
\suchthat z,w\in\Re}
\end{equation*}
\Sage{} does the same.
\begin{lstlisting}
sage: var('x,y,z,w')
(x, y, z, w)
sage: system = [ x + 2*y - z == 3,
....: 2*x + y + w == 4,
....: x - y + z + w == 1]
sage: solve(system, x,y,z,w)
[[x == r6, y == -r5 - 2*r6 + 4, z == -2*r5 - 3*r6 + 5, w == r5]]
\end{lstlisting}
as does \Maple{} $(3-2t_1+t_2,t_1,t_2,-2+3t_1-2t_2)$.
\partsitem The solution set is empty.
\begin{lstlisting}
sage: var('x,y,z,w')
(x, y, z, w)
sage: system = [ x + z + w == 4,
....: 2*x + y - w == 2,
....: 3*x + y + z == 7]
sage: solve(system, x,y,z,w)
[]
\end{lstlisting}
\end{exparts}
\end{answer}
\item
What does the computer give for the solution of the general
$\nbyn{2}$ system?
\begin{equation*}
\begin{linsys}{2}
ax &+ &cy &= &p \\
bx &+ &dy &= &q
\end{linsys}
\end{equation*}
\begin{answer}
\Sage{} does this.
\begin{lstlisting}
sage: var('x,y,a,b,c,d,p,q')
(x, y, a, b, c, d, p, q)
sage: system = [ a*x + c*y == p,
....: b*x + d*y == q]
sage: solve(system, x,y)
[[x == -(d*p - c*q)/(b*c - a*d), y == (b*p - a*q)/(b*c - a*d)]]
\end{lstlisting}
In response to this prompting
\begin{lstlisting}
> A:=array( [[a,c],
[b,d]] );
> u:=array([p,q]);
> linsolve(A,u);
\end{lstlisting}
\Maple{} gave this reply.
\begin{equation*}
\bigl[-\frac{-d\,p+q\,c}{-b\,c+a\,d},
\frac{-b\,p+a\,q}{-b\,c+a\,d}\bigr]
\end{equation*}
\end{answer}
\end{exercises}
\index{computer algebra systems|)}
\endinput