Doug Meade

 

Doug

---------------------------------------------------------------------
Douglas B. Meade <><
Math, USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
Phone: (803) 777-6183 URL: http://www.math.sc.edu

MaplePrimes Activity


These are answers submitted by Doug Meade

There appear to be (at least) two issues at play. The setup is:

with(plots):
with(Statistics):
L:=[[1],[3, 2],[3.4, 6], [5,3,7], [3,7,9,1], [2,6,8,4,5]]:

I would expect this could be done quite easily with animate:

animate( PointPlot, [ L[trunc(t)] ], t=1..5, frames=5 );

Note that without the frames=5, animate creates an animation with 25 frames - clearly not appropriate here. Also, the trunc(t) ensures that L receives an index that is an integer. But, this leads to the error message:

Error, (in plots/animate) invalid input: Statistics:-PointPlot expects its 1st argument, x, to be of type
{list({array, list, rtable}), {array, list, rtable}}, but received [[1], [3, 2], [3.4, 6], [5, 3, 7], [3, 7, 9, 1],
[2, 6, 8, 4, 5]][trunc(1.)]

It appears that PointPlot has some special evaluation rules that prevent it from being used in this way.

All is not lost as I'll just create a wrapper that calls PointPlot - like this:

myPlot := p -> Statistics:-PointPlot( L[trunc(p)] ):

Then, this works fine:

animate( myPlot, [ t ], t=1..5, frames=5 );

I would probably take this one step further and define

myPlot2 := p -> Statistics:-PointPlot( L[p] ):

and then create the animation with

animate( myPlot, [ t ], t=[$1..nops(L)] );

Note that this works because you are giving an explicit list of (integer) values for the animation parameter. (See ?plots,animate for more details and examples using the animate command.)

The only visible difference in these two approaches is that the displayed parameter in the latter case is an integer, and a float in the former.

I hope this will be useful to you,

Doug

NOTE: Is it true that the automatic help reference markup is in place in the new MaplePrimes? It existed for a while in the previous version, but then stopped working. I didn't know it was back with the new MaplePrimes until I came back to review my comment. I had tried to manually insert a link to the online help, but could not get the search to produce plots,animate as something I could select.

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

In my experience, in situations like this you want to redefine the \code so that it produces no output. Something linke:

\renewcommand{\code}[1]{}

If you want to get a little fancier, you could possibly use

\renewcommand{\code}[1]{\textit{Maple code deleted.}}

To have the code appear, just comment out the redefinition.

These might need a little bit of refinement depending upon exactly \code is defined in MapleTA, but I think this gives the general idea.

Doug

---------------------------------------------------------------------
Douglas B. Meade <><
Math, USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
Phone: (803) 777-6183 URL: http://www.math.sc.edu

Something like this?

P := <1,2,3,4,5>;
                                     [1]
                                     [ ]
                                     [2]
                                     [ ]
                                     [3]
                                     [ ]
                                     [4]
                                     [ ]
                                     [5]
eq := sin(p*x)=1;
                                sin(p x) = 1
S := <seq( fsolve( eq, x ), p=P )>;
                               [ 1.570796327]
                               [            ]
                               [0.7853981634]
                               [            ]
                               [0.5235987756]
                               [            ]
                               [0.3926990817]
                               [            ]
                               [0.3141592654]
< P | S >;
                              [1   1.570796327]
                              [               ]
                              [2  0.7853981634]
                              [               ]
                              [3  0.5235987756]
                              [               ]
                              [4  0.3926990817]
                              [               ]
                              [5  0.3141592654]

Hmm. As preformatted text, I would have expected the above to be displayed in a fixed-width font. Based on what I can see in the input window, this is not using a fixed-width font. But, when previewed, it does look fine. (A weakness, and something I expect that will perplex other users.)

I hope this is helpful,

Doug

---------------------------------------------------------------------
Douglas B. Meade <><
Math, USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
Phone: (803) 777-6183 URL: http://www.math.sc.edu

Have you looked at trunc? The help page ( ?trunc ) gives details and examples for trunc, floor, ceil, round, and frac.

trunc(13/4);
                                      3
floor(13/4);
                                      3
ceil(13/4);
                                      4

I hope this is helpful,

Doug

---------------------------------------------------------------------
Douglas B. Meade <><
Math, USC, Columbia, SC 29208 E-mail: mailto:meade@math.sc.edu
Phone: (803) 777-6183 URL: http://www.math.sc.edu

Why don't you use the third dimension to display the time?

You can use the transform command in the plottools package to have convert your 2D plots to 3D plots with height corresponding to the iteration counter. For example, define the mapping

to3d := i -> plottools:-transform( (x,y)->[x,y,i] );

To use this, just change your definition of plo[i] to

plo[i] := Z(i)( plot([u[i](t), v[i](t), t = k[i] .. k[i+1]]) )

The plot that this gives is shown below:

If you are going to change your loops for a, m, and n so that they are actual loops, then you may want to save the different plots in a table (but be careful about using floats as table indices). Maybe like this:

P[a,m,n] := plots:-display(seq([plo[i]], i = 1 .. iter), title=typeset("a=",a,", m=",m,", n=",n), axes=boxed);

If you look closely at my plot, you will see that this is the way I put the values of a, m, and n in the title.

You could probably also do something very nice with animation.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

While Preben and I have been able to suggest ways to address the OP's question, the real issue (at least to me) is that all of this could be eliminated if the dsolve was given a little more functionality with parameters. Recall the current setting:

with( plots ):
deqs := { diff(x(t),t) = h*sin(t) + y(t),
          diff(y(t),t) = x(t),
          x(0)=0, y(0)=0}:
integ := dsolve(deqs, numeric, parameters=[h]):

I'd like to be be able to include the parameters value in the call to odeplot.

odeplot( integ( parameters=[1],  [[t,x(t)],[t,y(t)]], t=0..3 );

or, to create an animation for different values of the parameter:

animate( odeplot, [ integ( parameters=[H] ), [[t,x(t)],[t,y(t)]], t=0..3 ], H=-1..5 );

The ideas Preben and I used can be  used in these cases as well, but these seem more natural - and more empowering.

Of course, to produce the 3D plot the syntax would need to be extended even further. For that you would need to be able to specify a value for the parameter and a value of the independent variable in a single call to the numeric integrator. (If you look at what Preben and I have suggested, it's basically a wrapper that combines 2 calls to integ - one to set the parameter and one to specify a value of the independent variable (t).) If this were possible, then you could produce the 3D plot as follows:

plot3d( eval( [x(t),y(t)], integ( t, parameters=[H] ) ), t=0..3, H=-1..5 );

Please don't read more into this post than I intend. I really love the ability to work with numeric solutions to IVP with parameters. It's just that now that I see what has been implemented, I see additional features that would make this feature even more powerful (and easier to use).

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

All you need to do is create a function that takes 2 arguments and returns x, or y. Here's a fairly standard way of doing this, so that it can be used later for plotting.

X := proc(T,H)
  global integ;
  if not ( T::numeric and H::numeric ) then return 'procname'('args') end if;
  integ(parameters=[H]);
  eval( x(t), integ(T) );
end proc:
Y := proc(T,H)
  global integ;
  if not ( T::numeric and H::numeric ) then return 'procname'('args') end if;
  integ(parameters=[H]);
  eval( y(t), integ(T) );
end proc:

The only thing that's not completely obvious is the if statement. This is needed so that when the function receives non-numeric inputs, as will happen when used (next) in a plot3d command:

X(1,b), X(a,2), X(a,b), X(1,2);
     X(1, b), X(a, 2), X(a, b), 1.0027783028602073

Now, here's how to create the plot:

plot3d( [X(t,H),Y(t,H)], t=0..3, H=-1..5, color=[red,blue], transparency=0.5, axes=boxed );

The plot is not that interesting, but we're using just a sample problem. This should work in the same way with your real problem.

I hope this has been helpful,

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

If you really want all solutions to a polar equation, I suggest using the AllSolutions option to solve (see ?solve,details ):

solve( cos(2*theta)=1/2, theta, AllSolutions );
                          1      1                
                          - Pi - - Pi _B1 + Pi _Z1
                          6      3                

In this answer Maple uses _Z1 to stand for an integer and _B1 to stand for a binary variable (value either 0 or 1)

about( _B1, _Z1 );
Originally _B1, renamed _B1~:
  is assumed to be: OrProp(0,1)

Originally _Z1, renamed _Z1~:
  is assumed to be: integer

You can construct a list of explicit solutions for different values of these parameters as follows:

S2 := [ seq( seq( [b,z,eval(S,[_B1=b,_Z1=z])], z=-3..3 ), b=0..1 ) ];
    [[         17   ]  [         11   ]  [         5   ]  [      1   ]  
    [[0, -3, - -- Pi], [0, -2, - -- Pi], [0, -1, - - Pi], [0, 0, - Pi], 
    [[         6    ]  [         6    ]  [         6   ]  [      6   ]  

      [      7   ]  [      13   ]  [      19   ]  [         19   ]  
      [0, 1, - Pi], [0, 2, -- Pi], [0, 3, -- Pi], [1, -3, - -- Pi], 
      [      6   ]  [      6    ]  [      6    ]  [         6    ]  

      [         13   ]  [         7   ]  [        1   ]  [      5   ]  
      [1, -2, - -- Pi], [1, -1, - - Pi], [1, 0, - - Pi], [1, 1, - Pi], 
      [         6    ]  [         6   ]  [        6   ]  [      6   ]  

      [      11   ]  [      17   ]]
      [1, 2, -- Pi], [1, 3, -- Pi]]
      [      6    ]  [      6    ]]

Then, you can select only those with values between 0 and 2*Pi :

select( s->evalb(evalf(s[3])>0 and evalf(s[3]-2*Pi)<0 ), S2 );
          [[      1   ]  [      7   ]  [      5   ]  [      11   ]]
          [[0, 0, - Pi], [0, 1, - Pi], [1, 1, - Pi], [1, 2, -- Pi]]
          [[      6   ]  [      6   ]  [      6   ]  [      6    ]]

Of course, if you want only the values of theta (and not _Z1 and _B1), just omit these from the list S2. In that case you can do this a little simpler:

S3 := [ seq( seq( eval(S,[_B2=b,_Z2=z]), z=-3..3 ), b=0..1 ) ];
[  17       11       5     1     7     13     19       19       13       7     
[- -- Pi, - -- Pi, - - Pi, - Pi, - Pi, -- Pi, -- Pi, - -- Pi, - -- Pi, - - Pi, 
[  6        6        6     6     6     6      6        6        6        6     

    1     5     11     17   ]
  - - Pi, - Pi, -- Pi, -- Pi]
    6     6     6      6    ]
select( is, S3, RealRange(0,2*Pi) );
                          [1     7     5     11   ]
                          [- Pi, - Pi, - Pi, -- Pi]
                          [6     6     6     6    ]

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

Here's how I would accomplish this:

with( plots ):
a:=[[1,1,1],[2,2,1],[3,4,4.5],[2,1,2.4]];
e := seq( pointplot( p[1..2], symbolsize=trunc(p[3]*10) ), p=a ):
display( e );

Note that the symbolsize must be an integer. I chose to use trunc, but any other function that results in an integer could be used (ceil, floor, round, ...).

The ability to use seq to work through the elements of a list (or operands of an expression) can be very powerful. In particular, note that there is no reference to the number of elements in the original list of points (a).

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

If you will show us how you are plotting a single frame of your animation, I know we can show you how to create the animation.

You will also need to tell us what parameter you want to vary to create the animation.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

All of the previous responses are correct, but do not deal with the OP's situation.

Suppose the indefinite integral has been entered using a palette. This is done with int, not Int. So, the first step needs to be the conversion to intert form.

This, too, can be done from the context menu. Put the cursor on the expression, right click, select 2-D Math (last item in the list), then Convert to, then Inert Form. The input won't change, and the will be no indication that this change was done. But, now, selecting Solve ... Show Solution Steps works fine. Here's what I get:

Noice that the input is centered with the output. This is not how this appeared originally, but happens when I hide the palettes (after Maple shows the steps in the solution). This appears to be a bug.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

One of the advantages of Maple is that it supports many different modes of use.

There are lots of point-and-click features that simplify the experience for new users. Robert Lopez has a large collection of "Clickable" mathematics resources that should be accessible from the Maplesoft websites. Many of these show how to use the built-in tutors, task templates, etc. Many of these make use of the Student package.

Others, myself included, have created collections of maplets.

As you become more comfortable, and your needs increase, you can move to either the document or worksheet modes of use. Documents provide a word processor-like interface that also allows usage of Maple to create attractive documents with sophisticated (and live) mathematics and graphics. The worksheet interface provides a more classical programming interface based on command lines.

Depending upon your specific needs and interests, you might find something good in the online help within Maple. If you want a book, I hope you will take a look at one that I co-authored in 2009: Getting Started with Maple. The publisher is Wiley, and it's available from Amazon.

I hope this is helpful. Please ask more questions as they arise.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

There are lots of ways to "show" this fact in a plot. To start, we give some values to the parameters in this example:

X1 := a1*exp(r1*t);  # growth rate r1
X2:= a2*exp(r2*t);  #  growth rate r2
LinComb:= c1*X1+c2*X2;   # a linear combination
                             X1 := a1 exp(r1 t)
                             X2 := a2 exp(r2 t)
                LinComb := c1 a1 exp(r1 t) + c2 a2 exp(r2 t)
PARAM := [ a1=1, a2=1, r1=2, r2=1, c1=1/2, c2=1/2 ]:
plot( eval( [X1,X2,LinComb], PARAM ), t=0..10 );             # shows how the LinComb (Avg) grows like X1
plots:-logplot( eval( [X1,X2,LinComb], PARAM ), t=0..10 );   # try this also with t=0..100

You could easily get more sophisticated with these visual arguments.

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

Let's see if I can answer some of these questions.

The quantity diff( x(t), t ) / x(t) is the per capita growth rate of x(t). When x(t) is a pure exponential, this quotient is a constant - the growth rate.

The asympt command finds asymptotic expansion of its first argument for large values of its independent varilable. It's found by using the series command (see ?asympt ).

The O(1) is an "order term". In this case, it tells you the coefficient of the exponential in the asymptotic expansion is bounded (as t increases).

I would say that any linear combination of exponentials grows (or decays) according to the size of the largest growth rate (coefficient of t in the exponential). For example:

with(MultiSeries):
X1 := a1*exp(r1*t);  # growth rate r1
X2:= a2*exp(r2*t);  #  growth rate r2
LinComb:= c1*X1+c2*X2;   # a linear combination
asympt(diff(LinComb,t)/LinComb, t) assuming r1 > r2;  # asymptotic growth rate of the linear combination

                             X1 := a1 exp(r1 t)
                             X2 := a2 exp(r2 t)
                LinComb := c1 a1 exp(r1 t) + c2 a2 exp(r2 t)
                                           (r1 - r2)
                                   /  1   \         
                         r1 + O(1) |------|         
                                   \exp(t)/         

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu

Here's how I would enter your equations:

sys :=
  diff(r(t),t,t)
    - r(t)*(diff(phi(t),t)^2+sin(phi(t))^2*diff(theta(t),t)^2)
    - exp(-r(t)^2) = 0,
  2*sin(theta(t))*diff(phi(t),t)*diff(r(t),t)
    + 2*r(t)*cos(theta(t))*diff(phi(t),t)*diff(theta(t),t)
    + r(t)*sin(theta(t))*diff(phi(t),t,t) = 0,
  2*diff(r(t),t)*diff(theta(t),t)
    + r(t)*diff(theta(t),t,t)
    - r(t)*sin(theta(t))*cos(theta(t))*diff(phi(t),t)^2 = 0;

You did not mention initial or boundary conditions. I'm going to assume you have initial conditions at t=0:

ic := r(0)=r0, D(r)(0)=r1,
      theta(0)=t0, D(theta)(0)=t1,
      phi(0)=p0, D(phi)(0)=p1;

It's unlikely that there is an explicit analytic solution to this system, so I'll look for a numeric solution:

sol := dsolve( { sys, ic }, numeric, parameters=[r0,r1,t0,t1,p0,p1] );

To use this numeric solution, first specify values of the initial conditions (parameters):

sol( parameters=[1,2,-3,4,-1,6] );
          [r0 = 1., r1 = 2., t0 = -3., t1 = 4., p0 = -1., p1 = 6.]

Then, a plot of the three components of the system can be produced with the odeplot command (from the plots package):

plots:-odeplot( sol, [[t,r(t)],[t,theta(t)],[t,phi(t)]], t=0..1 );

If, by chance, r, theta, and phi are spherical coordinates, you can plot the trajectory that this solution follows with:

 plots:-odeplot( sol, [r(t)*sin(phi(t))*cos(theta(t)),r(t)*sin(phi(t))*sin(theta(t)),r(t)*cos(phi(t))], t=0..10,
                 labels=["x","y","z"], axes=boxed );

As I do not know reasonable values for the initial conditions, I don't know if I have reasonable pictures.

Maple does seem to have some success finding an analytic general solution, but the result is too large to display (seriously!):

sol0 := dsolve( {sys} );
                 [Length of output exceeds limit of 1000000]
length( sol0 );
                                  48217766

I do not have high hopes that this solution will be useful. I hope this is helpful,

Doug

---------------------------------------------------------------------
Douglas B. Meade  <><
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.edu
First 9 10 11 12 13 14 15 Last Page 11 of 44