This program will calculate the deflection in a beam subject to a
compression load l
(see the figure to the right). The
beam has been normalized so that the endpoints are 0 and 1. For small values of
l the beam will not deflect. As l exceeds p2,the beam will begin to deflect. The program will consist of
five parts:
| ![]() |
The function that you are to find the root of should return the value of the deflection of the beam at the right endpoint given the value of the slope of the beam at the left endpoint. The method used to solve this problem is called the Shooting Method. The idea is to adjust the slope at the left endpoint until the beam passes through 0 at the right endpoint. It is based on the concept of adjusting the elevation (slope) of a cannon so that a cannon ball fired from the cannon will pass through a specified point down range.
The prototype for the forcing
routine f is
void f(float x, int n, float *y, float *yp)
where x is a point along the beam, n is the number of differential
equations (2 in this case), y is an
array to contain the displacement and slope at x, and yp
is an array of length 2 defined by:
yp[0] = y[1]
yp[1] = -lambda * sin(y[0])
where lambda is the compression load l
applied to the beam. Your main program should get the value of l, start the root finder with initial values
of 4 then 5 for the slope at the left endpoint, and a tolerance of 5e-6. You
should use 0.01 as the distance between points on the beam.
The one step differential
equation solver is defined by the following prototype:
void rk(float x, float h, int n, float *y, void (*f)(float, int, float *, float *))
where x, n and y are defined as
above, h is the distance between
successive points along the beam, and f is the name of the forcing routine
described above.