acer

32333 Reputation

29 Badges

19 years, 322 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

This problem occurs in Maple 16.00 when the typesetting level is "standard".

You can get around it in at least these two ways:

A) Do a point-release upgrade. It seems ok in 16.01, but why not go directly to the later 16.02a? Download from here (or see here or use the menubar to upgrade, see here.) With this approach it should print properly with either typesetting level.

B) Set the typesetting level to "extended". You can do this with the command,

interface(':-typesetting'="extended"):

or you can set it (for a single session, or globally for future sessions) as a GUI preference. Use the main menubar and choose Tools->Options, then choose the "Display" tab, and then switch it in the drop-menu "Typesetting level". (See here.)

acer

You could give each of the individual plots the `legend` option. You can build those up using `sprintf` (or `cat`). Then the plots:-display command will combine them.

For example,

p:=[1.5,2,2.5]:
with(plots):
display([seq(plot(x^i, color=COLOR(HUE,i/3),
                  legend=sprintf("Parameter %.1f",p[i])),
             i=1..3)]);

And here is a similar treatment for your previous post.

MapleS_test6_d.mw

acer

It's not quite clear what the three dimensions of your Array N are supposed to mean, so it's a little tricky to figure out what you want plotted here, and how.

There are quite a few problems in your posted Document. As written, the loop code would not run, generating an error about bad index into the Array.

In the plotting command you use `M` but that must surely be `N`.

Inside the inner loop there is `n0` which is not defined, so I suppose that `indexN0` was intended there. I changed this.

Somehow several instances of indexN0 have turned into text (?!) with upright font instead of the italics (usual for general names). I just changed this, though it might not have been necessary.

If I chose wrongly while getting it to run, apologies.

My best guess is that you are trying to make a plot for each "r value" of the second dimension of N, from 1 to nStepsR. And, judging from your intended label on the horizontal axis I figure you want the points of each such curve to be according to the value of the index of the first dimension of N (time, I guess).

Let's clear up something, though. There is no special `surfdata` command that handles multple surfaces. In your previous post the solution I gave wrapped `surfdata` inside a call to `seq`. The `seq` command generates a sequence of calls to its first argument (in that case, `surfdata`). So, you see, `surfdata` was in fact called multiple times.

One way to handle you current Question, if I have understood properly, is to again produce a sequence of individual 2D plots. There are two apects you want, I suspect. Different colors for each individual plot, and proper tickmarks for the horizontal axis. You used Maple 17 before, so I've done so too. I believe that you are trying to plot 1-dimension slices of N, such as N[..,r,1] where r has a fixed value. In other words, the horizontal axis represents the first dimension of Array N (time, I guess). It doesn't matter if I guess the wrong dimension of N. What matters more, I think, is that you have only a single fully explicit dimension of data, which is the value (vertical axis) at the Array entry. The horizontal aspect is just the position of the entries, the first index into N. That's why your label for the horizontal axis mentions scale. Because from one entry to the next the increment (1 to tMax) implicitly represents some unit of time. So you either have to note that unit in the label, or you could create a custon set of tickmarks for the horizontal axis.

Anyway, the command which does 2D plots of an indexed collection of values is plots:-listplot. Unfortunately there is no 2D analogue to `listplot` with a relationship similar to that of the 3D `surfdata` to `matrixplot`. (I'm still rambling about the scale or ticks long the first axis.)

Below, I use a nice feature of newer Maple versions (inclusing Maple 17) to set a palette of colors for the separate 2D plots. This avoids having to generate a list of nStepsR colors.

restart

"# Pathology problem for a population, N[t], of  cells:     N[t+1]  = r*N[t]*(1-N[t])      where N is normalized to represent the fraction of cells that can be contained in the culture vessel used, and r is the growth rate of the  cells (assumed to be constant for all clones)."
NULL

 

# Interactive package management: make the short form names of the commands of a Maple package available at the interactive level

with(plots):NULLNULL

 

""# Set the simulation length""

tMax := 50:NULLNULL

NULL

NULL

rMax := 5:NULL

NULL

fractionFactor := 10^(-5):NULL

sensitivityN0 := 10^(-9):

nStepsN0 := 10:

NULL

N0Min := 1*fractionFactor:

N0Max := nStepsN0*sensitivityN0+N0Min:

NULL

sensitivityR := .5:

nStepsR := 8:

NULL

rMin := 1:

rMax := nStepsR*sensitivityR+rMin:

 

NULL

N := Array(1 .. tMax, 1 .. nStepsR, 1 .. nStepsN0, datatype = float[8]):

NULL

NULLNULL

for indexN0 to nStepsN0 do for indexR to nStepsR do r := indexR*sensitivityR+rMin; for t to tMax-1 do if t = 1 then N[t, indexR, indexN0] := indexN0*sensitivityN0+N0Min end if; N[t+1, indexR, indexN0] := r*N[t, indexR, indexN0]*(1-N[t, indexR, indexN0]) end do end do end do:

    NULL

pal := ColorTools:-GetPalette("Dalton"):
    NULL

display(fixed_r_stable_plots, view = -.2 .. 1.2, gridlines = false);

``

 

``

Download MapleS_test6_b.mw

 

Another way to handle this whole business is the use the `plot` command. Suppose that we knew that each increment of the first index of N (1 to tMax) represented 3 seconds. In that case you could form a reusable 1D column Vector of time values, and conjoin it with each 1D column Vector of height values (eg, N[..,r,1] for fixed r, changed from 1D Array to column Vector). This way, there is no need to create custom tickmarks.


restart

"# Pathology problem for a population, N[t], of  cells:     N[t+1]  = r*N[t]*(1-N[t])      where N is normalized to represent the fraction of cells that can be contained in the culture vessel used, and r is the growth rate of the  cells (assumed to be constant for all clones)."
NULL

 

# Interactive package management: make the short form names of the commands of a Maple package available at the interactive level

with(plots):NULLNULL

 

""# Set the simulation length""

tMax := 50:NULLNULL

NULL

NULL

rMax := 5:NULL

NULL

fractionFactor := 10^(-5):NULL

sensitivityN0 := 10^(-9):

nStepsN0 := 10:

NULL

N0Min := 1*fractionFactor:

N0Max := nStepsN0*sensitivityN0+N0Min:

NULL

sensitivityR := .5:

nStepsR := 8:

NULL

rMin := 1:

rMax := nStepsR*sensitivityR+rMin:

 

NULL

N := Array(1 .. tMax, 1 .. nStepsR, 1 .. nStepsN0, datatype = float[8]):

NULL

NULLNULL

for indexN0 to nStepsN0 do for indexR to nStepsR do r := indexR*sensitivityR+rMin; for t to tMax-1 do if t = 1 then N[t, indexR, indexN0] := indexN0*sensitivityN0+N0Min end if; N[t+1, indexR, indexN0] := r*N[t, indexR, indexN0]*(1-N[t, indexR, indexN0]) end do end do end do:

    NULL

tvals := Vector(1 .. tMax, proc (i) options operator, arrow; 3.0*(i-1) end proc):

pal := ColorTools:-GetPalette("Dalton"):
    NULL

fixed_r_stable_plots := [seq(plot(Matrix([tvals, Vector[column](N[1 .. tMax, r, 1])]), opts, color = pal[r]), r = 1 .. nStepsR)]:

display(fixed_r_stable_plots, view = -.2 .. 1.2, gridlines = false);

``

 

``

NULL

NULL

Download MapleS_test6_c.mw

I hope that at least gives you some ideas for handling this.

acer

There are various ways to get what you want, according to whether your `g` is itself an operator or an expression.

But don't do the last one below, if you can avoid it. The reason is that it calls `diff` every single time you call `fp1`.

restart:
f := x -> g(x):

f(1);
                                    g(1)

fp1 := unapply( diff(g(x),x), x );
                                 fp1 := D(g)

fp1(1);
                                   D(g)(1)


restart:
g := x -> sin(x):
f := x -> g(x):

f(1);
                                   sin(1)

fp1 := unapply( diff(g(x),x), x );
                             fp1 := x -> cos(x)

fp1(1);
                                   cos(1)

restart:
g := sin(x):
f := unapply(g, x):

f(1);
                                   sin(1)

fp1 := unapply( diff(g,x), x );
                             fp1 := x -> cos(x)

fp1(1);
                                   cos(1)

restart:
g := sin(x):
f := unapply(g, x):

f(1);
                                   sin(1)

fp1 := D(f);
                                 fp1 := cos

fp1(1);
                                   cos(1)

restart:
g := x -> sin(x):
f := x -> g(x):

f(1);
                                   sin(1)

fp1 := X -> eval(diff(g(x),x), x=X);
                                      / d             \
                      fp1 := X -> eval|--- g(x), x = X|
                                      \ dx            /

fp1(1);
                                   cos(1)

acer

If you don't mind the fact that min(X) walks all of X once, and Search(...,X) can potentially walk it all a second time, then it seems as simple as doing,

minX := min(X):
loc_minX := ListTools:-Search(minX,X):
minX, W[loc_minX], W[loc_minX+1];

acer

If you want both arguments to be evaluated before being passed then how about just,

eval( 'CodeTools:-Test'(f(1), y) );

acer

You forgot to use := in your assignment to `a`. You used just an = sign by mistake, which just forms an equation and doesn't assign anything.

You may have intended,

a:=k-m*L;

acer

For this example you could set Normalizer:=simplify which appears to avoid so-called hidden zeroes while pivoting as well as keep the reduced row entries in check.

The default of Normalizer = normal is well-suited to entries all as rational polynomials. Using simplify is a big hammer, but figuring out the smallest hammer that will suffice is difficult in general.

acer

The "alloc" means allocated by the kernel. In Maple 18 the kernel can actually free memory to the OS when doing garbage collection, so that number can now go both up and down. In recent versions the kernel will also free memory to the OS on `restart`, at which point this number reverts to the size of memory allocated at kernel launch and initialization.

The "used" figure is an indicator of how much memory has being processed by the garbage collection mechanism. It's similar to a running total of size of memory of objects (no longer referenced) and reclaimed for re-use by the kernel. Since the same bits of memory may be reclaimed and re-used over and over, that running total can be a number much higher than the total memory of the machine. Also, this value is not reset to zero upon `restart`.

I suppose that you know that you can turn these messages off in the CLI, using kernelopts(printbytes=false) .

acer

S:= Array( 1..4, -6..3, 1..5 );

And use whatever ranges for the indices that you'd like. 

acer

In 2D Math input mode try typing it in with the keystrokes for & then \ and then ^ in order to escape the caret.

[edited] Oh, it seems there is a mention of this as an item lower down in the table for 2DMathShortcutKeys.

acer

Are you looking for purely real solutions?

Unless I transcribed something wrong when changing 45.5 to exact 91/2 then I don't quite see how there can be any purely real solution to the system.

Problem_7_Instructor_4_rat.mw

acer

Could it be converted from set to logic notation? I wonder... how. (How best, I suppose. `subs` might suffice.)

restart:                                                                   

with(Logic):

Equivalent( (A &and &not B) &and (A &and &not C), A &and &not (B &or C ) );

                                     true

So, if that is acceptable, how could this be improved,

restart:                                                        
ee := (A minus B) intersect (A minus C) = A minus (B union C):  
ff := subsindets( subs( `union`=`&or`, `intersect`=`&and`, ee ),
                  specfunc(`minus`),                            
                  z->op(1,z) &and &not op(2,z) ):               
evalindets( ff, `=`, z->Logic:-Equivalent(op(z)) );             

                                     true

I have a hazy recollection that this sort of question might have been asked before on this site.

acer

For Matrix M, you can do it with,

map( convert, M, exp);

acer

I don't really understand how you have (or have not) defined M[n+1], as expressions or operators, etc. But just using the expression you gave, here are some ideas for a multidimensional Array and plotting slices of it.

I used Maple 18, FWIW.

restart:

for n from 1 to 10 do
  R[n]:=n^2;
end do:

A:=Array( 1..10,1..10,1..5,1..2,
          (n,b,theta,m) -> (b*(theta^m)*R[n])/((theta^m)+R[n]^m)
          , datatype=float[8]  # only if it evaluates to floats
         ):

with(plots):

opts := transparency=0.3, style=surface:
all_fixed_m_plots := [ seq( surfdata(A[n,..,..,1], 1..10, 1..5,
                               labels=["b", "theta_m", "n"],
                               opts, color=COLOR(HUE,n/10)),
                      n=1..10 ) ]:

display( all_fixed_m_plots );
all_b_m_plots := [ seq( [ seq( surfdata( A[..,..,b,m],
                                         caption=sprintf("b=%a m=%a",b,m) ),
                               m=1..2 ) ], b=1..5 ) ]:

display(Array( all_b_m_plots ));

display(Array([
    surfdata(A[..,..,3,1]),
    surfdata(A[..,7,..,2]),
    surfdata(A[..,3,5,..])
              ]));
# The following are animations. Click on them and then use the menubar to play.
plots:-animate(plots:-surfdata,[ 'A[i,..,..,1]' ], i=[$1..10]);
plots:-animate(plots:-surfdata,[ 'A[..,..,i,1]' ], i=[$1..5]);
plots:-animate(plots:-surfdata,[ 'A[..,i,..,2]' ], i=[$1..10]);
plots:-animate(plots:-surfdata,[ 'A[..,3,..,i]' ], i=[$1..2]);

acer

First 234 235 236 237 238 239 240 Last Page 236 of 336