tsunamiBTP

292 Reputation

9 Badges

15 years, 182 days

MaplePrimes Activity


These are replies submitted by tsunamiBTP

@acer 

 I'd counter that you might not be reading all the responses with enough attention to what the thrust might be.

In the thread that was originally about fsolve vs Rootfinding I did not recognize the difference in the add vs sum.  Again, the subtlties in such commands are not always evident to the questioner.  You demonstrated effectively between fsolve & RootFinding, but to expect me as the questioner to recognize the difference between add vs sum, it simply did not happen in this instance.

I posted a new question on the issue of add vs sum & hopefully it will not be deleted.

@acer 

I guess I did employ the add command.  I guess I assumed the add & sum were one & the same.  I do not see anywhere that you distinguished between the 2 other than use the command in defining S1 in your code.  The issue on that thread was the difference between fsolve vs RootFinding so the underlying subtleties between add & sum were not discussed so I would have never known the difference without you directly mentioning it or that I stumble upon some discrepancy in future results.

This is where your responses seem a bit terse because you are assuming the person you are addressing has this underlying knowledge & that is rarely the case; hence, the need for the MAPLEPrimes question forum.  I think I will have some follow on questions about this distinction & will post a NEW question at that time & hopefully it will not be deleted by you.

@acer 

In my Answer to a related Question of yours (Dec 15, 2017) I showed you how to obtain something like a 500-1000 fold speedup in evaluating such summations. That question also involved rootfinding, but the essence of accelerating the summations is the same. You never responded to my Answer, and in the interim have made several other postings about performance of related summations -- without any attempt to utilize my performance suggestion.  That involved using add instead of sum.

I remember this discussion, but fail to see your point on summation.  If I recall I was solving for the roots of a derivative of a series which in itself is a series as well.  Once the roots are determined then evaluate the original series @the root location.  You showed me the rootfinder tool & how much faster it was than the conventional approach I was using.  It indeed was immensely faster as you state above.  However, evaluating a series as a function of some arbitrary variable I fail to see how the rootfinder tool can do this & then use it to compare with another expression form of the same series?  I suppose you could argue if the roots of one expression matches those of another then the 2 expressions are identical?  I can see the utility of this argument for comparing some intricale polynomial, but I am not sure about a series or all functions in general?

If this is what you were trying to point out I did not get that message.  Maybe you have an example?  Regarding the add command I will have to give that a try.  I do not recall attempting that operation.

 

@acer 

You are correct in that not all of the output gets into the MAPLEPrimes display below.  That is a bit annoying.  Anyway, did the unapply command UNDO what you identify as a PROCEDURE which was executed by equation (3)?  I see now that T1(m) is now effectively Q1 & I presume the same is true for T2(m) = Q2.

So do I execute the PROCEDURE 1st & then UNDO it via unapply OR simply invoke the unapply command exclusively?

Ck1 := sin(Pi*k)/(Pi*k);

a[0]+Sum(-(-1+cos(Pi*k))*sin(2*Pi*k*t/T)/(Pi*k), k = 1 .. m)

(1)

Q1 := 2*sin(alpha)*(diff(S11, t)); -1; Q2 := sum(2*sin(alpha)*(2*Ck2*Pi*k*cos(2*Pi*k*t/T)/T), k = 1 .. m); -1; is(Q1 = Q2), is(expand(Q1 = Q2)), is(combine(Q1 = Q2)), is(eval(Q1 = Q2)), is(value(Q1 = Q2)), simplify(Q1-Q2)

true, true, true, true, true, 0

(2)

T1 := proc (m) options operator, arrow; 2*sin(alpha)*(diff(a[0]+int(sum(2*Ck2*Pi*k*cos(2*Pi*k*x/T)/T, k = 1 .. m), x = 0 .. t), t)) end proc;

proc (m) options operator, arrow; sum(4*sin(alpha)*Ck2*Pi*k*cos(2*Pi*k*t/T)/T, k = 1 .. m) end proc

(3)

For the very first comparison below, it makes no sense whatsoever to compare the procedures, since they are obviously different.

You can simplify/combine/whatever before using `unapply`, to get two procedures with the same "body", which can be compared under `eval`.

Or you can simplify/combine/whatever the results of applying both procedures to some dummy name, and then compare those expressions.

Other possible comparisons follow.

T1 := unapply('2*sin(alpha)*(diff(a[0]+int(sum(2*Ck2*Pi*k*cos(2*Pi*k*x/T)/T, k = 1 .. m), x = 0 .. t), t))', m);

true, true, true, true, true

(4)

is(Q1 = T1(m)), is(expand(Q1 = T1(m))), is(combine(Q1 = T1(m))), is(eval(Q1 = T1(m))), is(value(Q1 = T1(m))), simplify(Q1-T1(m))

true, true, true, true, true, 0

(5)

``

``


 

Download is_command.mw

@acer 

I notice that you continue to ignore the advice -- made for several of your earliest (of many) Questions in this long saga -- that:

1) inert `Sum` may be more suitable than active `sum` to your overall investigations and more particularly your attempts at symbolic verification

NO, I am not ignoring anything.  I include both INERT & ACTIVE sums, for my sake, to indicate that indeed the 2 produce the same results, but the 2 commands do behave differently.  KEEP IN MIND that you know the inner working details of MAPLE.  I do NOT.  Before all of this work I did not know about INERT vs ACTIVE.  I picked up MAPLE as a tool for research purposes & have learned it only through trial & error & interacting within MAPLEPrimes.  I have had no formal classes or training with using MAPLE code.

2) `add` (under evalhf, or Compiled) would get far better performance than `sum` and likely exhibit less roundoff in the case that `sum` or `simplify` or `combine` produced trig terms with large rationals.

This I will check out.

Regarding the issue in question I am working with what you provided to digest what is occurring & likely will have follow questions.

@Preben Alsholm 

What is this T1(7) you speak of?  Nonetheless, I removed d/dt(S11) & still everything remains FALSE.  Can you please modify what I have below to generate a TRUE result?  Your analagous or parallel code examples do not seem to yield anything useful to my situation.  Your explanations are not being interpreted well.

NOTE that m is now included with both T1 & T2 so again FALSE results are generated.


 

Ck1 := sin(Pi*k)/(Pi*k);

a[0]+Sum(-(-1+cos(Pi*k))*sin(2*Pi*k*t/T)/(Pi*k), k = 1 .. m)

(1)

Q1 := 2*sin(alpha)*(diff(S11, t)); -1; Q2 := sum(2*sin(alpha)*(2*Ck2*Pi*k*cos(2*Pi*k*t/T)/T), k = 1 .. m); -1; is(Q1 = Q2), is(expand(Q1 = Q2)), is(combine(Q1 = Q2)), is(eval(Q1 = Q2)), is(value(Q1 = Q2)), simplify(Q1-Q2)

true, true, true, true, true, 0

(2)

T1 := proc (m) options operator, arrow; 2*sin(alpha)*(diff(a[0]+int(sum(2*Ck2*Pi*k*cos(2*Pi*k*x/T)/T, k = 1 .. m), x = 0 .. t), t)) end proc;

false, false, false, false, false, false

(3)

``

``


 

Download is_command.mw

 

@Preben Alsholm 

I am still experiencing problems.


 

Ck1 := sin(Pi*k)/(Pi*k);

a[0]+Sum(-(-1+cos(Pi*k))*sin(2*Pi*k*t/T)/(Pi*k), k = 1 .. m)

(1)

Q1 := 2*sin(alpha)*(diff(S11, t)); -1; Q2 := sum(2*sin(alpha)*(2*Ck2*Pi*k*cos(2*Pi*k*t/T)/T), k = 1 .. m); -1; is(Q1 = Q2), is(expand(Q1 = Q2)), is(combine(Q1 = Q2)), is(eval(Q1 = Q2)), is(value(Q1 = Q2)), simplify(Q1-Q2)

true, true, true, true, true, 0

(2)

T1 := unapply(Q1, m);

proc (m) options operator, arrow; 4*sin(alpha)*(-1+cos(Pi*t/T)^2+sin(Pi*t/T)^2*cos(Pi*t/T)^2)*cos(Pi*(m+1)*t/T)^2/((-1+cos(Pi*t/T)^2)^2*T)+4*sin(alpha)*cos(Pi*(m+1))*cos(Pi*(m+1)*t/T)^2/T-4*sin(Pi*t/T)*cos(Pi*t/T)*sin(alpha)*sin(Pi*(m+1)*t/T)*cos(Pi*(m+1)*t/T)/(T*(-1+cos(Pi*t/T)^2))+4*sin(alpha)*sin(Pi*t/T)*cos(Pi*(m+1))*sin(Pi*(m+1)*t/T)*cos(Pi*(m+1)*t/T)/(T*cos(Pi*t/T))-2*sin(alpha)*cos(Pi*(m+1))/T-4*sin(alpha)*(-1+cos(Pi*t/T)^2+sin(Pi*t/T)^2*cos(Pi*t/T)^2)*cos(Pi*t/T)^2/((-1+cos(Pi*t/T)^2)^2*T)+4*sin(alpha)*cos(Pi*t/T)^2/T+4*sin(Pi*t/T)^2*cos(Pi*t/T)^2*sin(alpha)/(T*(-1+cos(Pi*t/T)^2))+4*sin(alpha)*sin(Pi*t/T)^2/T-2*sin(alpha)/T end proc

(3)

is(eval(T1) = eval(T2));

false

(4)

T1 := proc (m) options operator, arrow; 2*sin(alpha)*(diff(S11, t)) end proc;

false

(5)

````

``


 

Download is_command.mw

@Kitonum 

It seems to work now.  Hopefully, it will not happen again.  I probably had some typo

@acer 

Below are my results for computing a series in 3 different ways:

S11 & S12 vs S13 & S14 vs integrate X & Y.

Now, am I interpreting the results correctly?  The reason I ask is that I am not confident that I am reinitializing my reference times & memory usage appropriately.

1) The 1st method requires much more computation time.

2) The first 2 methods require the same amount of memory while the 3rd method requires slightly more.


 

Ck1 := sin(Pi*k)/(Pi*k);

a[0]+Sum(-(-1+cos(Pi*k))*sin(2*Pi*k*t/T)/(Pi*k), k = 1 .. m)

(1)

Q1 := 2*sin(alpha)*(diff(S11, t)); -1; Q2 := sum(2*sin(alpha)*(2*Ck2*Pi*k*cos(2*Pi*k*t/T)/T), k = 1 .. m); -1; is(Q1 = Q2), is(expand(Q1 = Q2)), is(combine(Q1 = Q2)), is(eval(Q1 = Q2)), is(value(Q1 = Q2)), simplify(Q1-Q2)

true, true, true, true, true, 0

(2)

Q2 = sum((2*Ck2*Pi*k/T*2)*sin(alpha)*cos(2*Pi*k*t/T), k = 1 .. m)"(->)"true

2*sin(alpha)*cos(2*Pi*k*t/T)"(=)"sin(alpha+2*Pi*k*t/T)+sin(alpha-2*Pi*k*t/T)

Q3 := sum(2*Ck2*Pi*k*(sin(alpha+2*Pi*k*t/T)+sin(alpha-2*Pi*k*t/T))/T, k = 1 .. m):

Q1 = Q3"(->)"true"(->)"true"(->)"true"(->)"true"(->)"true

Q4 := 2*sin(beta)*(diff(S13, t)); -1; Q5 := sum(2*sin(beta)*(4*cos(2*Pi*(2*k-1)*t/T)/T), k = 1 .. n); -1; is(Q4 = Q5), is(expand(Q4 = Q5)), is(combine(Q4 = Q5)), is(eval(Q4 = Q5)), is(value(Q4 = Q5)); 1; simplify(expand(Q4-Q5)), simplify(combine(Q4-Q5)), simplify(Q4-Q5)

0, 0, 0

(3)

Q6 := sum(4*(sin(beta+2*Pi*(2*k-1)*t/T)+sin(beta-2*Pi*(2*k-1)*t/T))/T, k = 1 .. n):

Q5 = Q6"(->)"true

m := 2*n; 1; X := `assuming`([simplify(expand(combine(Q1/(2*sin(alpha)))))], [n::integer]); 1; Y := simplify(expand(combine(Q4/(2*sin(beta))))); 1; is(X = Y)

true

(4)

CHI := subs(t = x, X);

true

(5)

Doublecheck for concurrence:NULL

T0 := kernelopts(cputime), time(), time[real]();

79016085, 9107836, 8.685909271

(6)

t := (1/4)*T/n;

108488388, 3996964, 3.811801909

(7)

evalf[10](evalf(S13));

27398036, 0, 0.

(8)

evalf[10](a[0]+evalf(int(CHI, x = alpha .. b)));

38053904, 327620, .31244278

(9)

``

``


 

Download CPU_memory_usage.mw

@acer 

Is there some simple modification to get CPU & memory usage?  See below:



Maple Worksheet - Error

Failed to load the worksheet /maplenet/convert/CPU_&_memopry_usage.mw .
 

Download CPU_&_memopry_usage.mw

 

@acer 

OK, I am showing the error discrepancy for a small rang for values of n from 1 to 100.  I then recompute the values with  a greater number of sig figs for the evalf command & results are well behaved.  My suspicion is that the sin term in the denominator is the culprit sense I am evaluating the integral from T/(4n) to 0.  The value of T/(4/n) is a solution to the roots of (7).

How to establish the level of sig figs a priori I still do not know.  Maybe you have some insight?  It almost seems the form of the function within evalf must be known.  So some arbitrary function of not well understood behavior will wreak havoc?

divergent_behavior.mw

@acer 

OK I will anticipate your advise

@acer 

Is there a good rule of thumb in choosing the precision & how to apply it?  Let's assume I do not realize that the expressions I was analyzing should be equivalent.  I would then conclude by the results that the expressions are NOT equivalent.  However, if I had picked a particular value of n where the expressions agreed I would arrive at an opposite conclusion.  So I need to know how far I need to evaluate the sig figs.  50 sig figs seems a bit absurd in a practical sense, but you have demonstrated otherwise.

I appreciate you pointing this out.  Now I need to wrap my head around the issue.

@acer 

Hi acer.

I posted the question & then took my flash drive home to look at the problem closer & it occurred to me that you pointed out a ROUNDOFF issue in the past.  At that time I failed to grasp that issue because the discrepancy was so LARGE.  My impression has been that ROUNDOFF issues affect significant figures accuracy to some 10^-x order.  When I see errors on the order of 10^+x I think something else must be the culprit.  Now it manifested itself again in a slightly different situation.  The odd thing is that the discrepancy occurs only within a band of n values.  I think on the previous question you pointed out that the ROUNDOFF was large for small values of n & diminished for higher values of n.

In this instance good results for small & large values of n, but not so much for the narrow region for n<7<100.  This almost seems to be some issue of a singularity associated with n.  Anyway, I will attempt to apply your suggestions, but I am sure I will have follow up questions on this.

@vv WOW, that was quite a workaround which is not entirely intuitive, but I believe is correct.  It certainly was not what I was expecting.

I'll attach my worksheet for any future reference to such a situation.  What makes the evaluation work is given in the last line where the subs command is invoked.


 

Ck1 := sin(Pi*k)/(Pi*k);

(1-cos(Pi*k))/(Pi*k)

(1)

sum1 := sum(2*Ck2*Pi*k*cos(2*Pi*x*k/T)/T, k = 1 .. m);

true

(2)

subs(x = t, simplify(expand(combine(2*sin(alpha)*sum1)))) = simplify(expand(combine(Q3)))"(->)"true

m := 2*n;

true

(3)

X

-4*sin(Pi*t/T)*sin(Pi*t*n/T)*cos(Pi*t*n/T)*(2*cos(Pi*t*n/T)^2-1)/(T*cos(Pi*t/T)*(cos(Pi*t/T)^2-1))

(4)

subs(`assuming`([x = t, simplify(expand(combine(sum1)))], [n::integer]))

-4*sin(Pi*t/T)*sin(Pi*t*n/T)*cos(Pi*t*n/T)*(2*cos(Pi*t*n/T)^2-1)/(T*cos(Pi*t/T)*(cos(Pi*t/T)^2-1))

(5)

int(X, x = a .. t)

-4*sin(Pi*t/T)*sin(Pi*t*n/T)*cos(Pi*t*n/T)*(2*cos(Pi*t*n/T)^2-1)*(t-a)/(T*cos(Pi*t/T)*(cos(Pi*t/T)^2-1))

(6)

int(X, x = 0 .. t)

-4*sin(Pi*t/T)*sin(Pi*t*n/T)*cos(Pi*t*n/T)*(2*cos(Pi*t*n/T)^2-1)*t/(T*cos(Pi*t/T)*(cos(Pi*t/T)^2-1))

(7)

int(subs(`assuming`([x = t, simplify(expand(combine(sum1)))], [n::integer])), x = a .. t)

-4*sin(Pi*t/T)*sin(Pi*t*n/T)*cos(Pi*t*n/T)*(2*cos(Pi*t*n/T)^2-1)*(t-a)/(T*cos(Pi*t/T)*(cos(Pi*t/T)^2-1))

(8)

``

``


 

Download evaluating_integral.mw

3 4 5 6 7 8 9 Page 5 of 12