Calculus Computer Lab
Math 242L


News

Lab Schedule

Tutor Room

Newton's Method: a Java Demo

Derive Basics

Derive Information

Welcome

xxxxxxxxxxxxxxxxxxxxx

New Utility Functions

Download Utilitity Files

In the manual several functions are defined such TL(a) which computes the tangent line of a predefined function f(x) at the point x = a. In Chapter 5 and later there will be many more such functions which will approximates roots, integrals and solutions to differential equations.  To make it easier to compute with these function we have added a utility file add-util.mth with all the functions defined.  The way this utility file works is that you simply use the  File/Load/Utility menu and select the file add-util.mth.   DfW then loads the file "quietly" meaning that just the definitions are entered and nothing is displayed.  The file just takes a second or two to load in quiet mode.  To make this process easier we suggest having every lab file start out with the add-head.mth at the top and then add your name and lab number in double quotes.  See the sample session below where the first four lines are obtained by loading the add-head.mth file, then the file is renamed using the File/Save As menu as LAB1.MTH.

f-lab1.gif (9355 bytes)

We have changed the names and the way these function work by eliminating the need to predefine a function f(x).  For example, if you want to compute a tangent line for say f(x)=x3/3 at x=1 you would Author and Simplify:

TANGENT(x^3/3, x, 1)

The result will be y = x - 2/3.  . We describe the variables for this and the other functions typically as

TANGENT( u, x, a)

where the u refers to any expression in the variable x and a is a parameter in the function.

Example 1.  Let's solve the equation x2 + x - 1 = 0 using the Newton method of Chapter 5.  We'll use x0 = 5 as our initial guess.  We obtain our first approximation by Authoring i-author.bmp (1340 bytes) NEWT( x^2+x-1, x, 5) and then Simplifying i-simp.bmp (1300 bytes) to get 2.63263.  We repeat this process using this new value as our starting point.  After 4-5 iterations we obtain an approximation we good to 6 decimal places.

Example 2.  Suppose that you want to find the quadratic polynomial ax2 + bx + c that passes through the three points: (0,0), (1,2) and (2,8).  You load the utility file add-util.mth and then Author CURVEFIT( x, [[0,1], [1,2], [2,8]]).  After simplifying the result will be 2x2.  Probably the best way to do this is to start by defining the 3x2 matrix of points using the matrix button i-matrix.bmp (1468 bytes) and then plotting i-plot.bmp (1372 bytes) the 3 points on a graph.   Next you Author i-author.bmp (1340 bytes) the CURVEFIT( x, part and then right click and insert the matrix of data points.  Simplify i-simp.bmp (1300 bytes) and plot to make sure the answer function does indeed pass through the 3 data points.  The CURVEFIT function will find the appropriate degree polynomial through the data regardless of the number of points.

Example 3.  Suppose that you want to find the quadratic polynomial ax2 + bx + c that passes through the two points: (0,0) and (1,2).  In addition, you want the derivative to be 1 when x=0.  You load the utility file add-util.mth and then Author CURVEFIT( x, [[0,1], [1,2]], [[0,1]]).  In other words, you enter one matrix for the points satisfied by the function and another matrix for the points satisfied by the derivative.  The degree of the answer polynomial is always one less than the total number of equations for both the function and its derivative.

Example 4.  To approximate the solution to the equation u = 0, where u is an expression in x, using the Newton method with initial guess a you author and approximate NEWT(u, x, a).  Suppose instead that you want the first k approximates starting with x = a, then you approximate NEWT(u, x, a, k).  The 4th argument is optional.  You get a nice picture of the Newton method in action by approximating DRAW_NEWT(u, x, a, k) and then plotting i-plot.bmp (1372 bytes) the result.  Notice that the starting point can be a complex number in which case the approximates are also complex.  The function DRAW_COMPLEX(v) can be applied to the solution vector to get a matrix of [x,y] points which can then be plotted in a 2D-plot window.

Example 5.  Suppose you want to approximate the integral which defines the natural logarithm of 2 using say the Simpson Rule for numerical integration.  This means that we need to approximate the integral of 1/x over the interval [1,2].  We do this by Authoring i-author.bmp (1340 bytes) the expression SIMP( 1/x, x, 1, 2).  Now since we are interested in a decimal approximation we use the i-approx.bmp (1348 bytes) button to simplify the expression.


Complete List of Functions:

SUBST(u,x,a) Substitutes x=a in the expression u.
SECANT(u,x,a,h) Secant line of u(x) through x = a and x = a + h.
TANGENT(u,x,a) Tangent line of u(x) at x = a.
CURVEFIT(x,data,ddata) Fits a polynomial in the variable x, though the points data:=[[x0,y0],[x1,y1],...] provided ddata is either omitted or []. Otherwise, the graph of the derivative must pass through the ddata points.
NEWT(u,x,x0) Newton algorithm for root of u(x)=0 with initial guess x0. If the optional k argument is used then a vector of k iterates is returned.
DRAW_NEWT(u,x,x0,k) Draws a picture of Newton method applied to u(x)=0 with initial guess x0 and k iterates. Simplify expression and plot the result.
DRAW_COMPLEX(v) Converts the vector of complex numbers [x0+iy0, x1+iy1,...] into a matrix of points [[x0,y0], [x1,y1],...] which can then be plotted in a 2D-plot window.
BISECT(u,x,v) Bisection method for solving u(x)=0 with interval v=[a,b]. The answer is either the left or right half of the interval depending on the root.
LEFT(u,x,n,a,b) Numerical approximation to the integral of u(x) over [a,b] using the left-endpoint method with n rectangles.
MID(u,x,n,a,b) Numerical approximation to the integral of u(x) over [a,b] using the midpoint method with n rectangles.
RIGHT(u,x,n,a,b) Numerical approximation to the integral of u(x) over [a,b] using the right-endpoint method with n rectangles.
TRAP(u,x,n,a,b) Numerical approximation to the integral of u(x) over [a,b] using the trapezoid method with n trapezoids.
SIMP(u,x,n,a,b) Numerical approximation to the integral of u(x) over [a,b] using Simpson's method with n subdivisions.
DRAW_LEFT(u,x,n,a,b) Draws graphic demonstration of the left-endpoint method for numerically integrating u(x) over the interval [a,b] using n rectangles.
DRAW_RIGHT(u,x,n,a,b) Same as above except for the right-endpoint method.
DRAW_TRAP(u,x,n,a,b) Draws graphic demonstration of the trapezoid method for numerically integrating u(x) over the interval [a,b] using n trapezoids.
DE(p,q,x,y,x0,y0) Solves the differential equation (DE) y'+p(x)y=q(x) with y(x0)=y0.
DF(r,x,x0,xm,m,y,y0,yn,n) The direction field (DF) for the differential equation: y'=r(x,y) with a grid determined by x0<x<xm with m subdivisions and y0<y<ym with n subdivisions.
EULER(r,x,y,x0,y0,xn,n) This gives an approximate solution to: y'=r(x,y) with y(x0)=y0. The answer is a vector of points [[x0,y0], [x1,y1], ...] from which one makes a piecewise linear approximating function, i.e., connect the points with straight line segments to get the approximating function's graph.
DE2(b,c,t,t0,y0,v0) Solves the 2nd order homogeneous differential equation with constant coefficients b,c: 
y''+by'+cy=0 with y(t0)=y0 and y'(t0)=v0.
DSOLVE2_IV(b,c,r,t,t0,y0,v0) Solves the 2nd order differential equation: y''+by'+cy=0r with y(t0)=y0 and y'(t0)=v0.

 

Need to Download add-util.mth?

Version 5

The files add-head.dfw (note the new file extension) and add-util.mth are in the folder G:\DfW5\M242L and is a small text file that can be copied onto a floppy disk.  Otherwise just click below:

add-head.dfw (1KB)
add-util.mth (6KB)

Note: In the lab we set the start in directory on the Derive 5 desktop icon to be H:\ so that whenever you start Derive this is where it looks for the file DFW.INI which contains your default settings such as the number of precision digits. We place the add-head and add-util files in the subfolder M242L in the DFW5 install folder. If you do things differently at home then you will need to modify the LOAD command in your add-head file so that both the lab and home locations will work. We suggest having two load commands as follows:

#2:  LOAD("G:\Dfw5\M242L\add-util.mth")
#3:  LOAD("C:\Dfw5\M242L\add-util.mth")

Here, in line 3 above just use the path on your system where the file add-head.mth is  is located.

Version 4

The files add-head.mth and add-util-ver4.mth are in the folder C:\DFW\M206L and is a small text file that can be copied onto a floppy disk.  Otherwise just click below:

add-head.mth (1KB)
add-util-ver4.mth (6KB)

Note: In the lab we set the default directory to be C:\DFW\M206L so that whenever you open a file this is where Derive will look for it. If you use a different default directory at home then you will need to modify the LOAD("add-util-ver4") command in the add-head file to reflect this change. For example, if you default directory is C:\mystuff then copy the above files to that location and change the load command to  LOAD("C:\mystuff\add-util-ver4").