[Maxima] Fourier series of a 2step function?

Richard Hennessy rvh2007 at comcast.net
Sat Sep 20 22:38:04 CDT 2008


It "was" a quagmire.  I done my best to sort it out.  Bye.


----- Original Message ----- 
From: "Richard Hennessy" <rvh2007 at comcast.net>
To: "Edwin Woollett" <woollett at charter.net>
Cc: "maxima mailing list" <maxima at math.utexas.edu>
Sent: Saturday, September 20, 2008 11:33 PM
Subject: Re: [Maxima] Fourier series of a 2step function?


By the way the whole matrix idea stinks as a way to line things up, you should not have words in a matrix.  I saw
something about format in the help which may have the ability to line things up nicely but I can't remember how I found
it.

This is a quagmire.

Rich



----- Original Message ----- 
From: "Richard Hennessy" <rvh2007 at comcast.net>
To: "Richard Hennessy" <rvh2007 at comcast.net>; "Edwin Woollett" <woollett at charter.net>
Cc: "maxima mailing list" <maxima at math.utexas.edu>
Sent: Saturday, September 20, 2008 11:00 PM
Subject: Re: [Maxima] Fourier series of a 2step function?


"I get row after row of Col 1 = [ if ]
                                             [ if ]
                                             [ if ]"

Make sure you use "If" not "if", capitalising "if" prevents Maxima from thinking it's an if and that might be it.  I did
get "if" inside quotes being threated as a if conditional when I was testing.

Rich

----- Original Message ----- 
From: "Richard Hennessy" <rvh2007 at comcast.net>
To: "Edwin Woollett" <woollett at charter.net>
Cc: "maxima mailing list" <maxima at math.utexas.edu>
Sent: Saturday, September 20, 2008 9:57 PM
Subject: Re: [Maxima] Fourier series of a 2step function?


"Can you work with this definition of a piecewise cont.
function and get the correct integrals and derivatives?"

No, not yet but I will look into it.

Rich


----- Original Message ----- 
From: "Edwin Woollett" <woollett at charter.net>
To: "Richard Hennessy" <rvh2007 at comcast.net>
Cc: "maxima mailing list" <maxima at math.utexas.edu>
Sent: Saturday, September 20, 2008 6:28 PM
Subject: Re: [Maxima] Fourier series of a 2step function?


On Sept 20, 2008, 2:04 AM(!!), Richard Hennessy wrote:


> It could be better, but it's late.
>
> Rich
> I was working on declaring functions peicewise and I came up with this
> (probably not very good solution).  I have
> defined some functions that allow you to declare a function in sections
> (pw) like you want and integrate (pwdefint and
> pwintegrate) and differentiate (pwdiff).
>
> (%i1) set_display('ascii)$
> (%i2) pwintegrate(expr,x):=
> block
>    ([__i, __k,__l],
>        if matrixp(expr) then
>            (
>                __l:[],
>                if length(expr[1]) = 11 then
>                (
>                    for __i: 1 thru length(expr) do
> __l:endcons([expr[__i,5],expr[__i,7], integrate(expr[__i,11],
> x)],__l),
>                    pw(__l,x)
>                )
>            )
>        else
>            integrate(expr,x)
>    )$

> (%i6) f:[-inf, 0, -15, x, -10, sin(x^2)*x*20+cos(3*x)*10, -5, x^2+x+6, -2,
> 10*x, 0, x, 10, 0, inf]$
>
>
> (%i9) pwdefint(pw(f,x),x,-inf,inf), numer,ratprint=false;
> (%o9)
> 7.250095748755271
>

This is an interesting use of Maxima's matrix tools to deal with
piecewise continuous functions.

I think you get better numerial accuracy if you omit "numer",
(and I don't think "ratprint:false" matters), and let Maxima
do it as it wants and then use float( result ), as in

----------------------------------
(%i9) ans1 : pwdefint(pw(f,x),x,-inf,inf), numer,ratprint=false;
(%o9)                          7.250095748755271
(%i10) ans2 : (pwdefint(pw(f,x),x,-inf,inf) ,float(%%) );
(%o10)                         7.25009572340884
(%i11) (ans1-ans2)/ans2 ;
(%o11)                       3.4960133751591161E-9
---------------------
Also, when I use your  pwdiff(...) function as in
---------------------
(%i12) pwdiff(pw(f,x),x,1);
------------------
I get row after row of Col 1 = [ if ]
                                             [ if ]
                                             [ if ]
                                              etc.
and like wise for all the columns, the only output
of use is Col 11.
------------------
Another way to define piecewise continuous functions
would be using unit_step(x), as in

(%i16) u( x ) := unit_step(x)$
(%i17) uu( x1, x2 ) := u( x - x1 ) - u( x - x2 )$
(%i18) (load(draw),load(qdraw))$
               qdraw(...), qdensity(...), syntax: type qdraw();

/* here we plot uu( 1, 2 ) using qdraw  */

(%i19) qdraw( yr( -1, 2 ), xr( -1, 3 ), ex( uu( 1, 2 ), x, 0, 3 )  )$

/*  which gives a nice unit square wave  */

/* let's define a two element pw function as  */

(%i20) g(x) := x*uu( 0, 1)  +  x^2*uu( 1, 2)$

/*  and plot it  */

(%i21) qdraw( yr( -1, 5), xr( -1, 3), ex( g(x), x, 0, 3)  )$

/* which shows func "x" from (0, 1) and "x^2
   from (1, 2)  */

Can you work with this definition of a piecewise cont.
function and get the correct integrals and derivatives?

It would be nice if fourie.mac were augmented with
the ability to handle this type of input function.

Ted Woollett

_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima

_______________________________________________
Maxima mailing list
Maxima at math.utexas.edu
http://www.math.utexas.edu/mailman/listinfo/maxima 



More information about the Maxima mailing list