acer

32405 Reputation

29 Badges

19 years, 345 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

For this example the lower curve may be added. It makes the lower edge appear smoother.

The code already included the curve along the upper boundary (which is why it seems a little darker). This now even closer to what plots:-shadebetween does internally.

(f,g) := 2, 1/sqrt(1-x^2):

plots:-display(plot(g,x=0..sqrt(3)/2),
   plottools:-transform(unapply([x,y+g],x,y))(plot(f-g,x=0..sqrt(3)/2,filled=true)));

@Carl Love Good eye! I had forgotten about that aspect of the calling sequence.

An empty set suffices to designate lack of inequality constraints. So in this example below the operator designates the equality constraint x+y=2 .

Optimization:-Minimize((x,y)->x, {}, {(x,y)->x+y-2}, -1..1, -2..2);          

                                    -15  [                     -15]
           [-0.111022302462515654 10   , [-0.111022302462516 10   ]]
                                         [                        ]
                                         [           2.           ]

An example showing this clearly on the help-page would be nice.

@Markiyan Hirnyk I followed the instruction for inequality constraints, as that is what your examples contain. 

That piece of documentation does not make much sense to me either, as far as equality constraints go.

But we can test that the form I used is being interpreted as an ineqaulity constraint (and for the examples you gave... that is relevant).

Optimization:-Minimize(x, {x+y=2}, x=-1..1, y=-2..2);          

                             -8                            -8
       [-0.103259778874000 10  , [x = -0.103259778874000 10  , y = 2.]]

Optimization:-Minimize(x, {x+y<=2}, x=-1..1, y=-2..2);

                           [-1., [x = -1., y = 0.]]

Optimization:-Minimize((x,y)->x, {(x,y)->x+y-2}, -1..1, -2..2);     

                                       [-1.]
                                 [-1., [   ]]
                                       [0. ]

The above indicates that the form of operator (for a given inequality constraint) that I used is being interpreted as the documentation describes for inquality constraints (converted to operator form). I do agree with you that the documentation that describes how equality constraints ought to be handled is quite unclear.

If I had an equality constraint in expression form then I might approach it as follows, using a pair of inequality constraints (that together imply the equality constraint).

Optimization:-Minimize((x,y)->x, {(x,y)->x+y-2,
                                  (x,y)->-(x+y-2)},
                        -1..1, -2..2);

                                    -15  [                     -15]
           [-0.111022302462515654 10   , [-0.111022302462516 10   ]]
                                         [                        ]
                                         [           2.           ]

So I will submit a but report that the documentation for expressing equality constraints in operator form is unclear and incomplete (missing).

@Markiyan Hirnyk I suspect that you have not properly realized that an inequality constraint has to be put into the form v(x1,x2,...,xn)≤0 before taking its left-hand-side as the expression to use inside the procedure.

Here is an example that roughly uses the approach that Carl described.

Of course if there is more than just one constraint then they would have to be handled (stored) separately.

My use of the colorscheme option below likely requires Maple 2015. (In an older version, remove that option.)

restart;

obj := proc(x,y)
   global _Objcount, _Objvals;
   local res;
   res := (x-1)^2+(x-y)^2;
   _Objcount := _Objcount+1;
   _Objvals[_Objcount]:=[x,y,res];
   res;
end proc:

cons1 := proc(x,y)
   global _conscount, _consvals;
   local res;
   res := 8 - x*(y^2+1);
   _conscount := _conscount+1;
   _consvals[_conscount]:=[x,y,res];
   res;
end proc:

_conscount, _consvals := 0, '_consvals':
_Objcount, _Objvals := 0, '_Objvals':

ans := Optimization:-Minimize( obj, { cons1 });

ans := [.517128660127401329, Vector(2, {(1) = 1.6256197919129367, (2) = 1.9802019912605846}, datatype = float[8])]

_Objcount, _conscount;

98, 98

with(plots):

display(
   pointplot3d([[convert(ans[2],list)[],ans[1]]],
               symbolsize=25, color=red),
   pointplot3d([seq(_Objvals[i],i=1.._Objcount)],
               symbolsize=20, colorscheme=["Black","LightGreen"]),
   spacecurve([seq(_Objvals[i],i=1.._Objcount),[convert(ans[2],list)[],ans[1]]],
              symbolsize=20, colorscheme=["Black","LightGreen"])
       );

display(
   plot3d(0.0, x=0..6, y=0..5, transparency=0.7),
   plot3d(8-x*(y^2+1), x=0..6, y=0..5, transparency=0.7),
   pointplot3d([[convert(ans[2],list)[],eval(8-x*(y^2+1),[x=ans[2][1],y=ans[2][2]])]],
               symbolsize=25, color=red),
   pointplot3d([seq(_consvals[i],i=1.._conscount)],
               symbolsize=20, colorscheme=["Black","LightGreen"]),
   spacecurve([seq(_consvals[i],i=1.._conscount),[convert(ans[2],list)[],ans[1]]],
              symbolsize=20, colorscheme=["Black","LightGreen"])
       );

evalf[5]([seq(_Objvals[i],i=1.._Objcount)]);

[[0., 0., 1.], [0., 0., 1.], [0.50000e-8, 0., 1.0000], [-0.50000e-8, 0., 1.0000], [0., 0., 1.], [0., 0.50000e-8, 1.0000], [0., -0.50000e-8, 1.0000], [2., 0., 5.], [2., 0., 5.], [2.0000, 0., 5.0000], [2.0000, 0., 5.0000], [2., 0., 5.], [2., 0.50000e-8, 5.0000], [2., -0.50000e-8, 5.0000], [5.6000, 4.8000, 21.800], [5.6000, 4.8000, 21.800], [5.6000, 4.8000, 21.800], [5.6000, 4.8000, 21.800], [5.6000, 4.8000, 21.800], [5.6000, 4.8000, 21.800], [5.6000, 4.8000, 21.800], [3.7233, 2.2977, 9.4486], [3.7233, 2.2977, 9.4486], [3.7233, 2.2977, 9.4486], [3.7233, 2.2977, 9.4486], [3.7233, 2.2977, 9.4486], [3.7233, 2.2977, 9.4486], [3.7233, 2.2977, 9.4486], [2.9868, 1.3157, 6.7397], [2.9868, 1.3157, 6.7397], [2.9868, 1.3157, 6.7397], [2.9868, 1.3157, 6.7397], [2.9868, 1.3157, 6.7397], [2.9868, 1.3157, 6.7397], [2.9868, 1.3157, 6.7397], [3.1353, 1.5137, 7.1888], [3.1353, 1.5137, 7.1888], [3.1353, 1.5137, 7.1888], [3.1353, 1.5137, 7.1888], [3.1353, 1.5137, 7.1888], [3.1353, 1.5137, 7.1888], [3.1353, 1.5137, 7.1888], [3.0621, 1.4162, 6.9615], [3.0621, 1.4162, 6.9615], [3.0621, 1.4162, 6.9615], [3.0621, 1.4162, 6.9615], [3.0621, 1.4162, 6.9615], [3.0621, 1.4162, 6.9615], [3.0621, 1.4162, 6.9615], [2.9783, 1.3065, 6.7083], [2.9783, 1.3065, 6.7083], [2.9783, 1.3065, 6.7083], [2.9783, 1.3065, 6.7083], [2.9783, 1.3065, 6.7083], [2.9783, 1.3065, 6.7083], [2.9783, 1.3065, 6.7083], [.85303, 2.0378, 1.4252], [.85303, 2.0378, 1.4252], [.85303, 2.0378, 1.4252], [.85303, 2.0378, 1.4252], [.85303, 2.0378, 1.4252], [.85303, 2.0378, 1.4252], [.85303, 2.0378, 1.4252], [1.9216, 1.6701, .91266], [1.9216, 1.6701, .91266], [1.9216, 1.6701, .91266], [1.9216, 1.6701, .91266], [1.9216, 1.6701, .91266], [1.9216, 1.6701, .91266], [1.9216, 1.6701, .91266], [1.5966, 1.9739, .49830], [1.5966, 1.9739, .49830], [1.5966, 1.9739, .49830], [1.5966, 1.9739, .49830], [1.5966, 1.9739, .49830], [1.5966, 1.9739, .49830], [1.5966, 1.9739, .49830], [1.6259, 1.9801, .51721], [1.6259, 1.9801, .51721], [1.6259, 1.9801, .51721], [1.6259, 1.9801, .51721], [1.6259, 1.9801, .51721], [1.6259, 1.9801, .51721], [1.6259, 1.9801, .51721], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713], [1.6256, 1.9802, .51713]]

 

 

Download objfun.mw

 

@Markiyan Hirnyk I replaced the inequality constraint 8 - x*(y^2+1) <=0 by 8 - x*(y^2+1) in a procedure.

In your followup example you should replace {8 >= x*(y^2+1)} by {(x,y)->x*(y^2+1) - 8} to get the operator form for that inequality constraint.

That's because (as documented) the constraint form to use is f(x,y)<=0 and so 8 >= x*(y^2+1) should be considered as x*(y^2+1) - 8 <=0 .

Optimization:-Minimize(x^2+(y-1)^2, {8 >= x*(y^2+1)});

                              -39                           -19
      [0.183670992315982423 10   , [x = 0.135525271560688 10   , y = 1.]]

Optimization:-Minimize((x,y)->x^2+(y-1)^2, {(x,y)->x*(y^2+1) - 8}); 

                                       [0.]
                                  [0., [  ]]
                                       [1.]

@Markiyan Hirnyk Your usage is incorrect.

Optimization:-Minimize( (x-1)^2+(x-y)^2 , { 8 <= x*(y^2+1) });               

     [0.517128660129716033, [x = 1.62561974988123, y = 1.98020202339228]]

Optimization:-Minimize( (x, y)->(x-1)^2+(x-y)^2 ,
                        { (x, y) ->8 - x*(y^2+1) });

                                         [1.62561979191297]
                  [0.517128660127401107, [                ]]
                                         [1.98020199126056]

See the section "Constraints" in the Optimization,General,OperatorForm help-page.

 

@John Dolese Great. The new Figure 2 is much better. There's still a lot more green than there ought to be. But the new Figure 2 jives visually with my own similar experiment using the current WavelengthToColor.

I already understood the point of the execise, as I've previously worked out much of this and more in Maple myself. But I'm sure that the extra explanation will help other readers.

I should find time to polish my sheets that produce a more accurate edge of the visual gamut in xy(Y). The generated colors agree quite a bit more with reference material, as a function of wavelength. I made a function which interpolates from the 1931 CIE data itself. Of course I must regress back to the displayable RGB gamut, to show it on a plot. But the `spectrum` it produces seems relatively accurate (visually and numerically), compared to online references. Really I should go further and produce a corrected WavelengthToColor procedure.

There is also an old `MathApp` that shows wavelength and color. The last I looked it used a crude piecewise linear approximation in three channels, so the spectrum it can produce is a bit clunky and artifically flat in places. The piecewise approx. it uses seems to be found a few places on the web (the earliest place I saw it was in some Matlab code...).

I'm not sure if it's documented, but when I last dug into the hard-coded conversion data internal to ColorTools I saw values that correspond to D65. I believe that a much earlier (first?) version of ColorTools might have used D50 conversion data, but that was sensibly changed quite soon after.

I too have wondered which "RGB" we get from the Java GUI. At least one of my LCD monitors offers a choice between Adode vs other RGB variants (and/or "temperature"). I'd like experiment with matching that up with the RGB variant that Maple's Standard (Java) GUI is displaying.

Another thing I'd like to do it adjust/wrap/hack ColorTools:-SpatterPlot to optionally show a full view of a highly translucent implicit surface of the visible gamut, to put some perspective on what it shows. Of course that surface would need to correspond to the value one chooses for the colorspace option of that command.

There were some interesting bits of new functionality for working with color in Maple 2015. (Hmm, maybe there's enough for a few posts.)

@John Dolese 

The WavelengthToColor command produces quite wrong values for the yellow-through-blue sections, and the green is particularly out of whack. I've known this for a while now, and have constructed a repaired scheme one using the 1931 CIE data and some techniques a bit like in the link I gave (but less coarse). It produces a "visible spectrum" more like what one usually sees in references (although of course it is generally not clear what source might be expected to emit such a light).

I notice that you haven't really explained why your Figures 1 and 2 show those colors which don't come close to  matching the popularly shown visible gamut usually shown in diagrams in xy(Y) space. How are you normalizing or projecting, with repect to Y? Since we seem to agree about where the current WavelengthToColor results go awry I wonder whether I am just misunderstanding something simple about the colors used to shade the curves in your Figures 1 and 2. I looked at the code hidden in your Tables. It seems to me that the degree to which WavelengthToColor is innaccurate does not accomodate the degree to which your curve's colors differ from stock references. But perhaps I misunderstand what you've intended to show. What do you mean by "D65_data_Monochromes"? Do you not mean the fully saturated pure colors that lie at the edge of the visible gamut? Why do they not match the visible `spectrum', in your Figure 1 and 2?

Perhaps I should as a simpler question. You appear to be trying to color the outer edge of the visible gamut in (projected) xyY, where the boundary contains the fully saturated "pure" colors. Since you are making a plot for display on computer monitors that are (usually) limited to some (flavor of) RGB displayable gamut then how generally do you intend on handling the colors outside the triangular RGB gamut but inside the visible gamut? Is it your intention to simply chop R, G, or B values that lie outside of 0.0..1.0? Or are you chopping/restricting in XYZ? Or do you intend to regress toward the D65 white point? Or something else entirely?

Thanks for bearing with me. I'd just like to understand your methodology a bit more.

Does your Document contain the plotting commands that generate each of the plots from numeric data? If not, then may I ask why not?

The plots in your Document labelled Figure 2 and Figure 3 do not show colors that I usually associate with the fully saturated extreme edge of the visible gamut (based on 1931 CIE data) when represented as if in xy(Y) color space. Have I misunderstood what the shades of color (described there as "D65_data Monochromes") in those two figures are supposed to represent? I would have expected something more like this (or even this done somewhat crudely in Maple). Without the commands which produce the plots it's difficult to make sense of the colors shown in those two figures in particular.

acer

This is a regression from Maple 18.02 to Maple 2015.0. I have submitted a bug report.

acer

There have been a few related Questions. For example, see here.

acer

@Carl Love If you made `&angle;` be an export of that module, which simply called the ModuleApply, then this might also  work with the Operator palette's entry for that entity. If so then this would be nice for 2D Input.

@Carl Love Yep, I did it that way on purpose. But thanks for mentioning it. I'm often torn when answering, between choosing what I think performs best and what I think will be most instructive. In this case the overhead of invoking that simple v->F.v, compared to using kernel builtin map2, is quite small compared to the savings from not repeating the same two matrix-multiplications and matrix-inverse for each entry. I figured that the map syntax is easier to understand, when learning.

I also didn't mention using float[8] Matrices/Arrays, or 3-dimensioanl Arrays instead of 2-dimensional Arrays of Vectors, because I figured the OP wants a particular visual layout. (Gosh, I also hope that the 2D Math evaluation bits inside Tables and inlined and so on is on purpose, and not because the OP has gone amok in Documents.)

If anyone's wondering after reading this Poster's submissions, I have a some very fast compiled routines for doing conversions between all the color spaces that Maple's ColorTools package knows about. But my routines act on 3D float[8] Arrays/Matrices. The conversions that ColorTools can do in its own scalar Color objects is just too slow for use on large amounts of data.

@Earl I agree: there ought to be a very simple but complete example, for a procedure, in the manuals or documentation.

Here is a simple example, for a procedure.

Here is a slightly more involved answer (checking existence of library, etc), for both procedures and a module.

Here is an example, for a module, buried (too) deep in the section of the Programming Manual on authoring packages. Its the subsection "Custom Libraries", and it's pretty wordy.

First 321 322 323 324 325 326 327 Last Page 323 of 593