20.04.2015 Views

The Resource Magazine For Apple, Atari, and Commodore ...

The Resource Magazine For Apple, Atari, and Commodore ...

The Resource Magazine For Apple, Atari, and Commodore ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

32 COMPUTE! September/October, 198O. Issue 6<br />

Solving<br />

Equations With<br />

A Computer<br />

Marvin L De Jong<br />

Department of Mathematics-Physics<br />

<strong>The</strong> School of the Ozarks<br />

Pt. Lookout, MO 65726<br />

INTRODUCTION<br />

<strong>The</strong>re is a large body of knowledge, known as<br />

"Numerical Analysis," that is used to solve pro<br />

blems that would be either loo difficult or too ineffi<br />

cient to solve with either h<strong>and</strong> calculations or an<br />

electronic calculator. <strong>The</strong> problems generally attack<br />

ed with numerical analysis techniques require either<br />

a computer or a programmable electronic calculator.<br />

<strong>The</strong> purpose of this article is to show how a few<br />

techniques from numerical analysis can be used to<br />

solve difficult equations. <strong>The</strong>se techniques do not re<br />

quire any extraordinary mathematical skills; a first<br />

course in high-school algebra will suffice.<br />

To begin, we will assume you can solve equations<br />

of the type,<br />

2x + 5 = -3 (1)<br />

This type of equation is solved using the rules:<br />

RULE (1) <strong>The</strong> same number (or algebraic expression)<br />

can be added or subtracted from both sides of an<br />

equation.<br />

RULE (2) Both sides of an equation can be multi<br />

plied or divided by any non-zero number (or algebraic<br />

expression).<br />

Thus, in Equation (1), we would first subtract<br />

five from both sides of the equation <strong>and</strong> next both<br />

sides of the equation would be divided by two, giving<br />

x = -4 as the answer. Any equation of the form<br />

Ax + B = C (2)<br />

has a solution x = (C - B)/A, which is very easy<br />

to program in BASIC or FORTRAN. <strong>The</strong> program<br />

in Listing 1 does this.Listing t program to solve a<br />

linear equation.<br />

10 INPUT A. B, C<br />

20 X = (C - B)/A<br />

30 PRINT X<br />

40 END<br />

Clearly in this case the problem could just as well<br />

have been done with pencil <strong>and</strong> paper. We are inter<br />

ested in more difficult problems, but RULES (1)<br />

<strong>and</strong> (2) above describe how equations may be modified<br />

to get the unknown "x" by itself on one side of the<br />

equation, <strong>and</strong> we will need these rules in what follows.<br />

To these rules we add a third, namely<br />

RULE (3) In certain cases both sides of an<br />

equation may be operated on by the same function<br />

<strong>and</strong> the results arc still equal.<br />

To illustrate, if x^ = 9, then we may operate on<br />

both sides of this equation with the square root func<br />

tion (SQR in BASIC) to get x = 3. Note that this<br />

technique misses the answer x = -3, but it illustrated<br />

the fact that taking the square root of both sides of<br />

an equation (usually) yields a valid result. Likewise,<br />

one can lake the logarithm (LOG in BASIC) of both<br />

sides of an equation provided we arc dealing with<br />

positive numbers, <strong>and</strong> we can take the exponential<br />

function (EXP in BASIC) of both sides of an equa<br />

tion, using RULE (3).<br />

<strong>The</strong> type of equations that are of interest in the<br />

present context can best be illustrated by some ex<br />

amples. How would you solve for X in the following<br />

equations:<br />

x^ = cos(x) (3)<br />

ex - 4x = 0 (4)<br />

log(x) - cos(x) = 0 (5)<br />

<strong>The</strong>se so-called non-linear equations cannot be<br />

solved by a simple application of the rules given so<br />

far. In fact, you may be disappointed to know that<br />

no single technique will solve all possible non-linear<br />

equations. Many people like mathematics because it<br />

seems to follow simple, hard-<strong>and</strong>-fast rules that lead<br />

to answers that are either right or wrong. On the<br />

contrary, mathematics requires creativity <strong>and</strong> the<br />

ability to view a problem from many angles. Further<br />

more, more often than not, the answers are only ap<br />

proximately correct rather than absolutely correct. In<br />

any case, let us examine two techniques that may be<br />

used to solve these difficult looking equations.<br />

<strong>The</strong> Method Of Successive Substitutions<br />

<strong>The</strong> method of successive substitutions is one of the<br />

Simplest techniques used to solve these equations. It<br />

comes with no guarantee that it will work, but because<br />

it is simple it is frequently worth trying.<br />

<strong>The</strong> first step is to take the equation to be solved<br />

<strong>and</strong> using the three rules given in the Introduction.<br />

put the equation in a form with x on the left-h<strong>and</strong><br />

side <strong>and</strong> everything else on the right-h<strong>and</strong> side of the<br />

equation. <strong>For</strong> example, the equation x^ = cos(x),<br />

Equation (3) above, becomes either x = (cos(x))/x or<br />

x = V eos (x). It is typical to find several possible<br />

forms. This step is usually described in textbooks by<br />

telling you to put your equation in the form<br />

x = f(x) (6)<br />

In our example, f(x) is either cos(x)/x or \Jc'os(x)<br />

depending on whether we arc using x = (cos(x))/x or<br />

x = Ncos(x). In any case, the equation is modified<br />

so that x is all by itself on one side of the equation<br />

<strong>and</strong> everything else is on the other side.<br />

<strong>The</strong> second step is to guess at a value of x that<br />

will satisfy the equation. This is an important step

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!