Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial sums are off for Fourier series of piecewise functions #8603

Closed
novoselt opened this issue Mar 25, 2010 · 27 comments
Closed

Partial sums are off for Fourier series of piecewise functions #8603

novoselt opened this issue Mar 25, 2010 · 27 comments

Comments

@novoselt
Copy link
Member

Doing

f = Piecewise([[(-pi, pi), x]])
print f.fourier_series_partial_sum(2, pi)
print f.fourier_series_partial_sum(3, pi)

we get

2*sin(x)
-sin(2*x) + 2*sin(x)

while according to the documentation we should get the second output with the first command.

Update: Same output with the new piecewise from #14801. Does it agree with the documentation there?

UPDATE: this is fixed in Sage 8.1 (see #23672):

sage: f = piecewise([[(-pi, pi), x]])
sage: f.fourier_series_partial_sum(2, pi)
-sin(2*x) + 2*sin(x)

Depends on #14801

CC: @wdjoyner @jasongrout @jondo @kcrisman @vbraun @slel @mkoeppe @eviatarbach @rwst @novoselt

Component: calculus

Keywords: sd31

Work Issues: other instances of the typo

Author: David Joyner

Issue created by migration from https://trac.sagemath.org/ticket/8603

@kcrisman
Copy link
Member

comment:1

This is still true, and syntax is also deprecated.


sage: f = Piecewise([[(-pi, pi), x]])
sage: print f.fourier_series_partial_sum(2, pi)
/Applications/MathApps/sage/local/lib/python2.6/site-packages/sage/functions/piecewise.py:1095: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
  a0 = self.fourier_series_cosine_coefficient(0,L)
/Applications/MathApps/sage/local/lib/python2.6/site-packages/sage/functions/piecewise.py:1099: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
  for n in srange(1,N)])
2*sin(x)
sage: print f.fourier_series_partial_sum(3, pi)
-sin(2*x) + 2*sin(x)

@novoselt
Copy link
Member Author

Changed keywords from none to sd31

@novoselt
Copy link
Member Author

comment:2

On a related note: what is the purpose of plot methods for Fourier partial sums? They don't do anything except for passing arguments to the usual global plot function, so they seem redundant to me and perhaps can be removed (after deprecation period).

@kcrisman
Copy link
Member

comment:3

You may be right. I'd have to look at it. Remember, these are all really old, so they probably at the time bypassed the non-existent 'plot' function, and then were subsequently changed, perhaps.

@wdjoyner
Copy link

one line change in docstring

@wdjoyner
Copy link

comment:4

Attachment: trac_8603-fourier-sum-docstring.patch.gz

This fixes the documentation of fourier_series_partial_sum, replacing

 f(x) \sim \frac{a_0}{2} + \sum_{n=1}^N [a_n\cos(\frac{n\pi x}{L}) +
b_n\sin(\frac{n\pi x}{L})],

by

 f(x) \sim \frac{a_0}{2} + \sum_{n=1}^{N-1} [a_n\cos(\frac{n\pi x}{L})
+ b_n\sin(\frac{n\pi x}{L})],

@kcrisman
Copy link
Member

comment:5

Thanks, David; I don't have time to review this now, but appreciate it.

Andrey and I were discussing this at Sage Days 31, and thought that maybe changing the behavior instead to match Taylor series would be good, but if this was in fact what you had intended all along, then this solution is better.

@kcrisman
Copy link
Member

Author: David Joyner

@burcin
Copy link

burcin commented Jun 19, 2011

comment:6

Replying to @kcrisman:

Thanks, David; I don't have time to review this now, but appreciate it.

Andrey and I were discussing this at Sage Days 31, and thought that maybe changing the behavior instead to match Taylor series would be good, but if this was in fact what you had intended all along, then this solution is better.

The .series() method of symbolic expressions cut off in a pythonic way, like David's change here. If .taylor() does something different we should change it.

This is a trivial change. I'd be happy to give a positive review if it passes all tests but the patch bot doesn't seem to be working for some reason.

@novoselt
Copy link
Member Author

comment:7

There are more instances of the same typo in other functions of this module, let's fix them all at once!-)

David, do you agree that plot methods can be eliminated as they are not really doing anything?

@novoselt
Copy link
Member Author

Work Issues: other instances of the typo

@kcrisman
Copy link
Member

comment:8

Replying to @novoselt:

There are more instances of the same typo in other functions of this module, let's fix them all at once!-)

Can you be more specific?

David, do you agree that plot methods can be eliminated as they are not really doing anything?

I think I looked at this at Sage Days 31, but now I forgot whether that statement is true.

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.1, sage-6.2 Jan 30, 2014
@ppurka
Copy link
Member

ppurka commented Feb 23, 2014

Dependencies: #14801

@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin modified the milestones: sage-6.2, sage-6.3 May 6, 2014
@sagetrac-vbraun-spam sagetrac-vbraun-spam mannequin removed this from the sage-6.3 milestone Aug 10, 2014
@mkoeppe
Copy link
Contributor

mkoeppe commented Jun 27, 2016

comment:14

Updated with information regarding the new piecewise implementation from #14801.

@mkoeppe mkoeppe modified the milestones: sage-6.4, sage-7.3 Jun 27, 2016
@egourgoulhon
Copy link
Member

comment:15

This is fixed by #23672.

Regarding the example in the ticket description, in Sage 8.1.beta4, we have now

sage: f = piecewise([[(-pi, pi), x]])
sage: f.fourier_series_partial_sum(2, pi)
-sin(2*x) + 2*sin(x)

We even have, since the half-period is now a default argument,

sage: f.fourier_series_partial_sum(2)
-sin(2*x) + 2*sin(x)

@egourgoulhon egourgoulhon removed this from the sage-7.3 milestone Sep 7, 2017
@kcrisman
Copy link
Member

kcrisman commented Sep 7, 2017

comment:16

Excellent. Is this documented via a test?

@egourgoulhon
Copy link
Member

comment:18

Replying to @kcrisman:

Excellent. Is this documented via a test?

Yes this is documented, both in Sage Reference Manual and in Sage Constructions, see here.

@kcrisman
Copy link
Member

kcrisman commented Sep 7, 2017

comment:19

Sweet. Strange that it didn't cause any doctest errors then? If it didn't, we should make sure to include at least two of the examples on the ticket in the doc somewhere.

@egourgoulhon
Copy link
Member

comment:20

Replying to @kcrisman:

Sweet. Strange that it didn't cause any doctest errors then? If it didn't, we should make sure to include at least two of the examples on the ticket in the doc somewhere.

I am not sure to understand what you mean. In the current version, as integrated in Sage 8.1.beta4, there are doctests like

sage: f = piecewise([((-1,0), -1), ((0,1), 1)])
sage: f.fourier_series_partial_sum(5)
4/5*sin(5*pi*x)/pi + 4/3*sin(3*pi*x)/pi + 4*sin(pi*x)/pi

In Sage <= 8.0, this would have returned (*)

4/3*sin(3*pi*x)/pi + 4*sin(pi*x)/pi

(*) with the half-period added as the second argument, i.e. f.fourier_series_partial_sum(5, 1))

@kcrisman
Copy link
Member

kcrisman commented Sep 7, 2017

comment:21

My concern was just that the correct nature was doctested, not the wrong one, and that we really did have that to test against regression at some point. Good!

@zimmermann6
Copy link

comment:23

I wonder why "wontfix" since the issue is fixed in 8.1.beta4.
Paul

@egourgoulhon
Copy link
Member

comment:24

Replying to @zimmermann6:

I wonder why "wontfix" since the issue is fixed in 8.1.beta4.
Paul

Actually, as said in comment:15, the issue is fixed in another ticket: #23672, hence the "sage-duplicate/invalid/wontfix" milestone for the current one and the "wonfix" resolution.

@egourgoulhon

This comment has been minimized.

@kcrisman
Copy link
Member

comment:26

Hey, do non-release managers get to mark "closed"? That would be a change in protocol.

Also, maybe the resolution should be "fixed" or "duplicate" if it is indeed fixed in another ticket?

@egourgoulhon
Copy link
Member

comment:27

Replying to @kcrisman:

Hey, do non-release managers get to mark "closed"? That would be a change in protocol.

This was announced in https://groups.google.com/d/msg/sage-release/4bIUu1NECwY/we3BMdkeAAAJ with apparently the approval of the release manager.

Also, maybe the resolution should be "fixed" or "duplicate" if it is indeed fixed in another ticket?

Ah yes, you are right (I thought this was automatically set to "wontfix" while closing "sage-duplicate/invalid/wontfix" tickets).

@kcrisman
Copy link
Member

comment:28

Replying to @egourgoulhon:

Replying to @kcrisman:

Hey, do non-release managers get to mark "closed"? That would be a change in protocol.

This was announced in https://groups.google.com/d/msg/sage-release/4bIUu1NECwY/we3BMdkeAAAJ with apparently the approval of the release manager.

10 hours ago :-) but this will be welcome for obvious dupes etc.

Also, maybe the resolution should be "fixed" or "duplicate" if it is indeed fixed in another ticket?

Ah yes, you are right (I thought this was automatically set to "wontfix" while closing "sage-duplicate/invalid/wontfix" tickets).

Yeah, that might be the default, but typically we try to be precise on this. Nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants