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

@Scot Gould GAMMA is not what helps here. It's happenstance. Any other `convert` call that happens to accept a float argument would also succeed in exactly the same way.

The fact that GAMMA also relates (otherwise) to factorial would make it unnecessarily misleading to recommend it to your colleague for this situation. No actual conversion takes place here.

As for the "operator form" calling sequence, I too am a fan. It's often my first choice if I just need to avoid so-called "premature evaluation", when invoking with a function call.

@dharr The GAMMA conversion is a red herring here. In fact there's no factorial->GAMMA special-function call conversion actually going on here.

What is going on here is that (new behavior in Maple 2023!) the evalhf facility is escaping out to compute the (kernel builtin) convert call.

Some years ago evalhf was enhanced to allow it to escape out (of itself) for calls to eval. This was interestingly general, since one can put a variety of things in an eval call). But this escape for an convert call, that's new.

Note however that what the convert command actually receives in the example is just the software float 15.19780218. There nothing special about GAMMA going on. Other unrelated an noneffective conversions succeed for the very same reason as this does.

Yes, that's right. This approach is simply yet another evalhf avoidance-mechanism. (There are still others... but alas I don't have all night...)

restart

kernelopts(version)

`Maple 2023.0, X86 64 LINUX, Mar 06 2023, Build ID 1689885`

F := proc (q) options operator, arrow; convert(100*factorial(400)*(1/100)^q*(99/100)^(400-q)/(factorial(400-q)*factorial(q)), GAMMA) end proc; trace(convert); evalhf(F(5.1)); untrace(convert)

proc (q) options operator, arrow; convert(100*factorial(400)*(1/100)^q*(99/100)^(400-q)/(factorial(400-q)*factorial(q)), GAMMA) end proc

execute convert, args = 15.19780218, GAMMA

execute convert, args = \`Standard Worksheet Interface, Maple 2023.0, Linux, March 6 2023 Build ID 1689885\`, string

15.1978021800000000

 

restart

F := proc (q) options operator, arrow; convert(100*factorial(400)*(1/100)^q*(99/100)^(400-q)/(factorial(400-q)*factorial(q)), sincos) end proc; trace(convert); evalhf(F(5.1)); untrace(convert)

proc (q) options operator, arrow; convert(100*factorial(400)*(1/100)^q*(99/100)^(400-q)/(factorial(400-q)*factorial(q)), sincos) end proc

execute convert, args = 15.19780218, sincos

execute convert, args = \`Standard Worksheet Interface, Maple 2023.0, Linux, March 6 2023 Build ID 1689885\`, string

15.1978021800000000

restart

F := proc (q) options operator, arrow; eval(100*factorial(400)*(1/100)^q*(99/100)^(400-q)/(factorial(400-q)*factorial(q))) end proc; evalhf(F(5.1))

proc (q) options operator, arrow; eval(100*factorial(400)*(1/100)^q*(99/100)^(400-q)/(factorial(400-q)*factorial(q))) end proc

15.1978021800000000

Download Factorial_to_Gamma_failed_plot_ac.mw

That above was Maple 2023.0. The single call evalhf(F(5.1)) as well as plot(F, 0..20) are both succeeding because evalhf is calling-out-of-itself to perform the convert calls, and that receives as its argument a result computed (also in this escaped mode) using regular software floats.

Now, in Maple 2022.2 and earlier the same call to convert throws an error under evalhf. So the single call evalhf(F(5.1)) emits an error. The plot(F, 0..20) succeeds because the plotting mechanism catches errors in computing values at points under evalhf mode, and re-tries them in regular evalf mode.

restart; kernelopts(version); plots:-setoptions(size = [300, 300])

`Maple 2022.2, X86 64 LINUX, Oct 23 2022, Build ID 1657361`

F := proc (q) options operator, arrow; convert(100*factorial(400)*(1/100)^q*(99/100)^(400-q)/(factorial(400-q)*factorial(q)), GAMMA) end proc

evalhf(F(3))

Error, unable to evaluate built-in function `convert` in evalhf


The error thrown by evalhf causes plot to re-try using regular
software float evalf mode.

plot(F, 0 .. 20)

F := proc (q) options operator, arrow; 100*factorial(400)*(1/100)^q*(99/100)^(400-q)/(factorial(400-q)*factorial(q)) end proc

proc (q) options operator, arrow; 100*factorial(400)*(1/100)^q*(99/100)^(400-q)/(factorial(400-q)*factorial(q)) end proc

evalhf(F(3))

Float(undefined)


There is no error thrown (just a nonnumeric value obtained, alas). So plot
doesn't fall back to re-trying in software float evalf mode. The plot structure
doesn't show a curve, because of the undefined values.

plot(F, 0 .. 20)

Download failed_plot_dharr_ac.mw

Could you please upload and attach a Maple .mw worksheet that is self-contained enough to reproduce your problem (at least if run in the same version as your Maple 2019)?

Could you please check that the same example exists in the Programming Guide that is bundled in the Help system for your Maple 2019?

My Maple 2019 version of the Programming Guide has named sections and subsections, but no page numbers. But I'd like to not only know which example is problematic for you, but to see the worksheet in which it fails.

I'm supposing that you are using the last (freely upgraded) Maple 2019.2 point-release for that version.

Many calculations can be programmed in Maple in several different ways, some of which may be fast and efficient, and some of which may be slow and inefficient. In my experience it is common for the most important thing to be obtaining a fast and efficient scalar/nonparallelized implementation first and foremost, and then move on to parallelization only when that is very good. Often times the improvements possible for an inefficient scalar/nonparallelized implementation significantly outweigh the further benefits of parallelization. Hopefully you'll be able to share some of the crucial bits of your monte-carlo simulation code, if you suspect that might be optimized.

It's not clear to me that you read and digested the commentary in my answer.

Would you be prepared to accept a result closer to y=0? If so, how close?

restart;

inf:=10:

pdes:= diff(u(y,t),t)-xi*diff(u(y,t),y)=diff(u(y,t),y$2)/(1+lambda__t)+Gr*theta(y,t)+Gc*C(y,t)-M*u(y,t)-K*u(y,t),
         diff(theta(y,t),t)-xi*diff(theta(y,t),y)=1/Pr*diff(theta(y,t),y$2)+phi*theta(y,t),
         diff(C(y,t),t)-xi*diff(C(y,t),y)=1/Sc*diff(C(y,t),y$2)-delta*C(y,t)+nu*theta(y,t):
  conds:= u(y,0)=0, theta(y,0)=0, C(y,0)=0,
          u(0,t)=0, D[1](theta)(0,t)=-1, D[1](C)(0,t)=-1,
          u(inf,t)=0, theta(inf,t)=0, C(inf,t)=0:
  pars:= { Gr=1, Gc=1, M=1, nu=1, lambda__t=0.5,
           Sc=0.78, delta=0.1, phi=0.5, K=0.5, xi=0.5
         }:

Digits:=20:
PrVals:=[0.71, 1.00, 3.00, 7.00]:
colors:=[red, green, blue, black]:
plt:='plt':
for j from 1 to numelems(PrVals) do
    pars1:=`union`( pars, {Pr=PrVals[j]}):
    pdSol:= pdsolve( eval([pdes], pars1),
                     eval([conds], pars1),
                     numeric, timestep=0.01, spacestep=0.001
                   );
    U := (Y,T)->eval(u(y,t),pdSol:-value(t=T)(Y));
    try
      plt[j]:=plot(D[1](U)(1e-10,t), t=0..2, color=colors[j]);
    catch: end try;
od:
plots:-display(convert(plt,list));

Download badPDE_ac2.mw

@petit loup There is nothing abjectly wrong with your use of roll, assigned via RandomVariable.

You primary performance issue is mainly solved just by using the more appropriate syntax I gave, ie.   Sample(roll, [n,n]) .

On a related note, your work might require regenerating additional (possible large) samples from the same random variable. That can be done with a slight efficiency gain by reusing the Matrix container.  Eg,

   X := Sample(roll, [n,n]):

and then, later on, perhaps several times,

   Sample(roll, X):

That last call repopulates the existing Matrix X with a fresh collection of random values. If done many, many times the saved overhead of not having to construct/memory-manage the previous Matrix structures may be measurable.

@Muhammad Usman Your original image showed no labels or ticks or values on the axes, so I removed them. You can get them back by removing the relevant options, eg.

restart;

with(plots): with(plottools,polygon): with(ColorTools,Color):

f := 11-((x-4)^2+(y-3)^2)/25: (a,b,c,d) := -5,11,-5,11:

Q := plot3d(f, x=a..b, y=c..d): (zmin,zmax) := (min,max)(op([1,3],Q)):

display(densityplot(f, x=a..b, y=c..d, 'style'=':-surface',
                    'colorscheme'=["zgradient",["Blue","Red"],'colorspace'="HSV"]),
  seq(polygon([[0,0],[0,0]],'thickness'=0.3, 'legend'=sprintf("%5.3f",z),
              'color'=Color("HSV",[:-Hue(Color("Blue"))*(zmax-z)/(zmax-zmin),1,1])),
      z=zmax..zmin, 'numelems'=24),
  'legendstyle'=['location'=':-right'], 'size'=[580,500], axes=frame);

Download M2022_colorbar_fun2.mw

Other changes to the axes can be done by simply using the usual options in the usual ways.

ps. As for your sequence of space-curves, for which you obtained a surface using surfdata, have you considered creating a interpolating function F from sampling those space-curves? Such a function call F(x,t) could be used with plot3d, densityplot, etc, just like the example expression above. Or you might use some formula in x and t thst produced the sequence...

@Muhammad Usman What does that mean, the "contour plot of the sequence"?!

I'm giving up. You're only providing brief, inadequate (and, to me, meaningless) fragments. It's not a proper description.

@Muhammad Usman Why would you think that either of those would work in densityplot?!

You have not given a proper or adequate description of what you're actually trying to do.

@Muhammad Usman You assign to f the result from plots:-surfdata, and then pass that f as the first argument to plots:-densityplot.

What do you expect that to do?

You should describe what you're actually trying to do, in adequate detail. I can't help you, if you don't.

What version of Maple are you using? Is it still Maple 2015?

Please put close followup queries to this here, instead of spawning wholly separate new Question threads for such.

@C_R I started with the Help page ?dsolve,numeric,DAE because in your Question you showed that the call came from the example worksheet for ?examples,numeric_DAE.

ps. If I enter the following in the Google search bar of my Chromium web-browser then the first hit is to that ?dsolve,numeric,DAE Help page.
    maple help dsolve "differential option"

I'm merely reporting what worked for me. Searching is often tricky.

@Traruh Synred Your boostTo.mw attachment here was saved using Maple 2018.2 (released in the year 2018), and not Maple 18 (released in the year 2014).

The naming scheme was changed in 2015, to have the release number match the year.

@Traruh Synred Your dMemB1List and dMemB2List are rtables (eg. Arrays, or row Vectors), and not lists.

You could try and concatenate them with,

   <dMemB1List|dMemB2List>

Your worksheet is missing code that defines B_recursive.

First 59 60 61 62 63 64 65 Last Page 61 of 591