acer

32747 Reputation

29 Badges

20 years, 110 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

Please don't post duplicates of the problem, as you try and figure out correct syntax and problem formulation.

@animeplot I could spend some time on the weekend writing Maplet code to do all of that, so try and see what might be happening. But it'd save time and effort (and possibly red-herrings if my code did something importantly different) if you could just let me look at your full source.

If you'd rather not post it all here (in a single worksheet of zipped file) as an uploaded attachment on a Comment/Reply then please feel free to send me a private message via Mapleprimes. I'd respond via emai, and then you'd have an email address to send it to. I understand, if you are not free to do this, though.

@Rouben Rostamian  That is a very good answer (as is Kitonum's).

I have submitted a bug report, suggesting that the Help pages for commands like plottools:-disk contain such useful and directly accessible Examples. (That is to say, the details in the style option's description on the ?plot,options page are too far removed from the ?plottools,disk Help page.) And the same goes for several other plottools commands' individual Help pages.

[edited above]

@Christopher2222 That is because `sum` can act like `add` , in the sense of adding up a small finite number of terms. IIRC it is a cutoff of something like 1000 terms. So for that small range it acts like one of the earlier responses. Above that cutoff it tries for actual symbolic summation, striving for a closed form formula.

@Kitonum Ahh. Thanks. I ought to have tried at least this:
 

Q:=Sum(cos(2*Pi*k/(b-a+1)), k=a..b):
value(eval(Q,a=0));
                       0

@Kitonum 

restart;
Q:=combine(sum(cos(2*Pi*k/(b-a+1)), k=a..b)):

simplify(expand(simplify(convert(eval(Q,[a=0]),exp)))) assuming nonnegint; # job done
                             0

eval(numer(Q)/denom(Q), [a=0, b=214748363]); # for fun
                             0

@Preben Alsholm Professor Ogilvie's comments relate to the Classic GUI, I believe.

In the Classic GUI the double-underscore syntax for a name such as xxx__yyy does not produce pretty-printed output with a subscripted name. Moreover in the Classic GUI the mechanism for pretty-printing input does render indexed names as subscripted names, but it does not render such double-underscore syntax names as subscripted names.

 

It's a pity that it needs a followup call to simplify ( or combine, or convert(...,exp) ) to resolve the result to zero, especially when it can do these:

sum(sin(k), k=-a..a) assuming a::integer;

                    0

sum(sin(k), k=-a..a) assuming a::real;

                    0

@Rouben Rostamian  I could also note that the numeric values are attained when accessing the converted list.

And the behavior allows both the Vector and the list entries to be updated when the assigned values for a and b change. That aspect of consistency might be considered desirable.

restart;

V:=Vector([a,b]);

_rtable[18446884068502819054]

a,b := 2,3;

2, 3

L:=convert(V,list);

[a, b]

V[1], L[1];
V[2], L[2];

2, 2

3, 3

L;

[2, 3]

V;

_rtable[18446884068502819054]

lprint(V);

Vector[column](2, {1 = a, 2 = b}, datatype = anything, storage = rectangular, order = Fortran_order, shape = [])

lprint(eval(L,1)):

[a, b]

a,b := 7,8;

7, 8

V;

_rtable[18446884068502819054]

L;

[7, 8]

 

Download Vector_list.mw

@tomleslie 

Sure, that seems a fine way to compute r(n) quickly even for large n. Great point!

But the original question was about why n*exp(1)*GAMMA(n,1) didn't immediately produce an integer, so my Answer was intended as an explanation (and workaround) for using that closed-form result.

The crossover value of n for timing of my method and yours seems to be about n=2500 or so (on my 64bit Linux, Maple 2017.3). But your method is always quick, and certainly straightforward, while mine appears to require less increase in memory allocation.

restart;

r := rsolve({u(n)=n*(u(n-1)+1), u(0)=0}, u, 'makeproc'):

CodeTools:-Usage(r(1000)):

memory used=1.60MiB, alloc change=64.00MiB, cpu time=32.00ms, real time=31.00ms, gc time=12.00ms

restart;

r := rsolve({u(n)=n*(u(n-1)+1), u(0)=0}, u):

S:=unapply('simplify'(convert(simplify(value(r)),hypergeom)),n):

CodeTools:-Usage(S(1000)):

memory used=4.16MiB, alloc change=0 bytes, cpu time=8.00ms, real time=10.00ms, gc time=0ns

restart;

r := rsolve({u(n)=n*(u(n-1)+1), u(0)=0}, u, 'makeproc'):

CodeTools:-Usage(r(2500)):

memory used=10.70MiB, alloc change=64.00MiB, cpu time=36.00ms, real time=37.00ms, gc time=16.00ms

restart;

r := rsolve({u(n)=n*(u(n-1)+1), u(0)=0}, u):

S:=unapply('simplify'(convert(simplify(value(r)),hypergeom)),n):

CodeTools:-Usage(S(2500)):

memory used=28.68MiB, alloc change=3.41MiB, cpu time=36.00ms, real time=34.00ms, gc time=0ns

restart;

r := rsolve({u(n)=n*(u(n-1)+1), u(0)=0}, u, 'makeproc'):

CodeTools:-Usage(r(7000)):

memory used=94.35MiB, alloc change=123.49MiB, cpu time=163.00ms, real time=155.00ms, gc time=68.00ms

restart;

r := rsolve({u(n)=n*(u(n-1)+1), u(0)=0}, u):

S:=unapply('simplify'(convert(simplify(value(r)),hypergeom)),n):

CodeTools:-Usage(S(7000)):

memory used=251.22MiB, alloc change=27.50MiB, cpu time=384.00ms, real time=350.00ms, gc time=164.00ms

 


Download crossover.mw

Since Kitonum kindly pointed out that GAMMA(n,1) doesn't produce an "expanded" result like integer*exp(-1) for n>50, here is a revised version which does.

For large n>100 it is faster than evaluating the sum only after substituting the integer value of `n`. For very large n it is much faster.

restart;

r := rsolve({u(n)=n*(u(n-1)+1), u(0)=0}, u):

S:=unapply('simplify'(convert(simplify(value(r)),hypergeom)),n);

proc (n) options operator, arrow; simplify(n*exp(1)*(GAMMA(n)-hypergeom([n], [n+1], -1)/n)) end proc

seq(S(i), i=57..60);

110163588853530184980727482893521304479399855114493057608241578732074256106649, 6389488153504750728882194007824235659805191596640597341278011566460306854185700, 376979801056780293004049446461629903928506304201795243135402682421158104396956359, 22618788063406817580242966787697794235710378252107714588124160945269486263817381600

CodeTools:-Usage(S(7000)):

memory used=251.17MiB, alloc change=27.49MiB, cpu time=428.00ms, real time=357.00ms, gc time=200.00ms

restart;

r := rsolve({u(n)=n*(u(n-1)+1), u(0)=0}, u):

SS:=s->simplify(value(eval(r, n=s))):

seq(SS(i), i=57..60);

110163588853530184980727482893521304479399855114493057608241578732074256106649, 6389488153504750728882194007824235659805191596640597341278011566460306854185700, 376979801056780293004049446461629903928506304201795243135402682421158104396956359, 22618788063406817580242966787697794235710378252107714588124160945269486263817381600

CodeTools:-Usage(SS(7000)):
 

memory used=1.34GiB, alloc change=342.50MiB, cpu time=12.30s, real time=11.38s, gc time=2.14s

 

Download exp_combine_2.mw

Another faster way to get the final results as explicit integers, for n>50, is,

S:=unapply('combine'('convert'(simplify(value(r)),elementary),exp),n);

@Jjjones98 My code assumes (at least) that there is one local minimum per revolution, and that a full revolution involves rotating by two Pi radians, no? Do your parameter values change that!?

If in doubt then please just attach what you've got so far in an uploaded worksheet (bug green arrow). Hammering out such details would likely be easy to do. How long you'd need to wait would just depend on people's schedules (e.g. I'm away from a computer today)

@Jjjones98 

Ignore the animation, as you certainly don't need to do anything by rough visualization. The main point of the code I showed there was the way to (programmatically) run until the next event, as a repeated operation, storing the phi values for each perihelion event. Just look at the line where I print a message using each, in a loop. You could do whatever you want with the stored perihelion event phi values. Compare them, compare their differences, or whatever you want. Recall that your original difficulty was in getting your hands on those phi values, and my code gets you those.

As for your plotting question, I don't understand what you mean by, "for r(phi) against r for a range of phi".

@nm Forced splitting of radicals can produce a result which is not valid , ie. not a correct factorization.

@brian bovril It consistently works fine for me, as long as I ensure that the generated images folder/directory is present in the same location as the exported .html file (or copy of same).

When I exported to .html from the Maple GUI there was a popup menu asking about "HTML Export Options", and there I chose "GIF" for representing "Math expressions".

If I copy the .html file to a new location but do not copy its whole associated images folder in a corresponding, new relatively located folder/subdirectory, then naturally the best my browser can do is show the value from the alt tags of the img items.

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