acer

32333 Reputation

29 Badges

19 years, 322 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@nscheng There is no option to put the usual legend inside the plot's axes, no.

But you can fake it by adding a textplot and short section of similarly colored curve, etc.

@Thomas Dean I used ubuntu Linux.

Your original Question and the attached worksheet both contain no mention of using the maplet plot driver.

I answered that it worked for me before you mentioned the maplet plot driver.

note: This problem might be new in Maple 2022.

Here is another approach. It is simpler, more reliable, and more flexible.

It removes altogether the dubious mixture of turning the original data into a table and then hoping that densityplot will sample at exactly the right floating-point values.

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

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

MM:=`<|>`(seq(m1[1+120*(i-1)..120+120*(i-1),3],i=1..85)):
V1:=m1[1..120,1]:
V2:=<seq(m1[1+120*(i-1),2],i=1..85)>:

F := Interpolation:-SplineInterpolation([V1,V2],MM,method=linear):
plots:-densityplot((x,y)->F(x,y), 1 .. 120, 0.9 .. 1.11,
                   colorstyle=HUE, style=surface);

If you want you could also add the grid=[121,86] option to densityplot. Since this is now interpolating, and no longer tied directly to the data values, you could also experiment with some other grid option values.

The above looks somewhat reasonably smooth. For other examples you might adjust some options to the Interpolate command (eg. cubic rather than linear, though slower).

You could also use that Matrix MM directly with the surfdata command, in the way I showed above. That is quite fast.

So it took a few moments to concoct a further adjustment to the original, using the same kind of approach.

restart;

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(evalf[8](SFloat(c2))) = c3]):
                else:
                        t[HFloat(c1)][ HFloat(evalf[8](SFloat(c2))) ] := c3:
                end:
        end:
        return eval(t):
end:``

read "./matrix.m"

T := convertArrayToTable(m1):

f := proc(x,y)
  global T:
  return T[HFloat(x)][ HFloat(evalf[8](SFloat(y))) ]:
end:

plots:-densityplot(f, 1 .. 120, 0.9 .. 1.11, grid = [121, 86],
                   style=surface, colorstyle = HUE, color = red)

NULL

Download table-hfloat_acc.mw

I'm not a fan of this particular densityplot approach -- and this might well end up being just as fragile.

@zenterix 

I suspect that the problem has something to do with how densityplot is constructing the x-y values. Any deviation in how it constructs, say, the y-values and you could get a slightly different value (float or HFloat, it hardly matters) and a mismatch with the indices of the inner tables. It seems like a fragile idea to try and match those values with more than one routine that splits the range. I think that I won't bother to try and further adjust that methodology.

Instead of relying of densityplot to get a precise match in the index values, you could turn the tables in T into Vectors, ie. turn all of T into a Matrix. In this way the actual indices are re-used to access the inner entries, with no mismatch.

You could then plot that Matrix using listdensityplot or surfdata.

restart;

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]):
                else:
                        t[HFloat(c1)][HFloat(c2)] := c3:
                end:
        end:
        return eval(t);
end:

 

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

 

T := convertArrayToTable(m1):

 

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

MMM:=`<,>`(seq(`<|>`(seq(T[ii][vv],
                         vv=sort([indices(T[ii],nolist)]))),
               ii=sort([indices(T,nolist)]))):

 

plots:-listdensityplot(MMM,colorstyle=HUE,style=surface,
                       ytickmarks=[1=TI[1],seq(10*i=TI[10*i],
                                               i=1..iquo(nops(TI),10))]);

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

 

NULL

Download table-hfloat_ac.mw
 

note: If the Matrix m1 has its entries arranged in an orderly fashion (ie. sorted wrt to both 1st and second columns -- I didn't bother to check) then the Matrix I used to plot could be constructed more directly, without need for all this table business. Or unprovided process which generates the m1 Matrix could be adjusted to construct the Matrix I used just above for plotting.

The Matrix MMM above, and Vectors of the common x- and y-values, could be used to build an interpolating procedure. That could be used to provide a smoother gradient of color. It could also be used with densityplot.

It works for me (not a blank plot), using Maple 2022.2.

Please don't put a close followup query on this topic in a wholly separate and new Question thread.

You could put it in a Reply here, or use the Branch button to connect them.

Your can zip up a .m file and then attach that in this forum.

@Rouben Rostamian  It's not a matter of Worksheet vs Document. It's a matter of the choice of input mode.

Inside text mode (after Crtl-t, say), one can direct enter the "approx" entry from the Common Symbols palette.

Inside text mode (after Crtl-t, say), one can also enter Ctrl-r and switch to 2D Math input mode, and then back to text if wanted. In Maple 2022 one may need to select the entered math use the right-click menu to convert to non-executable math, however.

restart;

# This is a Worksheet.

 

I entered the x≈4 while still in text mode, using the
Common Symbols palette item.

 

Note that the "x" above is in the upright Roman, like
the rest of the text.

 

This doesn't execute, even by default.

 

 

 

For `&approx;`(x, 4)I temporarily switched to 2D Math mode.

 

Note that the "x" above is in italics, just like 2D Input.

 

But I here I also mouse-selected that input and use the
right-click menu item,
   2D Math --> Convert To --> 2D Math Nonexecutable
so that it never executes to produce output if I use !!! from
the main menubar.

 

 

Download text_math.mw

@Mikhail Drugov If you mouse-select and then do the right-click menu action,

   2D Math -> Convert To -> Atomic Variable

then afterwards you could use Maple's lprint command to see the underlying structure that is being pretty-printed.

Below we can see that in the case of the superscript the result is a Maple name (ie. surrounded by single left-ticks, also known as name quotes). The structure of the name looks similar to MathML.

`#msup(mi("A"),mo("&ast;"))`

`#msup(mi("A"),mo("&ast;"))`

lprint(%);

`#msup(mi("A"),mo("&ast;"))`

`#msup(mi("A"),mo("&ast;"))`;

`#msup(mi("A"),mo("&ast;"))`

`#msup(mo("A"),mo("&ast;"))`

`#msup(mo("A"),mo("&ast;"))`

Download msup.mw

Sometimes it's even convenient to use nprintf to programmatically construct the special name.

@Mikhail Drugov Here are three ways to get the * in the superscript without getting either single  left-ticks visible, or any parsing as conjugation, etc.

Note the the first way uses a methodology I mentioned in my earlier Answer.

restart;

 


In the first example below I first use the keystrokes A ^ * , and then I select that
expression and right-click on it and use the right-click context-menu choice,

   2D Math -> Convert To -> Atomic Variable

That prevents it from being parsed as a complex conjugate (or hermitian
transpose, etc).

 

 

plot(x^2, labels = [`#msup(mi("A"),mo("&ast;"))`, ""])

 

Here are some ways, using 1D Input mode.

 

plot(x^2, labels=[A^`&ast;`, ""])

plot(x^2, labels=[`#msup(mi("A"),mi("*"));`, ""])


misc_superscripts.mw

@zenterix These examples led me to notice a GUI regression in lprint of HFloats, which I suspect began in Maple 2021.

I submitted a bug report.

@zenterix I'd likely have gotten there sooner if the second attachment's example in the original Question had not been mistakenly cast, which purported to show the background motivation or, as you wrote, "...why I want to create such a table". That example had all integer indices, or "keys" as you phrase it.

So it isn't true that, "..the issue in both cases I presented boiled down to this one thing", where one thing is, "...accessing an entry in a table with a decimal key." It isn't true because you gave three examples in three attachments, not two cases. And the third example had all integer keys.

Also, the problem was not merely because the indices were floating-point values ("decimals" as you phrased it) , but more precisely because some of the indices were hardware floats.

It's possible that the process might be rewritten to use listdensityplot, which at least could get rid of the trunc (though perhaps less efficient). I didn't bother with any major rewrite.

I didn't suggest anything like setting UseHardwareFloats to false, (or elementwise Matrix multiplication, etc) as I don't know how well this whole process has to scale.

@zenterix I don't understand why you didn't provide the actual example of what you really wanted to accomplish, with the appropriate data, up front.

Here is one way,

restart

  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[c1]) then:
                        t[c1] := table([ HFloat(c2) = c3]):
                else:
                        t[c1][HFloat(c2)] := c3:
                end:
        end:
        return eval(t):
end:``

A := Matrix([[1, .2, 3], [2, .2, 6], [3, .2, 9], [4, .2, 12]])

Matrix(%id = 36893627913894943668)

B := `<,>`(A, Matrix(`<|>`(A[1 .. (), 1], 2*A[1 .. (), 2], 2*A[1 .. (), 3])), Matrix(`<|>`(A[1 .. (), 1], 3*A[1 .. (), 2], 3*A[1 .. (), 3])), Matrix(`<|>`(A[1 .. (), 1], 4*A[1 .. (), 2], 4*A[1 .. (), 3])))

Matrix(%id = 36893627913894911996)

T := convertArrayToTable(B)

table( [( 1 ) = table( [( HFloat(0.2) ) = 3, ( HFloat(0.6000000000000001) ) = 9, ( HFloat(0.4) ) = 6, ( HFloat(0.8) ) = 12 ] ), ( 2 ) = table( [( HFloat(0.2) ) = 6, ( HFloat(0.6000000000000001) ) = 18, ( HFloat(0.4) ) = 12, ( HFloat(0.8) ) = 24 ] ), ( 3 ) = table( [( HFloat(0.2) ) = 9, ( HFloat(0.6000000000000001) ) = 27, ( HFloat(0.4) ) = 18, ( HFloat(0.8) ) = 36 ] ), ( 4 ) = table( [( HFloat(0.2) ) = 12, ( HFloat(0.6000000000000001) ) = 36, ( HFloat(0.4) ) = 24, ( HFloat(0.8) ) = 48 ] ) ] )

f := proc (x, y) global T; return T[trunc(x)][HFloat(y)] end proc

plots:-densityplot(f, 1 .. 4, .2 .. .8, grid = [5, 5])

NULL

NULL

Download convertArrayToTable_ac.mw

Please don't start a completely separate Question thread for close followups of this.

First 83 84 85 86 87 88 89 Last Page 85 of 591