Download Solving simultaneous equations

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Eigenvalues and eigenvectors wikipedia , lookup

Computational fluid dynamics wikipedia , lookup

Routhian mechanics wikipedia , lookup

Mathematical descriptions of the electromagnetic field wikipedia , lookup

Multiple-criteria decision analysis wikipedia , lookup

Inverse problem wikipedia , lookup

Linear algebra wikipedia , lookup

Bra–ket notation wikipedia , lookup

Four-vector wikipedia , lookup

Computational electromagnetics wikipedia , lookup

Transcript
Using Mathematica for linear algebra
Solving simultaneous equations
Mathematica will solve simulataneous equations for us, e.g.
(Note that one must use == in the relations, not =)
Solve@82 x + 5 y - z Š 2, x + y + 2 z Š 1, x + 5 z Š 3<, 8x, y, z<D
::x ® -
9
5
,y®
2
3
,z®
2
2
>>
This is how Mathematica deals with a case without a solution:
it gives an empty solution vector.
Solve@8x + y Š 2, x + y Š 5<, 8x, y<D
8<
Here’s what happens if the equations have an infinite number of solutions:
Solve@8x + y Š 2, 2 x + 2 y Š 4<, 8x, y<D
Solve::svars : Equations may not give solutions for all "solve" variables. ‡
88y ® 2 - x<<
We can also solve our original problem using the augmented matrix
eeaug = 882, 5, - 1, 2<, 81, 1, 2, 1<, 81, 0, 5, 3<<; eeaug  MatrixForm
2 5 -1 2
1 1 2 1
1 0 5 3
We ask Mathematica to “row reduce” the augmented matrix (see Boas 3.2) and can read off the answer
RowReduce@eeaugD  MatrixForm
9
1 0 0 -2
0 1 0
0 0 1
5
2
3
2
Finally, we can solve by writing the problem in matrix form, E r=D, with E and D as follows.
ee = 882, 5, - 1<, 81, 1, 2<, 81, 0, 5<<; ff = 82, 1, 3<;
MatrixForm@eeD
2 5 -1
1 1 2
1 0 5
MatrixForm@ffD
2
1
3
Here's the solution:
2
Linear1.nb
rr = [email protected]
:-
9
5
,
2
3
,
2
2
>
Vectors & operations
Vectors are entered in row form:
v1 = 81, - 1, 3<
81, - 1, 3<
v2 = 83, 1, 2<
83, 1, 2<
Dot product:
Dot@v1, v2D
8
It can also be written as just a Dot:
v1.v2
8
Cross product:
v1cr2 = Cross@v1, v2D
8- 5, 7, 4<
is antisymmetric, as it should be,
Cross@v2, v1D
85, - 7, - 4<
and is orthogonal to v1 and v2:
8Dot@v1cr2, v1D, Dot@v1cr2, v2D<
80, 0<
You can pick out individual components of a vector as follows:
(Note the double square parentheses.)
v1@@2DD
-1
Complex vectors
v3 = 81 + I, 2, - 3 I<; v4 = 86 + I, - 3 I, 4<;
To get the complex inner product, need to explicitly put in the complex conjugation:
Linear1.nb
[email protected]
7+ä
Reversing order gives complex conjugate:
[email protected]
7-ä
The norm or length of v3 is
Sqrt@[email protected]
15
Mathematica has a built in Norm function (which takes lots of types of argument), but in this case gives
the standard norm:
Norm@v3D
15
Cross product works for complex vectors too:
Cross@v3, v4D
817, - 1 - 22 ä, - 9 - 5 ä<
Matrices
Functions of Matrices
Eigenvalues and Eigenvectors
3