On Fri, Nov 14, 2008 at 9:09 AM, Andy Ray Terrel <[EMAIL PROTECTED]> wrote: > > One thing that would be nice is to give a bit more information on > different algorithms used for examples. It seems that we could really > just have such a large list of examples it is hard to keep up with > them. Really the idea I would have is to make a corresponding wiki > that explained the examples in more detail for someone trying to learn > things. > > For example if I didn't know what the gram-schmidt process did, I > would be utterly confused as why your trick worked and what it was > doing.
Right. I created an issue for that: http://code.google.com/p/sympy/issues/detail?id=1196 > > Because you just give the basis later function l2_norm, > l2_inner_product, l2_projection, and l2_gram_schmidt are never used > and should be, IMHO, removed. Well, it's an example, so I wanted to leave it there so that people know how it works. But it's true that it is never used. > > On Thu, Nov 13, 2008 at 8:07 PM, Ondrej Certik <[EMAIL PROTECTED]> wrote: >> >> --- >> examples/all | 1 + >> examples/gibbs_phenomenon.py | 131 >> ++++++++++++++++++++++++++++++++++++++++++ >> 2 files changed, 132 insertions(+), 0 deletions(-) >> create mode 100755 examples/gibbs_phenomenon.py >> >> diff --git a/examples/all b/examples/all >> index f2ad056..43ac2dc 100755 >> --- a/examples/all >> +++ b/examples/all >> @@ -23,6 +23,7 @@ >> ./differential_equations.py >> #./pidigits.py >> ./differentiation.py >> +./gibbs_phenomenon.py >> #./plotting_nice_plot.py >> ./series.py >> ./expansion.py >> diff --git a/examples/gibbs_phenomenon.py b/examples/gibbs_phenomenon.py >> new file mode 100755 >> index 0000000..64f8c02 >> --- /dev/null >> +++ b/examples/gibbs_phenomenon.py >> @@ -0,0 +1,131 @@ >> +#!/usr/bin/env python >> + >> +""" >> +This example illustrates the Gibbs phenomenon. >> + >> +It also calculates the Wilbraham-Gibbs constant by two approaches: >> + >> +1) calculating the fourier series of the step function and determining the >> +first maximum. >> +2) evaluating the integral for si(pi). >> +""" >> + >> +import iam_sympy_example >> + >> +from sympy import var, sqrt, integrate, conjugate, seterr, abs, pprint, I, >> pi,\ >> + sin, cos, sign, Plot, msolve, lambdify, Integral, S >> + >> +#seterr(True) >> + >> +x = var("x", real=True) >> + >> +def l2_norm(f, lim): >> + """ >> + Calculates L2 norm of the function "f", over the domain lim=(x, a, b). >> + >> + x ...... the independent variable in f over which to integrate >> + a, b ... the limits of the interval >> + >> + Example: >> + >> + >>> l2_norm(1, (x, -1, 1)) >> + 2**(1/2) >> + >>> l2_norm(x, (x, -1, 1)) >> + 1/3*6**(1/2) >> + """ >> + return sqrt(integrate(abs(f)**2, lim)) > > Why are you taking the absolute value here? Because if "f" is complex, you either need to do: f * f.conjugate() or abs(f)**2. > >> + >> +def l2_inner_product(a, b, lim): >> + """ >> + Calculates the L2 inner product (a, b) over the domain lim. >> + """ >> + return integrate(conjugate(a)*b, lim) >> + >> +def l2_projection(f, basis, lim): >> + """ >> + L2 projects the function f on the basis over the domain lim. >> + """ >> + r = 0 >> + for b in basis: >> + r += l2_inner_product(f, b, lim) * b >> + return r >> + >> +def l2_gram_schmidt(list, lim): >> + """ >> + Orthonormalizes the "list" of functions using the Gram-Schmidt process. >> + >> + Example: >> + >>> l2_gram_schmidt([1, x, x**2], (x, -1, 1)] >> + [1/2*2**(1/2), x*6**(1/2)/2, -3*10**(1/2)*(1/3 - x**2)/4] >> + """ >> + r = [] >> + for a in list: >> + if r == []: >> + v = a >> + else: >> + v = a - l2_projection(a, r, lim) >> + v_norm = l2_norm(v, lim) >> + if v_norm == 0: >> + raise Exception("The sequence is not linearly independent.") >> + r.append(v/v_norm) >> + return r >> + > > I wouldn't name a variable "l", it looks like 1 in many editors. Well, shouldn't rather one be using fonts that distinguish l, 1, i, etc.? I think it is absolutely essential to being able to distinguish between those. Ondrej --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-patches" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy-patches?hl=en -~----------~----~----~----~------~----~------~--~---
