acer

32480 Reputation

29 Badges

20 years, 6 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Maybe you could use the Statistics package, with high working precision.

> restart:with(Statistics):

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

> evalf[50](2*CDF(X,1)-1);
             0.68268949213708589717046509126407584495582593345319
 
> evalf[50](Quantile(X,(%+1)/2));
             0.99999999999999999999999999999999999999999999999997

> evalf[50](Quantile(X,CDF(X,1)));
             0.99999999999999999999999999999999999999999999999996

Did I do that right?

acer

Use Array instead of array, with the first letter capitalized.

A:=Array(1..3):
for i from 1 to 3 do
  A[i]:=f(i);
end do:
A;
                           [f(1) f(2) f(3)]

B:=Array(1..3,i->f(i));
                         B:=[f(1) f(2) f(3)]

See the help-page ?Array

acer

Have you tried using `map` to apply `diff` to each entry of the Vector?

acer

> restart:
> H:=Array(1..2^16,datatype=float[8],storage=rectangular,order=C_order);
                              [ 1..65536 1-D Array   ]
                         H := [ Data Type: float[8]  ]
                              [ Storage: rectangular ]
                              [ Order: C_order       ]
 
> rtable_dims(H);
                                  1 .. 65536
 
> rtable_options(H);
 datatype = float[8], subtype = Array, storage = rectangular, order = C_order
 
> rtable_options(H,order,storage);
                             C_order, rectangular

This is one of a few such helpful routines which can be used together to copy an Array/Matrix/Vector.

> P:=Array(1..3,[11,13,17],datatype=float[8],storage=rectangular,order=C_order);
                             P := [11., 13., 17.]
 
> rtable(rtable_dims(P),rtable_elems(P),rtable_options(P));
                                [11., 13., 17.]
And the `copy` routine does it even more carefully,
> interface(verboseproc=3):
> showstat(copy,2);
 
copy := proc(A)
local X, r, e;
       ...
   2     rtable(rtable_indfns(A),rtable_dims(A),A,rtable_options(A),readonly = false)
       ...
end proc

acer

Note that below I use an Array (capitalized).

> X:=Array(3): # originally with 3 elements only

> for i from 1 to 5 do
>  X(i):=i^2;
> end do:

> X; # using Maple 13, X can be "grown" to be of length 5
                        [1 4 9 16 25]

In much older versions of Maple, I would not have been able to grow X in size, and would have been limited to its original 3 entry spots. And I would have had to use the syntax X[i]:=... instead of X(i):=...

I could also have used a table structure, which is yet another type of mutable structure with an open-ended number of entries.

Note also that X was not created using X:=[...] as that would have created a list rather than an Array. See here for a bit more about comparison between Maple's data structures.

acer

I may be in the minority here, but I prefer using the Matrix() constructor with its listlist argument for the data. For example, I find that I only very rarely get the syntax wrong for something like this,

Matrix([[1,3],[-3,1]]);

You might also consider guessing what the common syntax mistakes are with using the angle brackets, and perhaps even convert/accept typical mistakes. For example, you could convert, <<1,3>,<3,-1>> and give partial or full marks.

acer

The Tolerances package uses evalr.

> R1:=INTERVAL(76.0 .. 84.0):
> R2:=INTERVAL(114.0 .. 126.0):
> Req:=R1*R2/(R1+R2):

> evalr(Req);
                     INTERVAL(41.25714285 .. 55.70526317)
 
> evalr(1/(expand(1/Req)));
                     INTERVAL(45.59999998 .. 50.40000003)

Now, that second result was just lucky. Terms simplified and repeated instances of R1 and R2 vanished before evalr got its hands on them.

Are you trying to bound the behaviour of the system, given bounds on the capabilities of the components? If so, then I can imagine that a Tolerances package that functions well could be useful.

If not, then are you trying to characterize behaviour given physical measurements of the resistances (with of course have an associated measurement error)? In that case, is the ScientificErrorAnalysis package of any use? Note that for that package, the error does not represent an interval, but rather a distribution.

> restart:

> R1:=ScientificErrorAnalysis:-Quantity(80.1,4.0)*Unit(ohm):
> R2:=ScientificErrorAnalysis:-Quantity(120.1,6.0)*Unit(ohm):

> Req:=combine(R1*R2/(R1+R2),errors);
           Req := Quantity(48.05199800 [Omega], 1.730531812 [Omega])

acer

map(trunc,a);

map(round,a);
Or, in Maple 13,
trunc~(a);

round~(a);
Notice that the ~ elementwise operation preserved the float[8] datatype, which is why those two results came back as floats.

acer

With a small but nonzero chance (probability) you might have to wait for 1000 rolls before that happens. And an even smaller chance that you'd have to wait a million rolls.

So your question could do with an associated probabaility in order to make good sense.

More often, the reverse is asked. For example, "What is the probability that I would roll all those many instances within my first 500 rolls?"

I'm assuming that you're not just asking the simplistic question: "What's the minimal number of rolls needed for it to be possible?" (ie. 1+2+3+4+5+6)

acer

See the ?evalf help-page.

acer

You may be able to write a Compilable proc that does what falls inside your i-loop, and possibly also to handle the sorting that follows it.

See here for an example of explicit code to do Statistics:-StandardDeviation, which may be used with Compiler:-Compile.

Such a Compilable proc might also accept a datatype=float[8] Vector parameter SH and act on that inplace, by populating it with the looped results. Of course, the datatype=float[8] Matrix/Array StockReturn would be one of its input parameters.

You could either loop and call such a proc, passing in each permutation, of even better you could pass in the full `per` permutation (as acceptable data for the Compiler) and loop inside the very proc itself.

acer

I've now got a routine that induces barrel, pincushion, and moustache distortion, which seems to work well as a prototype. Right now, it takes about .2-.25 sec on an 800x600 jpg (as a three-layer float[8] Array, in Maple).

I hope to hammer on it a bit more, to attain even less image degradation by using ArrayInterpolation. And then get the inverted operations. And then post the module code.

acer

If V is in fact already a Maple list of (variable) names then you could try plex(op(V)) as argument to Grobner:-Basis.

acer

I'm pretty sure this could be done fine in Maple.

I'd probably start with a simple design like this, beginning with correcting barrel distortion. Write a procedure that accepts as parameters both the input float[8] Array and the output-container float[8] Array (to hold the result), and any optional scalar parameters that characterize the distortion. Then implement the formulae available in several places on the web, to write corrected data into the output-container. Use variable and parameter typing, so that the procedure could be hit with the Compiler. This procedure would return NULL, as it would act inplace on the reuable output-container, minimizing garbage production.

Once that first proc were satisfactory, create a module package with that proc as one export. Write other exports for other distortions.

acer

Use ':-y' for that. It's a reference to the global name y, not the local parameter name (and protected by single uneval quotes, just in case :-y has been assigned).

acer

First 291 292 293 294 295 296 297 Last Page 293 of 337