## 3068 Reputation

19 years, 342 days

Doug

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

## see response to your earlier post...

http://www.mapleprimes.com/forum/howdoiplot2xnmatrix#comment-22162

That should give you a good start. Show us what you have tried for 3 and 4. Then we can probably help to fill in the gaps in your knowledge about Maple.

This sounds a lot like an assignment. As such, I'm not going to do the work for you.

Doug

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## see response to your earlier post...

http://www.mapleprimes.com/forum/howdoiplot2xnmatrix#comment-22162

That should give you a good start. Show us what you have tried for 3 and 4. Then we can probably help to fill in the gaps in your knowledge about Maple.

This sounds a lot like an assignment. As such, I'm not going to do the work for you.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## just plot the transpose...

The rows of an Nx2 matrix are interpreted as point by the plot command. So, plot the transpose of your 2xN matrix. For example,

```with( LinearAlgebra ):
B := RandomMatrix(2,10):
plot( Transpose(B), style=point );
plot( B^%T, style=point );
```

For your second question, have you tried the following:

```A^n . B
```

where B is the 2xN matrix. For example,

```A := RandomMatrix(2,2):
B := RandomMatrix(2,10):
A^3 . B;```

Recall that . is the non-commutative multiplication and * is commutative.)

I hope this helps.

Merry Christmas!

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## What have you tried?...

Can you give us an indication of what you are trying to do? Do you want symbolic answers? numerical? graphical?

What, specifically, are the models that interest you?

In what forms are you looking the models that you listed?

How familiar are you with Maple? If you are just getting started, what other technologies are you used to using?

If you can more clearly explain your interests, and show how you have tried to get started using Maple, we can probably help to fill in some of the missing gaps.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## try PDEtools[declare]...

You can get slightly more efficient output by using PDEtools[declare]:

```restart;
PDEtools[declare]([a(t),F(t),eta(a)]);
F(t) will now be displayed as F
a(t) will now be displayed as a
eta(a) will now be displayed as eta

Xi := v_w*x*eta(a(t))*F(t)/a(t)^2:
```
```diff( Xi, t );
```

v_w*x*(D(eta))(a)*a[t]*F/a^2+v_w*x*eta*F[t]/a^2-2*v_w*x*eta*F*a[t]/a^3

Are we getting closer to what you want to do?

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## alias, not declare...

You have to "declare" the dependency BEFORE you assign a value to the name. See, for example:

```restart;
mfx := x -> x^2;
2
x -> x
mfx(x);
2
x
PDEtools[declare](mfx(x));
Error, (in PDEtools:-declare) cannot declare objects as x^2
restart;
PDEtools[declare](mfx(x));
mfx(x) will now be displayed as mfx
mfx(x);
mfx

```

Note, however, if you now define the mfx function, you lose this declaration:

```mfx(x);
2
x

```

I believe you want to be using the alias command instead of PDEtools[declare]:

```alias( mfX = mfx(x) ):
mfx(x);
mfX

```

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

There appear to be some inconsistencies in your description of the dependencies. Here's what I read:

a(t) depends on t,
eta depends on a(t) which in turn depends on t
and F depends on t

In your sample Maple, you have F depending on both eta and t. If F depends only on t, how does eta enter your equation? What is x?

While I do not know if the following is exactly the form you have in mind, it does show how to enter the dependencies and find the derivative wrt t.

```Xi := v_w*x*eta(a(t))*F(t)/a(t)^2;
v_w x eta(a(t)) F(t)
--------------------
2
a(t)
diff( Xi, t );
/ d      \                        / d      \
v_w x D(eta)(a(t)) |--- a(t)| F(t)   v_w x eta(a(t)) |--- F(t)|
\ dt     /                        \ dt     /
---------------------------------- + --------------------------
2                                2
a(t)                             a(t)

/ d      \
2 v_w x eta(a(t)) F(t) |--- a(t)|
\ dt     /
- ---------------------------------
3
a(t)

```

Here is, I hope, the derivative in a typeset form.

v_w*x*(D(eta))(a(t))*(diff(a(t), t))*F(t)/a(t)^2+v_w*x*eta(a(t))*(diff(F(t), t))/a(t)^2-2*v_w*x*eta(a(t))*F(t)*(diff(a(t), t))/a(t)^3

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## using Statistics' RandomVariable, Normal...

Using the Statistics package, I can do this with 3 commands (from the Statistics package): RandomVariable, Normal, and PDF (or CDF).

If you want to see how to use these 3 commands, read on.

```with( Statistics ):
X := RandomVariable( Normal(3,3) );
_R1

f := PDF(X,t);
(1/2)    /  1         2\
2      exp|- -- (t - 3) |
\  18         /
-------------------------
(1/2)
6 Pi

int( f, t=0..infinity );
1   1    /1  (1/2)\
- + - erf|- 2     |
2   2    \2       /

evalf( % );
0.8413447460

```

Or, if you prefer, using the CDF:

```CDF(X,infinity)-CDF(X,0);
1   1    /1  (1/2)\
- + - erf|- 2     |
2   2    \2       /
```

Here, I note that you can also use CDF(X,infinity) as a fancier name for 1.

To see the PDF and CDF, you can use the following command:

```plot( [PDF(X,t),CDF(X,t)], t=-infinity..infinity );
```

These can be consolidated into a fewer (1) command, but the above is more explicit about what Maple is actually doing.

This seems pretty straightforward to me. The online help for the Statistics package is not that difficult to navigate. You just have to read it carefully.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## tables and procedures and remember table...

The two code pieces do not do the same thing!

In your first case, you create a as a table and access its values using subscripts (denoted by square brackets):

```restart:
for i from 1 to 5 do  a[i]:=i;  end do:
map2( is, a, [table,procedure] );
[true, false]
print( a );
table([1=1,2=2,3=3,4=4,5=5])
```

In your second case, you create a as a procedure (function) with 5 pre-assigned values that are stored in a "remember table": (See ?remember)

```restart:
for i from 1 to 5 do  a(i):=i;  end do:
map2( is, a, [table,procedure] );
[false, true]
print( a );
proc()  option remember, 'procname(args)'  end proc;
```

The current contents of Maple's remember table for the function a is found to be:

```op(4,eval(a));
table([1=1,2=2,3=3,4=4,5=5])```

So, the function definition is really using a table. The first implication of this has to mean that there is more overhead in storing the procedure. I'd also suspect that it would be slightly slower to access information from the procedure than directly from a table. For an example like this, these differences are likely to be very slight. But, in other settings, I can see that these could become significant.

My recommendation is to use a table, with square brackets, when that is what you are really using.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## graphical viewing using animation or 3d...

I think you have missed on  your guesses for interesting values of Q. Rather than getting individual plots for fixed values of Q, I let Maple create an animation of this curve as a function of the parameter Q. Here's the basic idea, building upon Robert's use of implicitplot:

```with( plots ):
animate( implicitplot, [18^2-y^2 = 10^q*(ln((3000*(18-y))*sqrt(0.412e-4))-ln(sqrt(x)))/(0.412e-4*Pi),
x=0..5000, y = 0 .. 20,gridrefine=3,crossingrefine=3], q=-2..-1 );

```

Note that I replaced Q with 10^q and modified the viewing window. In my code, I'm looking at Q between 0.01 and 0.1. (I'm having trouble uploading a file to MaplePrimes right now, so I can't show you what this produces.) Further refinements are probably called for, but I don't know enough about the specifics of your problem to begin to guess what you want to see.

You could also look at your equation in 3D. I don't see that the gridrefine and gridcrossing options are available in implicitplot3d, so it's a little more difficult to get a good picture.

```implicitplot3d(18^2-y^2 = 10^q*(ln((3000*(18-y))*sqrt(0.412e-4))-ln(sqrt(x)))/(0.412e-4*Pi),
x=0..2000, y = 0 .. 20, q=-2..-1, axes=boxed );
```

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## simplified plots...

Can't you get the first plot with a single plot command?

```plot( sin(x), x=-2*Pi..2*Pi, color=black, tickmarks=[spacing(Pi/2,0),3] );
```

You will have, in general, better success with math expressions in plot captions, etc., if you use the typesetting capabilities built-in to plot. For example,

```plot( 2*cos(x/2-Pi/6), x=-2*Pi..2*Pi,
tickmarks=[spacing(Pi/2,0),3],
title=typeset("A plot of one period of \n", y=2*cos(x/2-Pi/6)) );
```

As far as creating plots for use in LaTeX, my current process is to manually export the plot to a GIF or JPEG file, then convert each image to a PDF file, which can now be brought into my (pdf)LaTeX documents. (The exporting to a file can be automated using plotsetup.

I think you'll have much more success with this approach.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## code generation limitations...

If you want to work with a 3D array of data, why don't you do so in Maple?

For example:

```A1 := [[1, 2], [3, 4]];
A2 := [[7, 1], [6, 2]];
A3 := [[2, 1], [5, 2]];
[[1, 2], [3, 4]]
[[7, 1], [6, 2]]
[[2, 1], [5, 2]]
```
```AA := [ A1, A2, A3 ];
[[[1, 2], [3, 4]], [[7, 1], [6, 2]], [[2, 1], [5, 2]]]

AA[1,2,1];
3
```

Then,

```Matlab( A1 );
cg4 = [1 2; 3 4;];
Matlab( AA );
Error, (in Print) cannot print lhs

```

Oh, I see. It appears that Maple's conversion to Matlab does not know what to do with a 3D array of data. That's unfortunate - and not mentioned in the help page. This is something to be improved for the future!

Maple's behavior for your attempts does seem to be inconsistent with what's on the help page (see the underlined sentence):

resultname=value
Specifies the name of the result (that is, the generated procedure or the left-hand-side variable in the generated assignment) when the input is unnamed. The value can be any string. When no result name is specified or deduced, an automatically generated name is used.

This, too, is something that should be improved.

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## Deja Vu?...

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## Yahtzee!...

Yahtzee is all five dice with the same value, right?

If so, then this should work:

```restart;
die := integer(range=1..6):
roll := n -> RandomTools:-Generate(list(die,n)):
for n from 1 do
R := roll(5);
if nops({R[]})=1 then break end if
end do:
n;
```

The explicit creation of a roll is unnecessary. But, if you change end do: (colon) to end do; (semi-colon) you will see each roll.

The only complication in this is converting the list to a set. That's what {R[]} does. The same could have been done with convert(R,set), but that takes too long to type. You could avoid this altogether by making roll return a set - but then you don't know the detail of the roll. Here's how that would look:

```rollS := n -> RandomTools:-Generate(set(die,n)):
for n from 1 do
R := rollS(5);
if nops(R)=1 then break end if
end do:
n;
```

I've see values as low as 5 and higher than 5000. Of course, this only accounts for natural Yahtzee's, not the two additional rolls with a subset of the dice.

If you want to gather some data on this event, maybe you'll want to do something like the following:

```YahtzeeCount := proc()
local die, n, rollS, R;
die := integer(range=1..6):
rollS := n -> RandomTools:-Generate(set(die,n)):
for n from 1 do
R := rollS(5);
if nops(R)=1 then break end if
end do:
return n;
end proc:
[seq( YahtzeeCount(), k=1..10 )];
[1595, 44, 949, 2737, 123, 422, 2939, 512, 257, 1289]
```

If I do too much more, I'll be depriving you of the fun of playing with this.

I hope this has been helpful,

Doug

```---------------------------------------------------------------------
Math, USC, Columbia, SC 29208  E-mail: mailto:meade@math.sc.edu
Phone:  (803) 777-6183         URL:    http://www.math.sc.ed```

## = or :=, that is the question...

Did you enter and execute

```x=4;
```

or

```x := 4;
```

Only the latter is an assignment. The former is an equation, and does not give a value to x.

```---------------------------------------------------------------------