Sei sulla pagina 1di 42

Utilizing MS EXCEL Solver

in Solving
Simultaneous Equations

Syamsul Rizal Abd Shukor


PhD, AMIChemE
Review: Linear Equations in Matrix Form

The first step in using matrix methods to solve a


series of linear simultaneous equations is to write
them in matrix form
For n simultaneous equations and n unknowns:

where A is the coefficient matrix (n n); X is the matrix of


unknowns (n 1), and C is the constant matrix (n 1)
Review: Linear Simultaneous Equations

Recall that if there are more unknowns then


equations, then we cannot find a unique solution
If there are more equations than unknowns, then
some equations must be redundant
If there are exactly the same number of equations
and unknowns, then there may be a unique
solution. In this case the coefficient matrix will be
square
Solution of System of Linear Equations

We can find the unknown variables by multiplying


the inverse of the coefficient matrix by the
constant matrix
Summary Linear Equations

If the inverse of the coefficient matrix exists, then


there is a solution, and that solution is unique
If the inverse does not exist, then there are two
possibilities:
The equations are incompatible, and so there are no
solutions, or
At least two of the equations are redundant, and so
there are more unknowns than unique equations.
Therefore, there are an infinite number of solutions
Non-Linear Equations

If any of the equations are non-linear, then the


matrix method will not work
Example: Consider these two equations:

The x2 term in the first equation prevents the use


of a matrix solution
Excel Solver

Solver is an Excel Add-In that can find solutions to


many problems with multiple independent
variables
The first step is to check that Solver is installed
If so, it will appear in the Data group of the ribbon:
Installing Solver

If Solver is not present on


the ribbon, start by
clicking the Office
Button

And selecting Excel


Options
Installing Solver

Choose Add-Ins

And click Go beside


Excel Add-Ins
Installing Solver

Check Solver and click OK

If Solver has not been installed, click Yes to install


it now
Using Solver

Solver attempts to set the value of a target cell to


its minimum, its maximum, or a specific value,
By changing one or more input cells (independent
variables,
While maintaining specified constraints (optional)
Solver Example

Consider this equation:

Use Solver to find values of x for which


y is minimized
y is equal to exactly 50
y is maximized, within limits of x from 0 to 10
Solver Example

To better understand this problem, consider this


plot of y vs. x:
200

180
On your own,
160
y create the plot
140
as shown here
120

100

80

60

40

20

0
-10 -5 0 5 10 15
x
Solver Example

Label a cell for the independent variable x and


enter the formula for y in another cell:
Solver Example

Start Solver. For the first part of the problem we


want to minimize y (Target Cell C4) by changing x
(cell C2):
Solver Example

Start Solver. For the first part of the problem we


want to minimize y (Target Cell C4) by changing x
(cell C2):
Solver Example

The answer is that when x = 2, y = 16, the


minimum value of y that is possible:
200

180

160
y
140

120

100

80

60

40

20

0
-10 -5 0 5 10 15
x
Solver Example

Next, find the value of x for which y = 80:


Solver Example

But we can see from the


graph that there are two
solutions to the problem 200

This is typical for non- 180

160
y
linear problems; multiple 140

solutions are possible


120

100

The solution found often


80

60

depend on the initial 40

20

guess entered before 0


-10 -5 0 5 10 15

running Solver
x
Solver Example

Try x = -10 as the initial guess and run Solver


again:
Solver Example

Now try to maximize y:


Solver Example

Since the value of y increase to infinity for both


increasing and decreasing values of x, there are no
maxima values to be found
However, we can constrain the problem by requiring
the input value of x to be between 0 and 10:
Solver Example
200

180

160
y
140

Allowable x-values
120

100

80

60

40

20

0
-5 0 5 10 15
x
Solver Example

We find that when x = 10, y = 80. This is the


maximum value that y can have, subject to the
constraints on x.
Solver Example

However, even this


solution is affected by
the initial guess. For
example, if we try x =
-10 as the initial value:

Then we get a different


solution, although the
value of y is clearly not
maximized:
Solver Example

It is important to realize that Solver finds local


maximum and minimum values
200

180

160 Allowable
y
140 x-values
120

100

80

60

40

20

0
-5 0 5 10 15
x
Simultaneous Equation Example

Back to our earlier example - consider these two


equations:

Can we find values of x and y that satisfy both


equations?
Simultaneous Equation Example

With non-linear simultaneous equations, the first step


is to write the equations with all of the variables and
constants on the same side of the equal sign
We give the resulting expressions variable names (f1
and f2 here):

When both f1 and f2 are zero, then the equations are


satisfied
Simultaneous Equation Example

Start by labeling two cells for the input variables (x


and y)
Label two cells for f1 and f2, and enter their
formulas:
Simultaneous Equation Example

Remember that Solver must have a single target


cell: we cannot specify that both f1 and f2 are to be
zero
We could specify that the sum of f1 and f2 be zero;
however, this would not guarantee that both are
zero as one could be positive and the other
negative
If we square both values, then both these values
must be greater than or equal to zero
If the sum of the squares equals zero, then both f1
and f2 must be zero
Simultaneous Equation Example

Add cells for the squares and their sum. The sum
(cell E7) will be the Target Cell in the Solver setup:
Simultaneous Equation Example
Simultaneous Equation Example

Solver has found a


solution: x is about
-1 and y is about 0
Simultaneous Equation Example

These are the exact values for the solution:


Simultaneous Equation Example

Try different guess values of x and y:


Simultaneous Equation Example

A second solution if found: x = 1.5 and y = 12.5


Simultaneous Equation Example

A graphical solution is possible with two


equations. Notice that the curves intersect in two
places 80

60 Equation 1
y Equation 2
40

20

-20

-40
-5 -4 -3 -2 -1 0 1 2 3 4 5
x
Simultaneous Equation Example

Zooming in, we can see the solutions that we found


with Solver 20

15 Equation 1
y Equation 2
10

-5

-10
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x
Simultaneous Equation Example

Now try these equations (only the second is


changed)
Simultaneous Equation Example

In this case, no solution can be found


Simultaneous Equation Example

Graphing the equations shows that they do not


intersect
20

15
Equation 1
y Equation 2
10

-5

-10

-15
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x
Summary

Excel Solver can be used to numerically find


maxima, minima, and specific values of a target
cell by varying one or more input cells, with or
without additional constraints
Solver can also find solutions of simultaneous non-
linear equations
Important to recognize that multiple solutions
may exist for non-linear problems

Potrebbero piacerti anche