Easy3.mws

**integration, assume, solve(analytic) and 'allvalues', solve dsolve(analytic),
dsolve(numeric), Heaviside **

**restart; with(plots): **

**int(sin(x),x=0..2); **

Now a more complicated integration.

An element of charge dq located at (a,b) creates an element of potential dV at (x,y):

**dV := k*dq /sqrt((x-a)^2+(y-b)^2);**

Then we'll get ready for an integration over a rod on the x-axis. xp will be the integration variable.

**dV1:=subs(k=9e9,b=0,a=xp,dV)**;

Now put in lambda = 10^-9 C/m for charge/length on the rod, and integrate. The rod is 3 meters long from the origin along the +x axis.

**V := int (subs(dq=1e-9,dV1),xp=0..3);
plot3d(V,x=0..5,y=1/1000..2); **# view the results, staying away from
the rod itself.

The plot3d graph can be manipulated by using the mouse (or arrow keys in DOS) , showing different views and different ways of presenting the data.

This is a **derivation of the compton wavelength formula**.

It illustrates eliminating variables, dealing with analytic solutions.

It uses **'assume'** to improve the chances of the derivation succeeding.

The 'solve' analytic solution of the two momentum equations gives the famous 'Root of ...' output.

To deal with this, one must use '**allvalues**' to make sense of
the output. This gives a solution for momentum, and angle phi. We select
the momentum solution, and eliminate phi, making sure to select the positive
momentum solution.

restart:assume(h>0,p>0,lam>0,lamp>0,m>0,c>0);assume(theta,real);assume(phi,real);

First the x and y momentum equations.

eq1:=h/lam=h/lamp*cos(theta)+p*cos(phi); eq2:=0=h/lamp*sin(theta)+p*sin(phi); sol:=solve({eq1,eq2},{phi,p}); s:=allvalues(sol[1]); # Careful! Pick the 'p' solution, eliminating phi. p:= rhs(s[1]); # Careful again! Want positive p.

Now the energy equation, with p's value substituted in it.

eq4:= h*c/lam + m*c^2 = sqrt((p*c)^2 + (m*c^2)^2)+h*c/lamp; s1:=solve(eq4,lamp); s2:=s1-lam;

Finally we get that lambda-prime minus lambda = (h/mc)(1-cos (theta) ).

simplify(s2);

Download comptn2.mws [Use 'Save File' and then open it in Maple]

Now we show how to use dsolve, first with a simple mass-spring system.

This solution can be analytic.

**assume(ks>0,m>0); **# real positive constants

**ys:=dsolve(m*diff(y(t),t,t)=-ks*y(t),y(t));** # analytic solution,
assigned to ys

**yn:=dsolve({5*diff(y(t),t,t)+2*y(t)=0,y(0)=1,D(y)(0)=0},y(t),numeric);**

Numeric solution is assigned to yn

Ask for help on odeplot command if we need it.

**?odeplot **

**odeplot(yn,[t,y(t)],0..6);** # here is a simple way to plot the
numeric solution

Here's another very simple use of dsolve.

Suppose a 10.5-kg object travelling at 5 m/s is subject to a retarding force of 0.2 N. Solve newton's second law for this simple case and plot it. If you plot it long enough it will turn around. Note the use of rational numbers, rather than decimals. Maple is much happier with rationals.

**s1:=dsolve({105/100*diff(x(t),t,t)=-2/10,x(0)=0,D(x)(0)=5},x(t));**

**x:=rhs(s1);** # assign the analytic solution. Not this simple with
numeric solutions.

**plot(x,t=0..100); **

**x:='x'**; #unassign x -(free it up)

Now we illustrate the Heaviside (step) function. If you type in **Heaviside(3.2);
**and **Heaviside(-1/3);
**you can see that it's 1 if its argument is positive, and 0 if it argument
is negative.

First, we create a step function of x which is 1 when x is > a. Then we put the step at x=2 and plot it to make sure it's ok.

**step:=Heaviside(x-a);**

**plot(subs(a=2,step),x=-5..5); **# check it by looking at the plot

As an exercise, the user should now create a function using 'step' which is 1 between x=1 and x=5, and is zero outside that range. Plot it, of course, to see if it's ok.

Next, we want to take account of linear velocity damping in a mass spring. The damping force must be positive when v is negative, and the force must be negative when v is positive. A plot will confirm that we got it right.

**Fdamp:=-v*(Heaviside(v)+Heaviside(-v));
plot(Fdamp,v=-2..2); **

We can now study the mass-spring system with damping.

**eqn:= m*diff(x(t),t,t) = -k*x(t)-b*diff(x(t),t)*(Heaviside(diff(x(t),t))+Heaviside(-diff(x(t),t)));
**

**values:={m=1,k=1,b=2/10};
eqa:=subs(values,eqn);**

**sd:=dsolve({eqa,x(0)=1,D(x)(0)=0},x(t),numeric);**

**sd(1); **# see what the solution looks like at t=1

**odeplot(sd,[t,x(t)],0..10);**

Here is an example of both Heaviside functions and doing a dsolve for two variables. (So it really belongs among the 'fancy' worksheets.)

A moving mass m1 has a spring of unstretched length x0 attached to it. m1 has an initial velocity in the +x direction and travels until it encounters a stationary mass m2. The spring compresses during the collision until the masses separate, and we plot the motion of both masses as a function of time.

**restart;with(plots):
d:=-x2(t)+x1(t)+x0; **# spring compression

eq2:=+k*(d)*Heaviside(d) = m2*diff(x2(t),t,t);

**values:={m1=1,m2=1,k=10,x0=1/2};
eqs:=subs(values,eq1),subs(values,eq2);
s:=dsolve({eqs,x1(0)=0,D(x1)(0)=5,x2(0)=1,D(x2)(0)=0},{x1(t),x2(t)},numeric);**

**h:=odeplot(s,[t,x1(t)],0..3/2,color=red):
j:=odeplot(s,[t,x2(t)],0..3/2,color=blue):
display({h,j},title=`x1(t)[red], x2(t)[blue] vs t`);**

With this as a starter problem, students could be asked to work out the problem of two masses falling vertically, one above the other. [This is analogous to the small ball being dropped just above a large ball so that after they strike the ground, the small ball bounces high into the air.] One spring is attached to each mass, and one mass is directly above the other. The masses are released from rest at the same time, with some separation between them. The lower mass's spring strikes the ground and it rebounds, then encounters the spring of the upper mass. After the collisions the upper mass rebounds to some maximum height. The idea is to find the maximum rebound height of the upper mass, given masses and spring constants. The adjustable parameter is the distance between the masses when released from rest.

a) Given masses, spring constants, and unstretched spring lengths, and the initial height of the lower mass, reason out how the collision should occur so that the upper mass rebounds to a maximum height.

b) After the qualitative considerations are worked out, simulate the drop, and the motion of the two masses.

**Exercises for the user.**

1. Integrate (sin(x))^2 from 0 to 6*Pi or any other integer multiple of Pi/2. This should verify that the average of sin^2 x is 1/2 over these ranges.

2. A 2-kg ball is moving in the x-direction, subject only to a drag
force (N) given by its velocity (m/s) squared divided by 10000. Use **dsolve**
to find the motion of this ball, and then plot its position vs. time.

3. Use Heaviside functions to create a 'window' of height 1 between x=10 and x=20, being zero everywhere else.

4. Use Heaviside functions to create a sawtooth wave which starts at (0,0) and goes to (1,1) and then back down to (0,2).

End of Easy3