acer

32303 Reputation

29 Badges

19 years, 309 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Maybe you could create a Matrix inside the procedure get_quantities, instead of a table like q1, and then have that procedure assign directly to the entries of that Matrix, and have that routine also return that Matrix? Ie, right at the beginning of the procedure, insert a line like the following, and leave the rest as it is.

q1 := Matrix(4,4);

Having done it your original way, can you get the conversion of table q1 to a 4x4 Matrix like so, assuming q1's indices are valid?

Matrix(4,4,{op(map(op@lhs=rhs, op(eval(q1))))});

acer

> Optimization:-Maximize( diff(2*Pi*(x+1)*(ln(sqrt(x)+1)),x$4), x=0..10 );
              [0.0427548197437215699, [x = 2.75891892689316043]]

acer

Use := instead of = to assign a value to a variable. Eg, x:=3

acer

ko:=2*Pi/v*f;v:=2.998*10^8;f:=2.525*10^9:
Lo:=29.379;Wo:=34.477:

evalf(1/(120*Pi^2)*Int(eval((sin(ko*W/2*cos(theta))
  /cos(theta))^2*sin(theta)^3
  *BesselJ(0,ko*L*sin(theta)),
                            [L=Lo,W=Wo]),
                       theta=0..Pi,
                       'method'='_d01akc'));

I got a result of -0.01815483673 in 50sec or so, using default precision and error tolerance.

It may be that you could speed it up by using a faster J0, see here for some idea on that.

acer

At least in some cases (eg. no method specified) it seems that `evalf/int` is using all that time and memory just getting started. I have not looked into it, but I suspect that it is either expanding the expression for the integrand or going to a lot of trouble investigating its possible singularities.

One way to prevent this might be to instead supply the integrand in procedure form. For example,

> kernelopts(printbytes=false):
>
> expr := (700.*(8.54845000761408*10^(-14)+1.89764579559636*10^(-20)*x
>   -7.30287375722720*10^(-15)*sqrt(-4.88741578151207-0.117848792714772e-5*x
>   +5.88741696*(7.0875263*10^(-8)*x+.999999929124737)^2)
>   -7.30287375722720*10^(-15)*sqrt(-4.88740033154292-0.166284570377619e-4*x
>   +5.88741696*(0.1000049503e-5*x+.999998999950497)^2)))*(0.1000049503e-5*x
>   +.999998999950497)^699:
>
> infolevel[`evalf/int`]:=1:
>
> p := (igrand,var,eps,dig) ->
>          evalf(Int(unapply(igrand,var),0..1,
>                ':-epsilon'=eps,':-digits'=dig)):
>
> (st,ba):=time(),kernelopts(bytesalloc):
> p(expr,x,5e-48,50);

evalf/int/quadexp:   "applying double-exponential method"
From quadexp, result = .49597789486775255522822143063830103993131048383834929e\
-10   integrand evals = 251
error = .67577561574848300181818879875801379481549548196653190e-51
                                                                 -10
          0.49597789486775255522822143063830103993131048383835 10
 
> time()-st,kernelopts(bytesalloc)-ba;
                                0.133, 4586680
 
>
> (st,ba):=time(),kernelopts(bytesalloc):
> p(expr,x,5e-999,1000);

evalf/int/quadexp:   "applying double-exponential method"
From quadexp, result = .495977894867752555228221430638301039931310492022899466\
644863155892848792957698316173663416356289280340905183621150933083273451751150\
688422251537570640162013777422635304107239944450854442949767766202422446813541\
291842170676719302147344953018224571852568056425318369349620141132215664822215\
819287624610431244975489292421620589776615490634158715997539524368315885124846\
153868928963307985971934432936330690528228760948143732704933423546808015212843\
065059133506284234900991409770961781215958171389339091813958975665245259554991\
181406210188106754305841450043143640081874455867725359231876948238091718080644\
231647469827063510487344935299299152255130074981136941456133991963011948044995\
829920234596881886237877233743689759617015486304687740377240361926300875357677\
049754829216907385465518935029639003669159179549426024797385784517069670593408\
967451285579119784282997998255078239510298598777672271590769801905513044439130\
719274573082826119220723147476362297182784530976883370888472407370292016105096\
461010654172468e-10   integrand evals = 8191   error = .1068957763222413909290\
828331581885717950307856444575520792184164009774485992862378877061120684652068\
714145198449315644786112745330862670544704617614956186071965227208091156796992\
256598099347440766070207316614597873130731815998688007568359515194511680633176\
396158809188160122103800317522749656609284273976702105353889250453265858917615\
486718998884574997644271626928718028210940547954748026592216995188832704352515\
979352254760364928590099305101723248523293242587788666434766509931861178185114\
847526054524146290792220280179815449593112497516125009690794504185125187551950\
088621959082874712868649577856815778879385492925898730268912091565390712055242\
330338275797393922906922143071412442829077625378206709586863625907087434233770\
070603377405265805862337264135543276582539463159570394335875648239786455475575\
619505354210999282781782450683806487521491218373429892166139026584437340700477\
878225633094049331656000341766679459768696159800547988877948596749307806759845\
79938998234766655481151608564670377169577799486e-1002

0.4959778948677525552282214306383010399313104920228994666448631558928487929\
    57698316173663416356289280340905183621150933083273451751150688422251537\
    57064016201377742263530410723994445085444294976776620242244681354129184\
    21706767193021473449530182245718525680564253183693496201411322156648222\
    15819287624610431244975489292421620589776615490634158715997539524368315\
    88512484615386892896330798597193443293633069052822876094814373270493342\
    35468080152128430650591335062842349009914097709617812159581713893390918\
    13958975665245259554991181406210188106754305841450043143640081874455867\
    72535923187694823809171808064423164746982706351048734493529929915225513\
    00749811369414561339919630119480449958299202345968818862378772337436897\
    59617015486304687740377240361926300875357677049754829216907385465518935\
    02963900366915917954942602479738578451706967059340896745128557911978428\
    29979982550782395102985987776722715907698019055130444391307192745730828\
    26119220723147476362297182784530976883370888472407370292016105096461010\
 
           -10
    6542 10
 
> time()-st,kernelopts(bytesalloc)-ba;
                                20.330, 6421352

You wouldn't necessarily need to create a procedure like p above. I just did that to make it easier to try various values. The key bit was unapplying expr with respect to variable x.

You might also wish to control the epsilon and digits optional parameters separately.

I notice that when specified to use 50 digits of working precision it claims that the resulting error estimate is something like 10^(-51). But only 44 digits or so of that result computed at digits=50 agree with the second result computed at digits=100. Hence you may wish to consider the error estimate (printed as userinfo messages) with circumspection, especially from the computation done at the highest choice of the digits parameter. You may be safer instead doing a pair of computations, like above, and accepting only the digits that agree.

acer

Are you allowed to use the StringTools package? Its routines Rotate and CharacterMap can make the application of a candidate solution simple.

S:="fsqFsHn sGGousG":

ABET:="ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz":

Now find the i such that this routine produces the decrypted message.

f := (i,abet,s) -> StringTools:-CharacterMap(
                         StringTools:-Rotate(abet,i),abet,s);

acer

Do you just want something that works? Or do you want something efficient for really large numbers of intervals?

If you know that a < c <... and b < d < ... then you could do a discrete binary search (over, say, the lower interval values).

What do you know about a,b,c,d,...?

Suppose the intervals are distinct and not overlapping, which makes it easier. Sort them by interval lower value. Then take the middle of those (ie. 5th of 9, not closest to numeric midpoint of upper and lower range bounds). Is x larger or smaller than the lower interval endpoint of the middle interval? The answer tells you which half of the set of intervals x belongs to. (Maybe check also whether x is inside that middle interval.) Repeat this whole process, on just that half of the set of intervals. And repeat...

acer

What are the dimensions of data?

[edited] I wrote something not right here. But I see that you figured it out, that something was being accessed with an index out of bounds.

acer

We already did.

acer

Let's call the encrypted string S and the decrypted original Q. There is a double e (ee) in the S. So that's probably not blank in Q, because the phrase wouldn't have a double blank.

What letter falls enough times at a pretty regular frequency in S, that might be the blank in Q? From the above, it isn't e. Assume that it's a.

Now, what does the e in S become in Q? What letters can occur in doubles? Perhaps o, or l, or s. But e occurs often in S. So it is probably a letter in Q that usually occurs often. Suppose that e in S is o in Q.

You said that the alphabet to use is " abcdefghijklmnopqrstuvwxyz".

Consider the guess a -> blank and o -> e. That means that you need a function finv (x) such that finv(1)=0 and finv(15)=5. In modular terms,  you would have,

finv(x):: x -> (a*x + b) mod 27

15 = (a*5 + b) mod 27
0 = (a + b) mod 27

If you solve that, you should get a=24 and b=3. But a has to be coprime to 27 for an affine cipher! Oops. So the guess is wrong.

How about the guess that e in S is actually e in Q as well. There are words that end in double e. (I'll be nice, this leads to the solution, if you solve the pair of modular equations using finv(1)=0 and finv(5)=5.)

In Maple, once you have the a and the b,

S := "fmw segjaweoouanerj a ceyqrype aswaheoaqbrqabeafrua eeaojerf afmjeayperjpu":

with(StringTools):

abet := " abcdefghijklmnopqrstuvwxyz":
L := Explode(abet):

f := x -> 1/a*(x-b) mod 27:

nL:=[seq( L[f(i)+1], i=0..26 )];
nabet:=Implode(nL);

CharacterMap(nabet,abet,S);

nb.  Using Joe's  set-up above, you'd  apply  finv := x -> A*x+B mod 27 with his A and B instead of my f using my a and b. Both solve it.

acer

It depends on how big the number is. I should have scaled n by 1.0 inside the log call.

> restart:
> n:=77^898789:
> f1 := x -> floor(log[10](1.0*x)/3.):
>  time( f1(n) );
                                     0.156

> n:=77^898789:
> f2 := x -> iquo(ilog10(x),3):
> time( f2(n) );
                                     0.066

Once the numbers get into the few millions of digits, the timing difference starts to show.

acer

The problem that you describe can occur if you fail to create a Library archive (.mla) in which to savelib.

See either the ?march or ?LibraryTools:-Create help-page.

When there is no available .mla archive file in which to save, the contents will get written out to a .m file. But that .m file will only contain a "shell" of the module, in your case, and not the whole thing.

acer

> f := n -> map(parse,[StringTools[LengthSplit](convert(n,string),3)]):
 
> f(394737234242);
                             [394, 737, 234, 242]
> g := proc(n::integer)
> local i, r, p;
>     r := n;
>     for i to floor(log[10](n)/3.) + 1 do
>         p[i] := irem(r, 1000, 'r');
>     end do;
>     convert(p,list);
> end proc:

> g(394737234242);
                             [242, 234, 737, 394]

Those are just two of many different fun ways to do this in Maple.

acer

> maximize(x*exp(-x),location);
                         exp(-1), {[{x = 1}, exp(-1)]}

> Optimization:-Maximize(x*exp(-x),x=-10..10);
               [0.367879441171442334, [x = 1.00000001071262612]]
 
> Optimization:-Maximize(x*exp(-x),method=nonlinearsimplex);
                       [0.367879441171442334, [x = 1.]]

acer

> M:=Matrix(3,4);
                                 [0    0    0    0]
                                 [                ]
                            M := [0    0    0    0]
                                 [                ]
                                 [0    0    0    0]
 
> M(4,1..):=<1,2,3,4>:

> M;
                              [0    0    0    0]
                              [                ]
                              [0    0    0    0]
                              [                ]
                              [0    0    0    0]
                              [                ]
                              [1    2    3    4]

acer

First 307 308 309 310 311 312 313 Last Page 309 of 336