250 Reputation

4 Badges

1 years, 73 days

MaplePrimes Activity

These are replies submitted by zenterix

@dharr This is a useful command, just not for the issue being asked about. 

To repeat the issue: you create an .mpl file and save it and in the code in this file you want to be able to access the absolute location of the file itself (no matter where the file is run from, whether in a saved worksheet, a non-saved worksheet, or Maple command line mode where there isn't a worksheet).

This means that you can open a new worksheet in Maple (not even save it), and from that worksheet you can run the .mpl file and the file will be able to access its own absolute path.

It also means you can just read the .mpl file from Maple command line mode and the file will be able to access its own absolute path.

@PeterTang This was a while ago so I don't remember very precisely but I don't think I found the optimal solution to this problem.

Luckily, I was working with only one other person, so I used absolute paths based on the particular user of the file I was running. Not ideal at all, but it worked.

And to repeat the issue: you create an .mpl file and in this file you want to be able to access the absolute location of the file itself. This means that you can open a new worksheet in Maple (not even save it), and from that worksheet you can run the .mpl file and the file will be able to access its own absolute path.

@acer Using the "grid" option (for example, grid=[1000,1000]) does not produce a vastly superior result and manipulating the plot becomes super slow on my computer.

The plot you generated looks good, but the required command to achieve this is not user friendly. 

Do any of the alternative ways involve a more automated process of achieving a plot similar to the one you generated above with the laborious process of splitting up the surface?

We know about the ridge because of manual calculations. What if we did not do any calculations and wished to see an accurate depiction of the graph of a function?

Ie, is the blue output some kind of default output?


@Carl Love 

libname returns the correct result, as does with(MyPackage).

Things seem to work now. One source if initial confusion was the following:

- the prompt is ">"

- if you type in a command and don't put a semicolon, all you get is another prompt below but no indication that Maple is waiting for you to complete the command with a semicolon.

- thus, if in the new prompt you think "what happened?" and try to type in a new command you will get an error, and it will snowball from there.

One question I have about using the console is that it prints out memory used, alloc, and time.

Where can I find more information about what this information is telling me exactly?

When I search the help files for "command line mode" I don't see a dedicated page for that mode (I'd like to know, for example, how to abort a running command)

@nm I save data to files when I have results that I know will be useful later.

Sometimes I am working on something, and would like to make some small change to a procedure. I have a big matrix I would like this procedure to operate on after changing the procedure.

Yes I could save the matrix and read it.

But I imagine there is a way to forget what was imported so I can import it again.

@Carl Love no output at all (if this were in the worksheet I would be sure nothing was imported). Is there some unique initialization file for the CLI that tells it where to look for packages that is different from the one worksheets use?


Here are the steps I took to try to find the answer to this question.

1) Google "maple 3d plot lighting".

2) The first entry is a Maple page with the title "Change Lighting". The main content shows how to change lighting using the context menu. There are two links: "Lighting Schemes" and "Changing Lighting". After clicking I realize they are links to the content below.

On the right-hand side are other links but it is not clear which, if any, will be useful for this task. I settle for the link "plot3d/options".

3) I search the new page ("Options for 3-D Plots") for "lighting". There is one result, inside the option "ambientlight", which is set with a list [r, g, b]. I tried in Maple with [0, 0, 0] and [1, 1, 1]. 

I just noticed that this works (before I asked this question I tried out this command, but I tried with values [255, 255, 255], unfortunately. [1,1,1] works perfectly.

After reading the answers above, I searched for "light" and found "lightmodel". This is the actual desired solution based on the experience with the UI.

Honestly, though, one should be able to search for "lighting", just as it appears in the UI context menu. 

Everyone is different. That's why building a UI is such a mix of science and art form. Making it simple and elegant and useful for all users to find what they want. Writing documentation, I would argue, is the same way.

@acer Do you think it would be a worthwhile side project to write a library for matrix manipulation? Or is there already one and I am not aware of it?

There are all sorts of matrix manipulations that one could want to do, as we see with, for example pandas and numpy in python.

For example, how do we obtain a new matrix with the rows sorted based on a specific column?

@acer Here is my solution putting everything you've described together


read "./matrix.m"

First let's do two test cases










surfM1 := `<,>`(seq(`<|>`(seq(m1[i][3], i=j..10200, 120)), j=1..120)):


120, 85


plots:-surfdata(surfM1, min(m1[..,1])..max(m1[..,1]), min(m1[..,2])..max(m1[..,2]), dimension=2, style=surface, colorscheme=["zgradient", ["Red", "Magenta"], colorspace="HSV"])


Here is a similar case, but now the first column has a step of 0.5.

read "./m2.m"




maxColumn1 := max(ch2[..,1])



step := ch2[1,1]



surfCh2 := `<,>`(seq(`<|>`(seq(ch2[i][3], i=j..17400, trunc(maxColumn1/step))), j=1..trunc(maxColumn1/step))):


600, 29





plots:-surfdata(surfCh2, min(ch2[..,1])..max(ch2[..,1]), min(ch2[..,2])..max(ch2[..,2]), dimension=2, style=surface, colorscheme=["zgradient", ["Red", "Magenta"], colorspace="HSV"])



Vector[row](2, {(1) = 17400, (2) = 3})


Here is a procedure that does everything in one go.

plotDensity := proc(arr)
  local rows, maxColumn1, minColumn1, maxColumn2, minColumn2, step, xPoints, surfM, i, j:
  rows := ArrayTools:-Size(arr)[1]:
  maxColumn1 := max(arr[..,1]):
  minColumn1 := min(arr[..,1]):
  maxColumn2 := max(arr[..,2]):
  minColumn2 := min(arr[..,2]):
  step := arr[2,1] - arr[1,1]:
  xPoints := trunc(maxColumn1/step):
  surfM := `<,>`(seq(`<|>`(seq(arr[i][3], i=j..rows, xPoints)), j=1..xPoints)):
  plots:-surfdata(surfM, minColumn1..maxColumn1, minColumn2..maxColumn2, dimension=2, style=surface, colorscheme=["zgradient", ["Red", "Magenta"], colorspace="HSV"])










Download DensityPlot.mw

Here are the compressed files with the matrices: DensityPlot.zip


Yes the data is structured in a simliar way. For example, the first column has rows that go from, say, 1 to 10 twelve times. The first values x from 1 to 10 are associated with some value y1 in the second column.

The second values x 1 to 10 are associated with some value y2 in the second column.

And so on.

The value in the third column represents f(x,y).

I agree that spending the time to format the matrix/array in a way that works with, say, surfdata is best. 

It's just that there is no top-level easy manipulation of array/matrix in Maple. Everything has to be done with these convoluted commands (as opposed to libraries in other languages). 

I will try now.

@acer Is there a way to set the range for the x-axis when using listdensityplot?

Below is an example, based on your worksheet above.

Note that with plots:-surfdata I can set the range (the x values go from 0.5 to 300 with a step of 0.5). listdensityplot shows a range of 1 to 600. I can't figure out how to set this range from the documentation.


currentdir(cat(kernelopts(homedir), "/mapleprimes")):

convertArrayToTable := proc(arr)
        local m, t, i, c1, c2, c3:
        m := ArrayTools:-Size(arr)[1]:
        t := table([]):
        for i from 1 to m do:
                c1 := arr[i,1]:
                c2 := arr[i,2]:
                c3 := arr[i,3]:
                if not assigned(t[HFloat(c1)]) then:
                        t[HFloat(c1)] := table([ HFloat(c2) = c3]):
                        t[HFloat(c1)][HFloat(c2)] := c3:
        return eval(t);


read "./m2.m":
m1 := Matrix(ch2,datatype=float[8]):





T := convertArrayToTable(m1):

TIndices := [indices(T,nolist)]:

TI := sort([indices(T[HFloat(1)],nolist)]):











Download table-hfloat_ac.mw

@acer Thanks, I will go with the simplest option for now. I need time to learn about some of the syntax in the other options.

@acer Ok, no problem, I've added my new question as a new comment to this thread.

Before going into details, here is a quick version of my question: I have a density plot that has incorrect display (the two red streaks) because data is not being read correctly for two specific keys in a table:

Those two red streaks are incorrect. 

I did a bit of debugging and I found what the issue is. My current question, and the reason for this post, is about why the issue is happening. It has to do with accessing values from a table where the keys are of type HFloat.

I will now try to succintly describe the issue, but I have also created a worksheet that reads the matrix with the data for the density plot above, converts the matrix to a table, and then creates the density plot. 

These files can be access in a Github repo I created, or as a .zip file attached to this post: table-hfloat.zip


A couple weeks ago, the original question in this entire thread was about how to take an n x 3 matrix and "convert" it to a nested table. Let me recall briefly what this table looks like.

In the outer table, the first column of the matrix are the keys.

This first column can have repeated elements. For each such key, the associated value is a table. This inner table contains as keys the values from the second column of the matrix that have the outer key as the first column in the matrix.

The values associated with each inner key is just the value in the third column of the matrix.

Now, in my other question, I was having trouble with this, but the issue was that the inner keys were floating point numbers. To make the creation of this table work, I converted all keys to HFloat. Then, when accessing keys in the table, I would also type cast to HFloat.

For example, let's say the table is called T and in the matrix there is a row with values 50, 0.95, 3 and another row with values 50, 0.945, 4.

Then we should be able to access T[HFloat(50)][HFloat(0.95)] and get 3, and T[HFloat(50)][HFloat(0.9450)] and get 4.

For the record, each row represents x, y, and z coordinates. 

The points represented by the first two columns form a grid. 

The Issue

I created a simple procedure that takes x and y values and returns T[HFloat(x)][HFloat(y)]. I then pass this procedure to plots:-densityplot so that it can get the values it needs.

This works perfectly, except that for some reason there are two inner keys that don't work: 0.945 and 0.9925.

From the density plot pictured above, you can see that the grid is for values of x between 0 and 120, and values of y between 0.90 and 1.11. Every single access of the table works except at values of y of 0.945 and 0.9925, and this is why we get those two red streaks.

I confirmed this by printing out every single attempt at accessing the table.

Why the heck does the access not work for these two values? The linked repo contains all the actual computations in Maple.

One more thing. Weirdly, this works: T[HFloat(50)][HFloat(0.9450000000)]

Ie, I deleted five zeros from the end of the number.

HFloat(0.945000000000000) and HFloat(0.9450000000) seem to produce the same result in Maple.


evalb(HFloat(0.945000000000000) = HFloat(0.9450000000))

results in false, even though if I change the 4 to a 7 then it results in true. 

1 2 3 4 5 6 Page 1 of 6