# [Maxima] z-transforms...

Ryan Krauss ryanlists at gmail.com
Fri Feb 16 17:44:07 CST 2007

```I found a simple difference equation example on the web:
http://people.revoledu.com/kardi/tutorial/DifferenceEquation/SolutionDifferenceEquation.htm
and was able to get the same answer using the z transform by hand.

My first attempt at a shifting property failed miserably:
defrule(r14,zt(f(n-m),n,z),z^(-m)*ztrans(f(n),n,z));

Ryan

On 2/13/07, Alasdair McAndrew <amca01 at gmail.com> wrote:
> Hi there Ryan - good to see you back.  I'm attaching the current version of
> my z-transforms package (with your correction - thanks!)  based mostly on
> the work of Robert Dodier, who knows more about Maxima than I'll ever learn.
>  As you can see, it would be easy to add new rules; also I've started on the
> inverse transform.
>
> I'm having a little trouble implementing one of the rules for the binomial
> function; ztrans(binomial(n,b),n,z) should return z/(z-1)^(b+1).  I'm trying
> to work out how I can implement such a rule which doesn't conflict with my
> rule r12.  That is, the binomial function should be recognized as such, and
> not as n*f.
>
> We need to implement rules for shifting, and see if we can use the package
> we have to solve a simple linear difference equation.
>
> I don't know about you, but I'm learning heaps, and enjoying myself.
>
> Oh, and speaking as an academic, if you can see any way of wrangling a paper
> out of all this, that would be a real bonus!
>
> cheers,
> Alasdair
>
>
> On 2/14/07, Ryan Krauss <ryanlists at gmail.com> wrote:
> > Hey Alasdair,
> >
> > I learned a lot from your example of rule based programming.  Thanks
> > for all your work.  I made one small correction and one small
> > contribution to what I copied and pasted from your email and saved it
> > to ztrans1.mac.  The correction is that I think the ztrans of a step
> > function should be z/(z-1)  or 1/(1-z^(-1)) .  You had 1/(1-z).  The
> > small contribution is a rule for exp(-a*n).  I added this because it
> > came up in my first test of my c2d function.  My main motivation for
> > this work is to find the z-transforms of systems whose continuous time
> > transfer functions I know when they are sample using analog-to-digital
> > converters (i.e. an ideal sample and hold circuit).  My c2d function
> > uses your ztrans as part of an algorithm to do all this.  It is fairly
> > straight forward once you have a ztrans function (since Maxima already
> > has an ilt function for inverse laplace).  My first test was on a
> > first order transfer function Gp=a/(s+a).  The inverse laplace of this
> > involves exp(-a*t), which lead to my need of a new rule.
> >
> > I think what we already have meets my basic, immediate need.  It would
> > be nice to clean up the output a bit, mainly getting it to output the
> > final discrete transfer function as two vectors of coefficients of z
> > (one for the numerator and one for the denominator).  I will post to
> > the list about that in a minute.  I also need to come up with a nice
> > way to get the output into Python.
> >
> > I am definitely interested in continued development and will need more
> > rules as I try to apply it to more systems.
> >
> > Any thoughts on what you would like to do next with it?
> >
> > Ryan
> >
> > On 2/13/07, Ryan Krauss <ryanlists at gmail.com> wrote:
> > > Hey Alasdair,
> > >
> > > FYI, I am back and trying to learn Maxima programming today.  I will
> > > read through some basics and look over what you have so far.  Let me
> > > know if there is anything you want me to test or look at or anything
> > > you recommend in getting started.
> > >
> > > Thanks,
> > >
> > > Ryan
> > >
> > > On 2/11/07, Alasdair McAndrew <amca01 at gmail.com> wrote:
> > > > Hi Robert,
> > > >
> > > > As usual I am amazed at your deep and complete knowledge of Maxima and
> its
> > > > workings.  Your suggestion works very well.  But I have one problem,
> > > > exemplified by the following (where I have set display2d to false):
> > > >
> > > > (%i218) ztrans(3^n*sin(4*n),n,z);
> > > >
> > > > (%o218) 'subst(z/3,z,sin(4)*z/(z^2-2*cos(4)*z+1))
> > > >
> > > > (%i219) ev(%,nouns);
> > > >
> > > > (%o219)
> -.2522674984359761*z/(z^2/9+.4357624139090746*z+1)
> > > >
> > > > As you see, "ev" has the effect of also evaluating sin(4) and cos(4),
> which
> > > > I don't want; the output should read
> > > >
> > > > (%o219)  sin(4)*z/(3*(z^2/9-2*cos(4)*z/3+1))
> > > >
> > > > Is there a way of preventing "ev" of evaluating functions, or is there
> an
> > > > alternative command?  I've hunted through the manual, but so far drawn
> a
> > > > blank.
> > > >
> > > > cheers,
> > > > Alasdair
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > On 2/12/07, Robert Dodier <robert.dodier at gmail.com > wrote:
> > > > > Hi Alasdair,
> > > > >
> > > > > >
> defrule(r8,zt(a^n*f,n,z),subst(z/a,z,ztrans(f,n,z)));
> > > > >
> > > > > I think what you want is 'subst(...) as the rule output, i.e.
> prevent the
> > > > > substitution from taking place, so that there can be further
> > > > > manipulation of ztrans(f,n,z), and the user can eventually evaluate
> > > > > ev(foo, nouns) to cause the substitution to be carried out.
> > > > >
> > > > > I added this stuff to the z-transform script that I have ...
> > > > >
> > > > > matchdeclare (bb, all);
> > > > > defrule (r11,
> > > > >     mrofsnart_z (zz, nn, aa^nn*bb),
> > > > >     'subst (zz/aa, zz, z_transform (bb, nn, zz)));
> > > > >
> > > > > which gives this output:
> > > > >
> > > > >     e5 : z_transform (sin (m*omega) * c^m, m, u);
> > > > >     apply_z_transform (e5);
> > > > >         =>
> 'subst(u/c,u,z_transform(sin(m*omega),m,u))
> > > > >     apply_z_transform (%);
> > > > >         =>
> > > >
> 'subst(u/c,u,sin(omega)/((-2*cos(omega)/u+1/u^2+1)*u))
> > > > >     ''%, nouns;
> > > > >         =>
> c*sin(omega)/((-2*c*cos(omega)/u+c^2/u^2+1)*u)
> > > > >
> > > > > Does that seem right?
> > > > >
> > > > > (The rules I made work on expressions which have the z-transform
> > > > > arguments in reverse order. I did that to help the pattern matcher
> > > > > find zz and nn. I ran into problems with one rule or another and
> that
> > > > > seemed to help. Not sure at this point if it's necessary.)
> > > > >
> > > > > Hope this helps -- let me know how it goes.
> > > > >
> > > > > Robert
> > > > >
> > > >
> > > >
> > >
> >
> >
>
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ztrans3.mac
Type: image/x-macpaint
Size: 1279 bytes
Desc: not available
Url : http://www.math.utexas.edu/pipermail/maxima/attachments/20070216/d180b070/attachment.bin
```