acer

32480 Reputation

29 Badges

20 years, 6 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Christopher2222 In general (outside this context of using the `convert` command) symbol and name cannot be used interchangeably.

For example not everything of type name is of type symbol.

I don't understand why you would make such a potentially confusing and generally untrue statement in a clause that reads ambiguously (and could be easily interpreted as a general claim).

I messed around with code (originally from someone I know) to do that in Maple, about 5-8 years ago. It did wireframe 3-D plots, and relied on having those 3-D cinema glasses that filtered the two colors. The hard part to using that would be to find the worksheet...

But if I recall it was not very involved code. I'm sure several people here could implement the basic idea quite quickly.

@wilk007 That functionality to embed and automatically start playing relies on use of a PlotComponent, which only supports a pair of integers (pixel counts), and not the "golden" ratio.

A simple adjustment of the code allows the integer dimensions to be passed in.

I'll approximate using the golden ratio by obtaining the height as a suitable multiple of the width.

restart;

wave := (x,t) -> 12*(3+4*cosh(2*x-8*t)+cosh(4*x-64*t))/(3*cosh(x-28*t)+cosh(3*x-36*t))^2:

autoplay := proc( anim, {continuous::truefalse:=false},
                        {size::[posint,posint]:=[400,400]} )
  local P, T;
  uses DocumentTools, DocumentTools:-Layout,
       DocumentTools:-Components;
  P := Plot(':-identity' = "Plot0", anim,
            ':-continuous'=continuous,
            'pixelwidth'=size[1], 'pixelheight'=size[2]);
  T:=InsertContent(Worksheet(Group(Input(Textfield(P)))),
                   ':-output'=':-table');
  DocumentTools:-SetProperty(T["Plot0"],':-play',true);
  NULL:
end proc:

aniplot := plots:-animate( plot,[wave(x,t),x=-20..20],t=-1..1,frames=45,thickness=3 ):

autoplay( aniplot, size=[1500, floor(1500*0.61)] );

I wrote a fancier version of the "autoplay" procedure above. It came up recently in another thread. I'll try and find the link for you.

NB. Several of your Mapleprimes posts contain images (pictures) of code. Nobody enjoys having to retype stuff out. Please use the green up-arrow in the editor to upload worksheet attachments, or inline your complete code as plaintext, moving forwards. Thanks.

@mapleatha You can simply change the printf to nprintf in Rouben's suggestion.

The result would then be a name, similar to the concatenation you asked about your related Question. And it would then print in the usual way (centered, and in blue or according to the style).

The mimicing of a sentence by multiplication is somewhat dubious and awkward, in comparison. If you don't need 2D pretty-printing of any portions then using nprintf is so much more straightforward.

Using Maple 2017 for 64bit Linux I get a smoothly rendered curve for this example, displayed inline in the Standard GUI, simply by removing the high numpoints option.

More particularly, for this example I get a jagged display for the inlined plot display if the value for the numpoints option is 2000 or greater, and a much smoother curve if numpoints is less than 2000 (or absent).

 

@_Maxim_ 

Loss of detail occurs due to scaling (and possibly by encoding which involves GUI-side conversion to PNG).

In the attachment below those details are still quite clear, by Preview2D without altering the size.

As mentioned, a benefit is that the point-probe manipulator can be used. Other benefits include the fact that it is regular output like a plot and so doesn't have the Embed restriction of one result per execution-group (which affects all programmaticly embedded component assemblies). Also, the GUI can be slower to render image backgroups on 2-D plots. I agree, if those benefits aren't needed then Embed serves better.

[edit] By supplying the extra option axes=none the Preview2D result can be a closer match to the image size, since the axes and tickmarks don't contributes to the sizing bookkeeping. But the point-probe details can still be enabled and accessed. (See new attachment) Perhaps a better default would be with axes=none.

2dpreview3.mw

@vv Nice example.

Testzero:=u->evalb(radnormal(expand(convert(u,exp)))=0):

Testzero( sin((3/7)*Pi)-sin((1/7)*Pi)+sin((2/7)*Pi)-sqrt(7)/2 );

                           true

That Testzero handles the original Matrix M. I hope nobody interprets this as meaning that I think finding a strong-enough but fast-enough zero detection mechanism is easy or even always possible.

[edited] Also, getting an effective Testzero won't help with expression swell and obtaining results that are unwieldy. So obtaining a Normalizer that handles the swell usefully while not taking a great deal of time can also be important. I realize that most of the participants in this thread are aware of the difficulties.

@Robert Israel I believe I observed that kind of thing for M[1..4,1..4] with Testzero=testeq.

 

@_Maxim_ The "Point Probe" manipulator is not available for 3-D plots. And ImageTools:-Preview displays a 3-D plot with an appropriate orientation and the color/shading applied to a plane where z=constant. (You can even rotate it with the mouse...)

The ImageTools:-Preview command was written before the background option for 2-D plots was introduced.

Here's a procedure which can be used to display an Image (Array or Matrix) in a 2-D plot, after which the manipulator can be used see coordinates of points in the image. You may have to use the right-click contextmenu item on the plot output to enable or set the manipulator, as per usual.

Preview2D:=proc(im::{Matrix,Array}(datatype=float[8]),
                {size::{[posint,posint],
                        identical(NoUserValue)}:=':-NoUserValue'},
                {scaleopts::list:=[]})
  # `scaleopts` get passed to ImageTools:-Scale while
  # any other passed arguments get passed to `plot`.
  local dims,wlo,whi,hlo,hhi,scaled,sizeopt;
  dims:=[rtable_dims(im)];
  if numelems(dims)<>2 then
     error "expecting an Array with 2 dimensions, got %1",
           numelems(dims);
  end if;
  wlo,whi := (lhs,rhs)(dims[2]);
  hlo,hhi := (lhs,rhs)(dims[1]);
  if size=':-NoUserValue'
    or ( size[1]=whi-wlo+1 and size[2]=hhi-hlo+1 ) then
     scaled := im;
     sizeopt := NULL:
  else
     scaled := ImageTools:-Scale(im, 1..size[2], 1..size[1],
                                 op(scaleopts));
     sizeopt := ':-size'=size;
  end if;
  plot('axes'="frame",'view'=[wlo..whi,hlo..hhi],
       'background'=scaled, sizeopt,
       'axis'=[':-thickness'=0,':-location'="low"], _rest);
end proc:

And here is is with your code. 2dpreview.mw

As for the need to wrap ImageTools command in try..catch to avoid overlong error messages, that appears to be a regression that occurred between Maple 2015.2 and Maple 2016.0. In Maple 2015 the error string generated by a procedure's param_processing was elided for large rtables. I have submitted a bug report.

@Christopher2222 That's what used to happen, as I stated above.

I haven't figured out yet whether unprotect/rewrite of `error` could work around the issue nicely enough. (Let alone whether examination of the callstack could make it appear as if the rethrown error were being emitted from the original location...)

@uomcsg Tom is suggesting that you would use the combine, rather than use trigsubs.

You can pass the optional argument trig to the combine command, to restrict the action to trig subexpressions.

restart;

M:=Matrix([[-a3*c[1]*s[3]-a3*c[3]*s[1]-d2*s[1], c[1], -a3*(c[1]*s[3]+c[3]*s[1])],
           [a3*c[1]*c[3]-a3*s[1]*s[3]+d2*c[1], s[1], a3*(c[1]*c[3]-s[1]*s[3])]]);

_rtable[18446884722066116606]

U:=eval(M,[seq(s[i]=sin(theta[i]),i=1..3),
           seq(c[i]=cos(theta[i]),i=1..3)]);

_rtable[18446884722070627982]

map(combine,U,trig);

_rtable[18446884722070641470]

 


Download combine_trig.mw

In my opinion the applyrule command is very weakly coded. I am not aware of any involved maple procedure or package that relies on it in a major way while not inheriting applyrule's many flaws.

I would reach for other tools first, like structured types and access or replacement tools that used types (subsindets, evalindets, indets, etc).

@tomleslie 

My edits were not intended as a criticism, and I hope weren't taken that way. Apologies it it was. I understand quite well that you were going for exposition and a prototype.

Having said that, the changes were quite short though the speedup is considerable. And its executable statements are just as understandable IMO (barring removal of comments). Things like making the mask creation done with evalhf, having the mask be float[8] datatype, some memory savings by inplace operations, and using `zip` rather than .~ for applying the mask.

It's almost fast enough for the process to be done with Explore, with parameters for the `width` and `centrefreq`. Fast experimentation of the filter application is one reason why I think fast can be useful.

(I am reminded again of a wish for fast, effective, and flexible peak detection in Maple.)

@tomleslie Nice job.

Attached is a revision that runs a bit faster.

restart;

img := ImageTools:-Read("https://i.imgur.com/7tXecNX.png"):

img2:=img[22..621,1..600]:

func:=proc(IMG, width, centrefreq)
  local F,H,W,filter,imgfft,filtfft,filtimg;
  uses ImageTools, ArrayTools, DiscreteTransforms;

  (W,H):=Width(IMG),Height(IMG);
  F:=subs([c=centrefreq,w=width],
          proc(i,j)
            evalhf( 1 - ( exp( - ( sqrt( (i-W/2)^2 + (j-W/2)^2 ) - c )^2/w )) );
          end proc):

  filter:= Array( 1..H, 1..W, F, 'datatype'='float[8]');

  imgfft:= CircularShift( FourierTransform(IMG), H/2, W/2 );

  filtfft:= CircularShift( zip(`*`,filter,imgfft), H/2, W/2 );

  InverseFourierTransform( filtfft,'inplace');

  map[evalhf,'inplace'](Re,filtfft);
  filtimg:= FitIntensity(Array(filtfft,'datatype'='float[8]'),
                         'inplace'=true ):

  end proc:

res := CodeTools:-Usage( func(img2, 150, sqrt(15000.0)) ):

memory used=203.24MiB, alloc change=90.72MiB, cpu time=543.00ms, real time=546.00ms, gc time=44.00ms

#ImageTools:-Embed([img2, res]);

#Q:=Matrix(3,3,(i,j)->sqrt( 2500.0 * (3*(i-1)+j) ));

#ImageTools:-Embed(convert(map(u->ImageTools:-Scale(func(img2, 200, u),0.5),Q),listlist));

 


Download ImProc_faster.mw

@ThU There is also keyboard shortcut for indexed underscripts, Ctl-Shift-_ (control-shift-underscore) for 2D Input mode.

There are also items on the Layout Palette for both indexed and literal name subscripts. (Those palette items have tooltips that show which is which).

Using either keyboard shortcut or palette entry you can obtain nice typeset subscripted input for indexed subscripts, without having to see the 1D style square-bracketed name in the input, and without having to change any preferences.

First 270 271 272 273 274 275 276 Last Page 272 of 594