acer

32333 Reputation

29 Badges

19 years, 323 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Mac Dude showed you convert(...,polynom) in his Answer to your series Question from one week ago.

@dharr 

Yes, that is an alternate, convenient syntax for obtaining a procedure T which (just like in my second worksheet) returns unevaluated for nonnumeric argument c.

The overall time to compute can be reduced by about a factor of 2 by giving it option remember (just as in my revision of my second worksheet). That is,

   T := unapply('fsolve'(m(t, c) = -1, t = 0 .. 1/2*Pi), c, numeric, proc_options = [remember])

This is a crude revision, without any effort to handle the excluded entries better.

(I'm in a hurry just now. Later, I'll look at it more carefully. Please don't consider this as mu "submission". It's just to show some simple ideas, keeping the natural style somewhat... Quite a bit more optimization is possible.

But there is also an X1,X2 aspect that I'm not content with.)

BoxMuller_ac1 := proc(N)
  local V, S, X1, X2:
  V  := Statistics:-Sample(Uniform(-1, 1), [ceil(2*N/3), 2]):
  S  := V[..,1]^~2 +~ V[..,2]^~2;
  map[evalhf,':-inplace'](proc(t)
                           if t>1.0 then return Float(infinity); end if;
                           (-2*log(t)/t)^(1/2);
                         end proc,S);
  X1 := select[':-flatten'](type, S *~  V[..,1], numeric);
  X2 := select[':-flatten'](type, S *~  V[..,2], numeric);
  return < X1 , X2>:
end proc:

Tell us the URL for the website of this course, so that we can download the complete details, including the definitions of those procedures.

@mmcdara 

A considerable speedup can be had from using just evalhf (as I showed). True, the Compiler brings more (as I also showed), but evalhf can be quite handy.

The Compiler is still bundled and working in my Maple versions 2018 and 2019.

The is command is not builtin, and is not fast. Even use of a custom anonymous operator as the first argument to select or Select means you've moved away from builtins. Pure builtin use would more like, say,

     select(`>`,S,q)

When you do both Heaviside and subtraction as separate elementwise operations you produce a garbage Vector of length N for each operation. Overhead costs add up.

Apart from your concerns with the behavior of Sample (with its default method), I am surprised by the performance of add on a float[8] Vector.

In the examples below the only difference is the approach to adding up the numbers of outliers in the generated samples. The results concur, but the performance varies.

I would have expected that the first of these would perform comparably to the second.

(I include the others for your interest.)

restart;

with(Statistics):

X := RandomVariable(Normal(0, 1)):

N := 10^6: R := 20: Q := [$0..5]: nQ := numelems(Q):

M  := Matrix(R, nQ, 0):

str:=time[real]():
for r from 1 to R do
  S := Sample(X, N):
  for q in Q do
    M[r, q+1] := add(Heaviside~(S -~ q)):
  end do:
end do:
time[real]()-str;

34.479

restart;

with(Statistics):

X := RandomVariable(Normal(0, 1)):

N := 10^6: R := 20: Q := [$0..5]: nQ := numelems(Q):

M  := Matrix(R, nQ, 0):

str:=time[real]():
for r from 1 to R do
  S := Sample(X, N):
  for q in Q do
    tt := Heaviside~(S -~ q):
    M[r, q+1] := evalhf(add(tt[i],i=1..N)):
  end do:
end do:
time[real]()-str;

6.561

restart;

with(Statistics):

X := RandomVariable(Normal(0, 1)):

N := 10^6: R := 20: Q := [$0..5]: nQ := numelems(Q):

M  := Matrix(R, nQ, 0):

K1:=proc(ss,q,N) local i; add(ss[i]>q,i=1..N); end proc:

str:=time[real]():
for r from 1 to R do
  S := Sample(X, N):
  for q in Q do
    M[r, q+1] := evalhf(K1(S,q,N));
  end do:
end do:
time[real]()-str;

5.800

restart;

with(Statistics):

X := RandomVariable(Normal(0, 1)):

N := 10^6: R := 20: Q := [$0..5]: nQ := numelems(Q):

M  := Matrix(R, nQ, 0):

K2:=Compiler:-Compile(proc(ss::Vector(datatype=float[8]),q::float,N::integer)
                        local i; add(`if`(ss[i]>q,1,0),i=1..N);
                      end proc):

str:=time[real]():
for r from 1 to R do
  S := Sample(X, N):
  for q in Q do
    M[r, q+1] := K2(S,q,N);
  end do:
end do:
time[real]()-str;

1.655

 

Download mmc_comp.mw

That was Maple 2019.1 on 64bit Linux. I also tried Maple 2017.2, in which the relative performance was similar.

@Carl Love That's also what I was trying to drive at.

I'd rather see the original problem then some concocted (series?) approximation. And the use of limit as y->infinity on the pade approximation is also odd. The whole thing looks shaky.

@Puneeth Anyone can observe your final call to solve(...,[a,b]) and figure out that you're trying to find a and b. 

What does your computation represent? What do the expressions (which you pass to `pade`) represent? What does n=11 represent?

One mistake is that you set Digits too low. Another is that you use `sum` in some places where `add` would be better.

Another is that (in the statement that assigns to F[k+3] in the loop) you have an instance of F(k+2) which is likely a typo for F[k+2].

Another is that you're missing the closing brace } in the call to solve.

But a bigger mistake is in not telling us properly what you're trying to accomplish.

Is there a question here?

Here is a copy of one of the uploaded images: in case the OP unhelpfully deletes it once again.

What does it mean, your question about Sage on a Maple forum?

Are you trying to ask a question about SageMath usage or syntax? Because, if you are, that has nothing to do with Maple.

Are the contents of those particular Matlab files (of yours) stored purely in plain text?

Perhaps you are describing a pure OS phenomenon on text files, which only MS-Windows controls?

@MapleUser2017 As mentioned, another possibility is an optional keyword parameter (which makes sense for using just a sole name to toggle on the alternate behavior).

Below, passing the name g acts the same as passing g=true (and omitting it acts the same as passing g=false).

restart;
graph := proc(fn::anything, {g::{truefalse, name}:=false})
   if g=false then return fn;
   else return plot(fn, gridlines);
   end if;
end proc:

graph(x^2);
graph(x^2,g);
graph(x^2,g=false);
graph(x^2,g=true);
Multiple optional keyword parameters can also be passed in an arbitrary order.

Don't you suspect that this is a difference between the Classic and (possibly all versions of) the Standard Java GUIs?

First 197 198 199 200 201 202 203 Last Page 199 of 591