Matlab/Mathematica Help Solving Linear and Non-Linear Sytems of Equations
Matlab/Mathematica Help Solving Linear and Non-Linear Sytems of Equations
Matlab/Mathematica Help Solving Linear and Non-Linear Sytems of Equations
1x + 2 y + 3 z = 2
5x + 8 y + 9 z = 1
3 x + 2 y + 1z = 5
1 2 3 x 2
5 8 9 y = 1
3 2 1 z 5
So in Matlab, first define matrix A and vector b:
A\b
You'll get one of three things. Either you'll get an answer, or you'll get:
Other helpful hints about solving linear systems include using Matlab's "rref" command. Try this out.
1x 2 + 2 y = 0
5x + 8 y = 1
To get Matlab to solve this, you'd type:
[x,y]=solve('x^2+2*y=0','5*x+8*y=1','x,y')
The output would be:
x=
[ 1]
[ 1/4]
y=
[ -1/2]
[ -1/32]
which represents two simultaneous solutions: (x, y)=(1,-1/2) and (x, y)=(1/4, -1/32).
One special note about using the solve command in Matlab, the answers are always given in lexicographic order so
if you typed
[y,x]=solve('x^2+2*y=0','5*x+8*y=1','x,y')
or even
[y,x]=solve('x^2+2*y=0','5*x+8*y=1','y,x')
you'd get the solutions backwards for x and y since x is clearly ordered before y in the alphabet.
1x + 2 y + 3 z = 2
5x + 8 y + 9 z = 1
3 x + 2 y + 1z = 5
1 2 3 x 2
5 8 9 y = 1
3 2 1 z 5
So in Mathematica, first define matrix A and vector b:
MatrixForm[A]
MatrixForm[b]
To use Gauss Jordan Row Reduction algorithms, you'll need to load the appropriate package by typing:
<<`LinearAlgebra`GaussianElimination`
Now, those aren't normal apostrophes. They are backwards apostrophes, found on the tilde key on the upper left
part of your keyboard. It took me a week to figure that out the first I used Mathematica. ARGH! J Once you've
loaded the package, you can use the command "LinearSolve".
LinearSolve[A,b]
Mathematica and Linear/Non-Linear Systems (Method 2)
Mathematica also has a "solve"command that can be used to solve systems of equations whether they are linear or
not. Consider the non-linear system below:
1x 2 + 2 y = 0
5x + 8 y = 1
To get Mathematica to solve this, you'd type:
Solve[{x^2+2*y==0,5*x+8*y==1},{x,y}]
The output would be:
99y -
1
1
1
, x 1=, 9y , x ==
2
32
4
which represents two simultaneous solutions: (x, y)=(1,-1/2) and (x, y)=(1/4, -1/32).