9.4. USING MATLAB 223

In general, the work done by a constant force in a straight line equals the productof the force times the distance over which it acts. If the force is varying with respectto position, then you have to use calculus to compute the work. For now, consider thefollowing examples.

Example 9.3.3 A 500 pound safe is lifted 10 feet. How much work is done?

The work is 500×10 = 5000 foot pounds.

Example 9.3.4 The force needed to stretch a spring x feet past its equilibrium position iskx. This is known as Hooke’s law and is a good approximation as long as the spring is notstretched too far. If k = 3, how much work is needed to stretch the spring a distance of 2feet beyond its equilibrium position? The constant k is called the spring constant. Differentsprings would have different spring constants. The units on k are pounds/foot.

This is a case of a variable force. To stretch the spring from x to x+ dx requires 3xdxfoot pounds of work. Therefore, letting W denote the work up till time x,dW = 3xdx andso the initial value problem is

dWdx

= 3x, W (0) = 0.

Thus W (2) = 32

(22)= 6 foot pounds because an antiderivative for 3x is 3

2 x2. In terms ofthe definite integral, this is written as

∫ 20 3xdx.

9.4 Using MATLABSometimes when you do applications, you end up with an integral you can’t evaluate be-cause you don’t know how to find an antiderivative. When this occurs, you need to usea numerical method. This is a long story best left to numerical analysis courses, but youcan easily get the answer numerically with computer algebra. Suppose you want to findthe really obnoxious integral

∫ 50 sin(x)exp

(−x2

)dx. In MATLAB, you would enter the

following.f=@(x)sin(x).*exp(-x.ˆ2);integral(f,0,5)Then you press enter and it gives.ans =0.4244The first line defines the function and the second tells it to find the integral mentioned

above. You have to use .* because you are dealing with lists of numbers and you want todo the multiplication to corresponding entries. MATLAB is like that. It will see x as a listof numbers and sin(x) as a list of numbers obtained from taking the sine of each number inthe list for x. It is similar for exp.

There is a discussion of numerical integration schemes in Problem 25 on Page 188.However, a rudimentary integration scheme is the Riemann sum. The versions in the aboveproblem are much better and what MATLAB uses is still more sophisticated.

If you have Scientific Notebook, it is even easier. You simply type∫ 5

0sin(x)exp

(−x2)dx