acer

32313 Reputation

29 Badges

19 years, 313 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Ahmed111 Sorry, I was looking at the wrong file -- you gave the same name to both your original and your revised attachments.

There are still mix-ups involving names like lambda__1 and lambda[1], H__34 and H[34], etc, with both present in some expressions, even in the 2D Input of assignments.

That happens in (at least) the 2D Input of the assignments to vvalueA2snum, and valphipsi12.

@zenterix Someone (perhaps you, the OP) tagged this Question as "pointplot3d". I suggest that makes the Maple Help page for the pointplot3d command a decent starting place for help with programmatic options for that very command.

As I explained, the general programmatic 3D plotting options Help page is linked from there, in two ways.

The Portal pages are very much skewed towards mouse-pointer based context-menu approaches. It's almost as if they were written with the idea that programmatic approaches are undesirable.

I'm not suggesting that you've done anything wrong; I'm simply trying to assist you with some friendly advice in your future programmatic Maple endeavors.

ps. If I search for "light" in the Maple help browser then the mentioned plot3d,option topic page is the second hit down in the returned Search Results. Perhaps it ought to be the top hit.

@zenterix Here is a way to sort a Matrix by a given column. I'll use the second column.

M := Matrix([[11,4,13],[21,-8,23],[31,1,33]]);

Matrix(3, 3, {(1, 1) = 11, (1, 2) = 4, (1, 3) = 13, (2, 1) = 21, (2, 2) = -8, (2, 3) = 23, (3, 1) = 31, (3, 2) = 1, (3, 3) = 33})

M[sort(M[..,2],output=permutation)];

Matrix(3, 3, {(1, 1) = 21, (1, 2) = -8, (1, 3) = 23, (2, 1) = 31, (2, 2) = 1, (2, 3) = 33, (3, 1) = 11, (3, 2) = 4, (3, 3) = 13})

Download sort_Matrix_by_column.mw

I would agree that it might be generally useful to have a Help page that contained common Matrix&Vector manipulations.

There are some manipulation commands (for Arrays, Matrices, & Vectors) in the ArrayTools package.

@zenterix It is not difficult to restructure the Matrix/Array of data. For the kind of regularly structured data you've described, the convertArrayToTable approach is very poor (relatively speaking). I was surprised that you returned to using it.

In fact I already showed you one way to do it directly and easily, using just seq and the angle-bracket constructor. The resulting Matrix can work directly with either surfdata or listdensityplot.

There are other ways to reassemble that data in a way that can be plotted directly, eg. the data can be rewritten as mxnx3, say, and "transposed. And there are still more ways, involving top-level easy commands. You seem so insistent that this quite basic task is difficult that's I think I should give up now.

@zenterix Did you notice that I specified the ytickmarks in the earlier listdensityplot example?

You can specify whatever you want for xtickmarks as well. Just for example,

     xtickmarks=[seq(100*i=100*(0.5+(i-1)*0.5),i=1..6)]


ps. I might not have made the following point clear enough before: I think that the idea of the convertArrayToTable procedure is poor. If your new data has the same kind of pattern (repeated blocks of indices in column 2, etc) then you could get rid of that procedure altogether. Using it is just asking for the kind of difficulties that you had earlier. For the earlier regular data you gave, it could be replaced just by this,   

read "./matrix.m":
m1 := Matrix(m1,datatype=float[8]):
MM:=`<|>`(seq(m1[1+120*(i-1)..120+120*(i-1),3],i=1..85)):

It's more robust as well as much terser. If your data is structured similarly then you could simply adjust for the new dimension sizes. I can't show you directly because you have not provided the new data.

@nm You are objecting to something about a case that you do not know for sure is in the domain that the OP is considering, and which can be handled trivially regardless.

But it might possibly be useful to the OP, so thanks.

More important IMO is that there is already a StringTools command to count the number of occurrences of a single character (ie. no need to write one's own), and that there is another existing command if one wants to tally all characters present.

@mmcdara The OP showed that it was interms of only volts in the Question, since the forced conversion to V^2 works.

@nm It's worth pointing out that evalc makes the assumption that the unknown names are real.

So, while this approach does attain the target it is unnecessarily confusing because it makes it appear that the transformation might depend on such properties or assumptions.

@Mike Mc Dermott There already is an option on the Tabulate command for specifying the relative widths of the columns. It's the weights option.

Combined with the options to specify the total width in either pixels or portion of the worksheet's width, that allows for complete specification of the column widths.

@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.

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