Section 7.1 Motivation for solving equations numerically
We often want to solve an equation of the form f(x)=0, given a real-valued function f of one real variable x. Some such equations admit a symbolic solution, obtained by some algebraic manipulations. For example, the equation 2exβ3=0 has the solution x=log(3/2). But if we put together two or more unrelated functions, for example 2ex+x3β1=0, algebra does not help.
For this reason, Matlab has a built-in root-finding function fzero
. Its first argument is the function which should be equated to zero, the second argument is our initial guess at where the solution may be (put 0 if you have no idea). For example,
fzero(@(x) 2*exp(x) + x^3 - 1, 0)
finds the solution -0.5439
. But even though we have fzero
, we still have to understand the methods used for finding roots, because
-
fzero
only gives one solution, there may be others;
- the output of
fzero
may be wrong.
An example of wrong answer:
fzero(@(x) exp(-x^2), 0)
returns x=-28.9631
. In reality, eβx2=0 has no solutions, and there is nothing special about the number produced by fzero
: this is just where its algorithm decided to stop, thinking βclose enoughβ.