Our goal here is to obtain a general purpose power function that takes a
position function, the destroyer's mass, the destroyer's drag coefficient, and
a time as parameters and computes power requirements. For example, we would
like to be able to ask Maple to compute something like
power1(position, 4.5e6, 3300, 5);
and obtain the power required at time 5 for a destroyer of mass 4.5e6 kg and
drag coefficient 3300 kg/sec that is following the trajectory specified by the
function position.
Passing a function such as position as a parameter to another function
such as power1 may seem strange to you, but you're actually seen this
kind of thing before. Where?
Click here for the answer
One potential problem with defining this new power1 function is that
power depends upon velocity and acceleration, and we receiving only position as
a parameter. How can we address this problem?
Click here for the answer
Let's try to build up the different pieces of the function. Let's assume that
the function will be defined as follows:
power1 := (pos, mass, drag, seconds) -> ...
Thus, there will be four arguments named pos, mass, drag, and
seconds.
To obtain the force required to produce the desired acceleration, we need to
multiply mass by acceleration:
mass * diff(pos(`t`), `t`$2)
Here, the $2 means to do a double differentiation. Why are we enclosing
`t` in single quotes?
Click here for the answer
To obtain the drag force that the destroyer must overcome, we need to multiply
the drag coefficient by velocity:
drag * diff(pos(`t`), `t`)
Next we need to add up the two forces and multiply by velocity, which we can
obtain once again by differentiating pos. If we put all this together,
we have the following function definition:
| power1 := (pos, mass, drag, seconds) ->
(mass * diff(pos(`t`), `t`$2) + drag * diff(pos(`t`), `t`))
* diff(pos(`t`), `t`); |
Experiment with this function. What is wrong with it?
Click here for the answer
We need to convert the current body of the function into a function and then
apply that to seconds. We can do that with unapply,
yielding:
| power1 := (pos, mass, drag, seconds) ->
unapply((mass * diff(pos(`t`), `t`\$2) +
drag * diff(pos(`t`), `t`)) *
diff(pos(`t`), `t`), `t`)(seconds); |
This is our general-purpose power function. You should verify that it
produces the same answers as the original power function when given
appropriate parameters.
Joseph L. Zachary
Hamlet Project
Department of Computer Science
University of Utah