If there is no command 2, the else can
be omitted.
WHILE….ENDwhile abs(r_old-r_new)
> tol
r_old=r_new;
r_new=0.5*(r_old
+ x/r_new)
end
command 4
|
You can skip Section 3.5 and most of Section 3.6. However, don’t miss the feval function described in NMM 3.6.3, which allows you to pass function names as inputs; you will need that for some of the programming assignments.
Once you start using logic and loops in your programs, you will certainly introduce bugs. If you are not careful, you could spend many hours this semester trying to root out the bugs you introduced. Chapter 4 is full of good suggestions about how to write your programs to reduce the likelihood of introducing bugs, and of methods for identifying the bugs you will inevitably introduce. Modularization really helps with debugging: it is much easier to correctly write and debug a short m-file than it is to debug a long m-file. To benefit from this advantage, you must carefully test and debug each little m-file separately, before you call it from other functions.
When you get to the stage in your life when you are considering writing a really long computer program, we strongly recommend that you read the book Code Complete before you begin. But Chapter 4 of NMM will suffice for 10.10.