acer

9 years, 29 days


These are answers submitted by acer

idea

20 hours ago acer 10426
1 1

I suppose that for you it is key that you can programmatically determine the situation after calling `solve`. So Warning and userinfo messages are not of direct use there.

But in the case of the "solutions may have been lost" warning an assignment is made to the name _SolutionsMayBeLost, and you can test for that.

restart:

P := proc()
  local ans;
  # First, clear the flag.
  :-_SolutionsMayBeLost := ':-_SolutionsMayBeLost';
  ans := solve(args);
  if ans=NULL then
    if _SolutionsMayBeLost=true then
      return FAIL; # indeterminate case
    else
      return false; # `solve` thinks no solution exists
    end if;
  else
    return ans;
  end if;
end proc:

P( {y-x=0,y-x=1} );

                             false

P( {a+r*t*ln(l)+(1-l)^2*m-b-r*t*ln(s)-(1-s)^2*n = 0,
    a+r*t*ln(1-l)+l^2*m-b-r*t*ln(1-s)-s^2*n = 0},
   {l, s} );

                              FAIL

This kind of thing (possibly tweaked), is my best guess at what will serve your need here.

Opinions welcome, whether it makes any sense to try to save the inbound value of _SolutionsMayBeLost, do the work inside a try..catch, and then restore that value in a `finally` clause.

acer

statement terminators

Yesterday at 1:58 PM acer 10426
0 0

For starters, you will need a semicolon statement terminator on the line preceding the while. In both 1D and 2D input modes it is invalid without that.

Next, the error message along with this code are a hint that you are using 2D Math input. The 2D Math input parser is picky. If I added semicolon terminators to all the lines immediately preceding end if statements, and if I also ensured that there was at least one space between any if and the round bracket your code immediately follows with (as separator), then I could execute the code without any parsing error in both Maple 17.01 and 18.01.

acer

16.01

Yesterday at 10:36 AM acer 10426
1 0

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

legend

Yesterday at 5:41 AM acer 10426
0 0

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

some ideas

Yesterday at 4:38 AM acer 10426
0 0

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

various ways

October 29 2014 acer 10426
3 0

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

Search

October 28 2014 acer 10426
1 1

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

eval?

October 28 2014 acer 10426
0 0

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

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

acer

assignment

October 28 2014 acer 10426
0 6

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

hidden zeroes

October 27 2014 acer 10426
1 3

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

alloc vs used

October 27 2014 acer 10426
2 1

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

Array

October 25 2014 acer 10426
0 0

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

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

acer

backslash

October 24 2014 acer 10426
0 1

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

real solutions?

October 21 2014 acer 10426
0 0

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

Logic

October 20 2014 acer 10426
2 2

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

1 2 3 4 5 6 7 Last Page 1 of 101