tomleslie

13876 Reputation

20 Badges

15 years, 182 days

MaplePrimes Activity


These are replies submitted by tomleslie

@Adam Ledger 

I agree with with Acer, in general, that defining functions with arrow notation ('->') or using unapply() falls into the quick+dirty realm of code. If I was writing rock-solid, maintainable, code for general (ie not just personal) use, I would probbaly avoid both constructs in favour of writing an explict procedure.

However, the examples you provide both work with unapply(), see attached, so I am unclear what your issue is when you claim that " unapply does not work if the function contains indeterminants with indeterminant exponents"

restart:
F:=unapply( (-2*n[2]*n[1]-4*n[2]*n[1]+4*n[1]+n[1])/(-n[1]^2-2*n[2]*n[1]+2*n[3]), n[1], n[2], n[3]);
F(1,2,3);
restart;
F:=unapply( (-2*n[2]*n[1]-4*n[2]*n[1]+4*n[1]+n[1])/(-n[1]^n[2]-2*n[2]*n[1]+2*n[3]), n[1], n[2], n[3]);
F(1,2,3);

proc (n_1, n_2, n_3) options operator, arrow; (-6*n_1*n_2+5*n_1)/(-n_1^2-2*n_1*n_2+2*n_3) end proc

 

-7

 

proc (n_1, n_2, n_3) options operator, arrow; (-6*n_1*n_2+5*n_1)/(-n_1^n_2-2*n_1*n_2+2*n_3) end proc

 

-7

(1)

 

Download unapp.mw

@Adam Ledger 

No way to do this with

S:=(seq(v[k],k=1..NumVARIABLES))->Soutput

but you can achieve the same thing with unapply(), as in

S:=unapply( Soutput, seq(v[k],k=1..NumVARIABLES) )

@Preben Alsholm 

No problems in Maple 18.02 on 64-bit Windows 7

No problems in Maple 2018 on 64-bit Windows 7

Have you followed the installation instructions (contained in the following file) for your OS

Install.html

Pay particular attention to the second bullet, about privileges, in the "Pre-Installation Intructions" section.

Make sure you enter the purchase code and "activate" properly! (items 4 and 5 in the "Install Maple 2017" section

@Muhammad Usman 

You just want me to assume that the tickmarks on the x-axis of the final plot are in radians, and you want these in degrees, then pretty much the same process works.

See the execution group I added to the end of your worksheet in the attached

plotLab2.mw

You are going to have to make your requirement clearer

All I can see is a 290 x 59 matrix, all of whose values are around 1550 - what am I supposed to do with them?

I have a feeling I have done this before - so this time forget your original worksheet, and just tell me what ius wrong with the one I have supplied

restart;

S1:= (1/2)*exp(I*(2*Pi*k*x/T))*((2*T*(4*tau^2*k^2*Pi^2*(4*tau-w)-T^2*w)*I)*exp(-(1/2)*w/tau)*sin(w*Pi*k/T)+2*(2*I)*Pi*k*tau*(4*tau^2*k^2*Pi^2*(-w+2*tau)-T^2*(2*tau+w))*exp(-(1/2)*w/tau)*cos(w*Pi*k/T)+(8*I)*Pi*k*tau^2*(T^2-(2*Pi*k*tau)^2))/(T^2+(2*Pi*k*tau)^2)^2:
S2:= (1/2)*exp(I*(2*Pi*(-k))*x/T)*((2*T*(4*tau^2*(-k)^2*Pi^2*(4*tau-w)-T^2*w)*I)*exp(-(1/2)*w/tau)*sin(-w*Pi*k/T)+((-(2*I)*Pi*k*tau*(4*tau^2*(-k)^2*Pi^2*(-w+2*tau)-T^2*(2*tau+w)))*2)*exp(-(1/2)*w/tau)*cos(-w*Pi*k/T)-(8*I)*Pi*k*tau^2*(T^2-((2*Pi*(-k))*tau)^2))/(T^2+((2*Pi*(-k))*tau)^2)^2:
S3:= S1+S2:
S4:= (T*(4*tau^2*k^2*Pi^2*(4*tau-w)-T^2*w)*exp(-(1/2)*w/tau)*sin(w*Pi*k/T)+2*Pi*k*tau*(4*tau^2*k^2*Pi^2*(-w+2*tau)-T^2*(2*tau+w))*exp(-(1/2)*w/tau)*cos(w*Pi*k/T)+4*Pi*k*tau^2*(T^2-(2*Pi*k*tau)^2))/(T^2+(2*Pi*k*tau)^2)^2*(-2*sin(2*Pi*k*x/T)):

is(simplify(S3)=simplify(S4));

true

(1)

T := M*tau:
w := N*tau:
M := Kappa*N:
Ck := -2*(T*(4*tau^2*k^2*Pi^2*(4*tau-w)-w*T^2)*exp(-(1/2)*w/tau)*sin(w*Pi*k/T)+2*Pi*k*tau*(4*tau^2*k^2*Pi^2*(2*tau-w)-T^2*(2*tau+w))*exp(-(1/2)*w/tau)*cos(w*Pi*k/T)+4*Pi*k*tau^2*(T^2-(2*Pi*k*tau)^2))/(T^2+(2*Pi*k*tau)^2)^2:

S5 := a[0]+Sum(Ck*sin(2*Pi*k*x/T), k = 1 .. m):
S6 := a[0]+Sum(S4, k = 1 .. m):
is(simplify(S5)=simplify(S6));

true

(2)

Q1 := diff(S5, x):
Q2 := diff(S6, x):
is(simplify(Q1) = simplify(Q2));

true

(3)

NULL

Q3 := Sum(2*Ck*Pi*k*cos(2*Pi*k*x/T)/T, k = 1 .. m):
Q4 := Sum(diff(S4, x), k = 1 .. m):
is(simplify(Q3) = simplify(Q4))

true

(4)

``


Download consistent_results.mw

If I download your code simp1.mw and run it in Maple 2018 - answers are not consistent. See attached.

I can reproduce the same behaviour in Maple2017.3 (ie one execution group does not produce the answer 4), but I had to re-execute the whole worksheet a few times to achieve this - and I lost "kernel connection" a couple of times.

Only conclusion I can draw is that the code I proposed produces flaky results: the code you proposed also produces flaky results; therefore not the details of the code, something else (completely unknown to me) is breaking

restart;
assign(seq(a[i] = RootOf(_Z1^6-3*_Z1^2-2*_Z1+11, index = i), i = 1..6)):
ee := a[1]*a[5]+a[2]*a[6]+a[3]*a[4]:
simplify(ee);
evala(%);

RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 5)+RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 6)+RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 4)

 

-(320/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)-(680/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)-(220/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)-(256/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)-(16/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^5-(16/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^3*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^4+(32/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^5-(16/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^4-(32/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^3*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^3-(24/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^4-(56/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^3-(16/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^3*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^2-(60/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^2+(64/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^2+(128/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)-(324/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^3+(110/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2+(40/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^5-(128/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^4-(196/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^3-(18/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^2+1780/449+(228/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^3+(66/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2-(232/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)+(24/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^5+(64/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^4+(164/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^3+(130/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^2-(192/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)-(32/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^5+(88/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^4+(128/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^3+(256/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)-(32/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^3*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^5-(48/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^3*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^3-(88/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^3*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^2+(256/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^3*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)+(32/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^5-(48/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^4-(48/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^3+(40/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)^2-(256/449)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)^2*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)

(1)

restart;
assign(seq(a[i] = RootOf(_Z1^6-3*_Z1^2-2*_Z1+11, index = i), i = 1..6)):
ee := a[1]*a[5]+a[2]*a[6]+a[3]*a[4]:
simplify(ee);
evala(%);

RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 5)+RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 6)+RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 4)

 

4

(2)

restart;
assign(seq(a[i] = RootOf(_Z1^6-3*_Z1^2-2*_Z1+11, index = i), i = 1..6)):
ee := a[1]*a[5]+a[2]*a[6]+a[3]*a[4]:
simplify(ee);
evala(%);

RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 5)+RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 6)+RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 4)

 

4

(3)

restart;
assign(seq(a[i] = RootOf(_Z1^6-3*_Z1^2-2*_Z1+11, index = i), i = 1..6)):
ee := a[1]*a[5]+a[2]*a[6]+a[3]*a[4]:
simplify(ee);
evala(%);

RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 1)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 5)+RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 2)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 6)+RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 3)*RootOf(_Z^6-3*_Z^2-2*_Z+11, index = 4)

 

4

(4)

 


 

Download simp1Test.mw

You seem to be asserting that if a summand is "well-behaved+analytic" - and I'll add in continuous and differentiable, then a closed for solution must be possible. You believe this, I don't.

Simple question - provide the closed-form solution for

sum(ln(k), k=1..m)

 

because I *can* get the desired answer in both Maple2017.3 and Maple2018.0, see below - but not consistently in either!

If I just re-execute each worksheet using !!!, I seem to get a different answer each time. About once in every ten re-executions, the answer 4 appears - so I guess I was just "lucky" with my original post!!

Since the 'restart' is in its own execution group - I ought to be getting a "consistent" start state, but the fact that I get different answers.......I have no idea what is happening. I've never seen this kind of inconsistency in Maple before!

The fact that it seems to be "equally inconsistent" (if that makes any sense at all!) in Maple2017.3 and Maple 2018.0 is pretty mind-blowing!

In Maple2015.2 and Maple2016.2, I *seem* to get consistent answers - but never the desired value of 4

restart;

kernelopts(version);
seq
( assign( a[i], RootOf( _Z1^6-3*_Z1^2-2*_Z1+11,index = i)),
  i = 1 .. 6
);
ee := a[1]*a[5]+a[2]*a[6]+a[3]*a[4]:
evala(ee);

`Maple 2017.3, X86 64 WINDOWS, Sep 13 2017, Build ID 1262472`

 

4

(1)

 

Download m2017evala.mw

 

 

restart;

kernelopts(version);
seq
( assign( a[i], RootOf( _Z1^6-3*_Z1^2-2*_Z1+11,index = i)),
  i = 1 .. 6
);
ee := a[1]*a[5]+a[2]*a[6]+a[3]*a[4]:
evala(ee);

`Maple 2018.0, X86 64 WINDOWS, Mar 9 2018, Build ID 1298750`

 

4

(1)

 

Download m2018evala.mw

Your assertion is that since Maple can compute sum(f(k,x), k=1..m), as a closed form, it *must* be able to compute sum(C(k)*f(k,x), k=1..m) as a closed form. I'll set a simple example -suppose f(k,x)=1 for all k, x. Your assertion is now that Maple should be able to calculate sum(C(k), k=1..m) for any C(k): ie all sums have closed forms! Get real

You make the statement

So below I have made additions to the worksheet @tomleslie provided.  You will see that I attempt to use "ACTIVE" sum to evaluate what appears to be the derivatives of both S5 & S6.  In doing so my computer chokes on the results & MAPLE crashes.  This is a problem since the "ACTIVE" sum is the 1st choice of an unwitting user to select since it appears in the GUI palette.

 

So my question on this particular demonstration why can the computer evaluate S5 & S6 using the "ACTIVE" sum; whereas, it cannot be done with Q5 & Q6?

You state "why can the computer evaluate S5 & S6 using the "ACTIVE" sum". The original worksheet I supplied did not evaluate S5 and S6 using the "active sum": it used the insert Sum() The worksheet in your response does not evaluate S5 and S6 using the "active sum": it uses the inert Sum() There is no evidence anywherein these two worksheets that S5 and S6 can be "evaluated" using the "active sum". Now if I  examine S5 (or S6) with my "calibrated eyeball", I make the educated guess that a "simple" closed-form solution is not possible: Fourier series would be so much easier if it were possible (and associated textbooks would be a lot shorter!).

To be fair, I am prepared to admit that if I attempt to evaluate S5 using an active sum(), then (eventually, and it takes a while!) I can get a response in terms of multiple (nested?) hypergeom() functions. However since this response occupies about 8 screenfuls, contains 65 hypergeom() functions, each instance of which represents an infinite sum of the ratio of products of Pochhammer functions - I really wouldn't consider this "progress". It may (or may not) be possible to obtain simlar results for S6, Q5, Q6 - I haven't got the patience to try. Using Maple to produce really complicated expressions from quite simple ones seems more than a little pointless.

Nothing in your original worksheet requires the use of "active" sum() commands. Using active sum() commands just complicates things. I prefer to go for "simple". If you want to get unnecessarily complicated, feel free - just don't expect me to join you.

####################################

On the subject of choice of commands for Maple palettes. If Maple dispensed with all palettes, I have no problem, since I never use them.

I suppose if I wanted something simple like the sum of all integers from 1..m, then sum() will return the "textbook" closed form, Sum() will do nothing (because it is inert), and add() will barf. Which would you prefer?

I don't really think the choice of commands for palettes is a worthwhile discussion for a user forum, although you are perfectly free to make your suggestions known to the designers at Maplesoft.

OP asks for integer values in the range 500..50000.

plots:-pointplot([seq([t,R(t)], t=500..50000)]);

The above (note capitalization and parentheses) will generate the required plot - but with 45000 points, and hence 45000 function evaluations. If R(t) is reasonably smooth, it will be much quicker to use every 100-th point (say), with

plots:-pointplot([seq([t,R(t)], t=500..50000,100)]);

because unless you specify this function, I doubt that anyone will be able to help

Post code which clearly demonstrates your problem.

If I try to run the code which you have posted, then it always produces an ERROR (see attached).

Now I'm pretty sure that I can see the reasons for these errors, but am  not inclined to address these until you provide code demonstrating your *declared* basic problem, that " it is very very slow". Your code is not slow - it doesn't seem to work, at least ofr the values of the parameter 'm' which I tried. (I had to "guess" values for 'm', since you do not supply any)

restart;
Cosenos := proc (m, x)
                 local x0, y, j0, k, K0, K1, S, y1, y2, r1, r2, d;
                 K0 := NULL;
                 K1 := NULL;
                 S := NULL;
                 d := nops(x);
                 for k to d-1 do
                     if   evalf(x[k]) = 1
                     then j0 := m
                     else j0 := 1+floor(x[k]*m)
                     end if;
                     K0 := K0, [(j0-1)/m, j0/m]
                 end do;
                 K0 := [K0];
                 r1 := K0[1][1];
                 r2 := K0[1][2];
                 for k from 2 to nops(K0) do
                     S := solve( {K0[k][1] <= 1/2-(1/2)*cos(m^(k-1)*Pi*t)
                                  and
                                  1/2-(1/2)*cos(m^(k-1)*Pi*t) <= K0[k][2],
                                   r1 <= t and t <= r2
                                 },
                                 t
                                );
                           r1 := min(evalf(lhs(S[2])), evalf(rhs(S[1])));
                           r2 := max(evalf(lhs(S[2])), evalf(rhs(S[1])))
                  end do;
                  S := fsolve(1/2-(1/2)*cos(m^(d-1)*Pi*t) = x[d], t = r1 .. r2);
                  y := x[1]-S;
                  x0 := x[1];
                  for k from 2 to d do
                      x0 := x0, 1/2-(1/2)*cos(m^(k-1)*Pi*S);
                      y := y, x[k]-1/2+(1/2)*cos(m^(k-1)*Pi*S)
                  end do;
                  y := `<,>`(y);
                  return evalf([x0]), evalf(Norm(y))
            end proc:

x:=[0.23423,1,0.4534,0.5345,0.244,0.4534];
Cosenos(1,x);
Cosenos(2,x);
Cosenos(3,x);

[.23423, 1, .4534, .5345, .244, .4534]

 

Error, (in Cosenos) invalid subscript selector

 

Error, (in Cosenos) invalid input: lhs received {-1/2 <= t, t <= -3/8}, which is not valid for its 1st argument, expr

 

Error, (in Cosenos) invalid input: lhs received {t <= -(1/27)*(29*Pi+arccos(1/3))/Pi, -(1/27)*(30*Pi-arccos(1/3))/Pi <= t}, which is not valid for its 1st argument, expr

 

 

Download badProc.mw

First 101 102 103 104 105 106 107 Last Page 103 of 207