## How to plot a prettier bifurcation diagram using M...

Dear All,

The following code plots the bifurcation diagram for a three-dimensional continuous dynamical system as a variable Re varies. However, the resulting plot (by pointplot command) is rather ugly, comparing with other bifurcation diagrams, see attached. Could anyone point me out how to improve its looking?

 > restart: with(plots): with(DEtools): with(plottools):with(LinearAlgebra): doSol:=proc( R )              local t_start:=2500,                    t_end:=5000,                    b:=-3,                    c:=3,                    v1:=1,                    f:=-4,                    v2:=2.0,                    omega:=0.1*sqrt(R),                    epsilon:=evalf(1/R),                    k:=0.1,                    kH:=(c+1)/(b-1),                    sys, evs, w, M, T, i, tt, solA, N_alpha,                    r_center, z_center, Zshift, alpha, alpha1,                    alpha2, del_alpha, m, Z, Rshift, RR;              sys:=diff(u1(t),t)=v1*u1(t)-(omega+k*u2(t)^2)*u2(t)-(u1(t)^2+u2(t)^2-b*z(t)^2)*u1(t),                   diff(u2(t),t)=(omega+k*u1(t)^2)*u1(t)+v1*u2(t)-(u1(t)^2+u2(t)^2-b*z(t)^2)*u2(t),                   diff(z(t),t)=z(t)*(kH*v1+c*u1(t)^2+c*u2(t)^2+z(t)^2)+epsilon*z(t)*(v2+f*z(t)^4):              solA:=dsolve({sys, u1(0)=0.6, u2(0)=0.6, z(0)=0.1},                           {u1(t),u2(t),z(t)},                           numeric, method=rkf45, maxfun=10^7,                           events=[[[u1(t)=0, u2(t)>0], halt]]                          );              evs:=Array():              evs(1,1..4):=Array([t,u1(t),u2(t),z(t)]);              interface(warnlevel=0):              for i from 2 do                  w:=solA(t_end):                  if   rhs(w[1])=t_start                  then break;                  end if;              end do:              RR:=M[i..,3]: Z:=M[i..,4]:              N_alpha:=numelems(RR):              r_center:=add(RR[i],i=1..N_alpha)/N_alpha:              z_center:=add(Z[i],i=1..N_alpha)/N_alpha:              Zshift:=Z-~r_center: Rshift:=RR-~z_center:              alpha:=(arctan~(Zshift/~Rshift)+(Pi/2)*sign~(Rshift))/~(2*Pi)+~0.5:              return alpha;   end proc:
 > i_start:=125: i_end:=250: i_delta:=0.1: M:=[seq( [j, doSol(j)], j=i_start..i_end, i_delta)]:
 > S:=seq([Vector(numelems(M[i,2]),fill=M[i,1]),M[i,2]], i=1..numelems(M),1): display(seq( pointplot(S[i],              symbolsize=1,              symbol=point) ,              i=1..numelems(M)),              axes=boxed,              view=[i_start..i_end,0..1],              size=[650,400],              axesfont= ["TimesNewRoman", 16],              labels=["Re",phi[n]],              labelfont = ["TimesNewRoman", 16],              labeldirections=[horizontal, vertical]);

Bifurcation_diagram.mw

Thank you.

Very kind wishes,

Wang Zhe

## How to do a color inversion in maple...

How can I do a color inversion on a jpg image in Maple?

## can Maple read and write png image files?...

and

http://www.maplesoft.com/support/help/maple/view.aspx?path=ImageTools%2fFormats

it seems to only support jpeg,tiff,bmp.

This seems like something from 1980's days. Is there another package to load other image formats? Such as png for example, and to export as png?

I'd like to import png file, rescale it in Maple (make thumbnail image) and export it again.

I am using 18.1 on windows 7

## Image Processing Toolbox

by: Maple
Dear Colleagues,Surfing the web I found several applications in MatLab, which perform image processing. One of them caught my attention and challenge to reproduce in Maple.I attached the text of the original application and my attempt to play in Maple. I ask you your guidance, support and intervention to reproduce as faithfully as possible the original application. It was impossible on the final image point to the center of the circle and draw.I believe that together we can achieve...

## images on surfaces

by: Maple

Let's see how we can display patterns, or even images, on 3D plot surfaces. Here's a simple example.

The underlying mechanism is the COLOR() component of a POLYGONS(), GRID(), or MESH() piece of a PLOT3D() data structure. (See here, here, and here for some older posts which relate to that.)

The data stored in the MESH() of a 3D plot structure can be a list-of-lists or, more efficient, an Array. The dimensions of that Array are m-by-n-by-3 where m and n are usually the size of the grid of points in the x-y plane (or of points in the two independent parameter spaces). In modern Maple quite a few kinds of 3D plots will produce a GRID() or a MESH() which represent the m-by-n independent data points that can be controlled with the usual grid=[m,n] option.

The plot,color help-page describes how colors may specified (for each x-y point pair to be plotted) using a procedure f(x,y). And that's fine for explicit plots, though there are some subtleties there. What is not documented on that help-page is the possibility of efficiently using an m-by-n-by-3 or an m*n-by-3 datatype=float[8], order=C_order Array of RGB values or am m*n float[8] Vector of hue values to specify the color data. And that's what I've been learning about, by experiment.

A (three-layer, RGB or HSV) color image used by the ImageTools package is also an m-by-n-by-3 Array. And all these Arrays under discussion have m*n*3 entries, and with either some or no manipulation they can be interchanged. I wrote earlier about converting ImageTools image structures to and from 2D density-plots. But there is also an easy way to get a 3D density-plot from an ImageTools image with a single command. That command is ImageTools:-Preview, and it even has a useful options to rescale. The rescaling is often necessary so that the dimensions of the COLOR() Array in the result match the dimensions of the grid in the MESH() Array.

For the first example, producing the banded torus above, we can get the color data directly from a densityplot, without reshaping/manipulating the color Array or using any ImageTools routines. The color data is stored in a m*n Vector of hue values.

But first a quick note: Some plots/plottools commands produce a MESH() with the data in a list-of-lists-of-lists, or a POLYGONS() call on a sequence of listlists (eg. `torus` in Maple 14). For convenience conversion of the data to a 3-dimensional Array may be done. It's handy to use `op` to see the contents of the PLOT3D() structure, but a possible catastrophe if a huge listlist gets printed in the Standard GUI.

```restart:
with(ImageTools):with(plots):with(plottools):
N:=128:

d:=densityplot((x,y)->frem((x-2*y),1/2),0..1,0..1,
colorstyle=HUE,style=patchnogrid,grid=[N,N]):
#display(d);

c:=indets(d,specfunc(anything,COLOR))[1];

/     [ 1 .. 16384 Vector[column] ]\
|     [ Data Type: float[8]       ]|
c := COLOR|HUE, [ Storage: rectangular      ]|
\     [ Order: C_order            ]/

T:=display(torus([0,0,0],1,2,grid=[N,N]),
style=surface,scaling=constrained,axes=none,
glossiness=0.7,lightmodel=LIGHT3):
#op(T); # Only view the operands in full with Maple 16!

# The following commands both produce the banded torus.

#op(0,T)(MESH(op([1,1..-1],T),c),op([2..-1],T)); # alternate way, M16 only

subsop([1,1]=[op([1,1],T),c][],T);
```

Most of the examples in this post use the command `op` or `indets` extract or replace the various parts of of the strcutures. Perhaps in future there could be an easy mechanism to pass the COLOR() Array directly to the plotting commands, using their `color` optional parameter.

In the next example we'll use an image file that is bundled with Maple as example data, and we'll use it to cover a sphere. We won't downsize the image, so that it looks sharp and clear (but note that this may make your Standard GUI session act a bit sluggish). Because we're not scaling down the image we must specify a grid=[m,n] size in the plotting command that matches the dimensions of the image. We'll use ImageTools:-Preview as a convenient mechanism to produce both the color Array as well as a 3D densityplot so that we can view the original image. Note that the data portion of the sphere plot structure is an m-by-n-by-3 Array in a MESH() which matches the dimensions of the m-by-n-by-3 Array in the COLOR() portion of the result from ImageTools:-Preview.

```restart:
with(ImageTools):with(plots):with(plottools):

p:=Preview(im):

op(1,p);

/                    [ 235 x 354 2-D  Array ]
|                    [ Data Type: float[8]  ]
GRID|0 .. 266, 0 .. 400, [ Storage: rectangular ],
\                    [ Order: C_order       ]

/     [ 235 x 354 x 3 3-D  Array ]\\
|     [ Data Type: float[8]      ]||
COLOR|RGB, [ Storage: rectangular     ]||
\     [ Order: C_order           ]//

q:=plot3d(1, x=0..2*Pi, y=0..Pi, coords=spherical, style=surface,
grid=[235,354]):

display(PLOT3D(MESH(op([1,1],q), op([1,4..-1],p)), op(2..-1,q)),
orientation=[-120,30,160]);
```

## ImageTools and densityplot

by: Maple

Many of us know that issuing plotting commands produces various kinds of plot data structure, the details of which are documented on the plot,structure help-page. That page covers most of the details, and a thorough read can reveal that the numeric data of a plot is often stored within such structures as either Array or Matrix.

But what about the result of a call to

## Matrix/Array access: order can be important

by: Maple

Way back in Maple 6, the rtable was introduced. You might be more familiar with its three types: Array, Matrix, and Vector. The name rtable is named after "rectangular table", since its entries can be stored contiguously in memory which is important in the case of "hardware" datatypes. This is a key aspect of the external-calling mechanism which allows Maple to use functions from the NAG and CLAPACK external libraries. In essence, the contiguous data portion of a hardware datatype rtable can be passed to a compiled C or Fortran function without any need for copying or preliminary conversion. In such cases, the data structure in Maple is storing its numeric data portion in a format which is also directly accessible within external functions.

You might have noticed that Matrices and Arrays with hardware datatypes (eg. float[8], integer[4], etc) also have an order. The two orders, Fortran_order and C_order, correspond to column-major and row-major storage respectively. The Wikipedia page row-major  explains it nicely.

There is even a help-page which illustrates that the method of accessing entries can affect performance. Since Fortran_order means that the individual entries in any column are contiguous in memory then code which accesses those entries in the same order in which they are stored in memory can perform better. This relates to the fact that computers cache data: blocks of nearby data can be moved from slower main memory (RAM) to very fast cache memory, often as a speculative process which often has very real benefits.

What I'd like to show here is that the relatively small performance improvement (due to matching the entry access to the storage order) when using evalhf can be a more significant improvement when using Maple's Compile command. For procedures which walk all entries of a hardware datatype Matrix or multidimensional Array, to apply a simple operation upon each value, the improvement can involve a significant part of the total computation time.

What makes this more interesting is that in Maple the default order of a float[8] Matrix is Fortran_order, while the default order of a float[8] Array used with the ImageTools package is C_order. It can sometimes pay off, to write your for-do loops appropriately.

If you are walking through all entries of a Fortran_order float[8] Matrix, then it can be beneficial to access entries primarily by walking down each column. By this I mean accessing entries M[i,j] by changing i in ther innermost loop and j in the outermost loop. This means walking the data entries, one at a time as they are stored. Here is a worksheet which illustrates a performance difference of about 30-50% in a Compiled procedure (the precise benefit can vary with platform, size, and what else your machine might be doing that interferes with caching).

Matrixorder.mw

If you are walking through all entries of an m-by-n-by-3 C_order float[8] Array (which is a common structure for a color "image" used by the ImageTools package) then it can be beneficial to access entries A[i,j,k] by changing k in the innermost loop and i in the outermost loop. This means walking the data entries, one at a time as they are stored. Here is a worksheet which illustrates a performance difference of about 30-50% in a Compiled procedure (the precise benefit can vary with platform, size, and what else your machine might be doing that interferes with caching).

Arrayorder.mw

## work with images in Maple...

With the command, subpicture,I take the portion of it that interests me.
How I manage to include this sub-image in another image (img)?

Preview(correctedT)

imgs := GetSubImage(correctedT, 100, 125, 20, 120)
Preview(imgs)

## logistic map example

by: Maple

Here's an example exhibited by Nusc, which I have tweaked slightly to make it look more like your mathematica example.

### Reference: http://www.mapleprimes.com/questions/36580-Bifurcation-Diagram

### xexpr is the logistic function to be iterated (we always start off at x=1/2, which will eventually attract).
### [ra,rb] is the range of the parameter.
### acc is the number of points sampled in [ra,rb]

Bifurcation := proc(initialpoint,xexpr,ra,rb,acc)

## ImageTools for complex (argument ) plot

by: Maple

The complexplot3d command can color by using (complex) argument for the hue, and compute height z by magnitude. So, when rotated to view the x-y plane straight on, it can provide a nice coloring of the argument of whatever complex-valued expression is being plotted.

Another way to obtain a similar plot is to use densityplot (with appropriate values for its scaletorange option) and apply argument to the expression or function being plotted. For some kinds of complex-valued...