help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple routine won't run.


From: Utkarsh Upadhyay
Subject: Re: Simple routine won't run.
Date: Mon, 30 Jul 2007 17:08:42 +0530

Hi,

>Note that in Octave you want to avoid explicit loops, and the above formula
>for e.g. x21 can be written as
>
 > [i,j]=meshgrid(0:1,0:1);
 > x21=sum(sum((d.^i.*(1-d).*(1-i).*(d/2).^j*(1-d/2).^(1-j)).*log(d.^i.*(1-d).*(1-i).*(d/2).^j.*(1-d/2).^(1-j))))

I was suggested this link on this mailing list sometime back, and I would like to pass it on.

http://www.mathworks.com/support/tech-notes/1100/1109.html

Its worth it.

HTH,
~musically_ut

On 7/26/07, Przemek Klosowski <address@hidden> wrote:

   Have written a (very first) octave routine:
   ...
   d^i*(1-d)^(1-i)*(d/2)^(k+j)*(1-d/2)^(2-k-j))*log(d^i*(1-d)^(1-i)*(d/2)^(k+j)*(1-d/2)^(2-k-j))
   ....
   d^i*(1-d)(1-i)*(d/2)^j*(1-d/2)^(1-j))log(d^i*(1-d)(1-i)*(d/2)^j*(1-d/2)^(1-j))
   ....
   (d/2)^(k+j)*(1-d/2)^(2-k-j)log((d/2)^(k+j)*(1-d/2)^(2-k-j))

There are issues with your expressions; for instance, the second one misses
some operators. I think you meant

   d^i*(1-d)*(1-i)*(d/2)^j*(1-d/2)^(1-j))*log(d^i*(1-d)*(1-i)*(d/2)^j*(1-d/2)^(1-j))

I would recommend practicing with some simpler expressions and functions before
tackling your fairly complicated problem.

Here's a neat trick: it turns out that properly formed Octave's expressions are, most
of the time, also valid Maxima expressions, and Maxima can format them nicely::

    (%i6) (d^i*(1-d)*(1-i)*(d/2)^j*(1-d/2)^(1-j))*log(d^i*(1-d)*(1-i)*(d/2)^j*(1-d/2)^(1-j));
    (%o6)
                                                            d 1 - j  j + i
                                               (1 - d) (1 - -)      d      (1 - i)
                    d 1 - j  j + i                          2
       (1 - d) (1 - -)      d      (1 - i) log(-----------------------------------)
                    2                                           j
                                                               2
       ----------------------------------------------------------------------------
                                             j
                                            2

    (%i7) tex(%o6);
    $${{\left(1-d\right)\,\left(1-{{d}\over{2}}\right)^{1-j}\,d^{j+i}\,
     \left(1-i\right)\,\log \left({{\left(1-d\right)\,\left(1-{{d}\over{2
     }}\right)^{1-j}\,d^{j+i}\,\left(1-i\right)}\over{2^{j}}}\right)
     }\over{2^{j}}}\leqno{\tt (\%o6)}$$


so you can see if the expressions you are writing are indeed what you think
they are, and you can even cut and paste the TeX output and get a nice printout.

Maxima is conveniently packaged for major Linux distributions, so to
install it I just did 'yum install maxima-gui'; I would expect that
it's available as a Debian package as well---can y'all confirm that?


Note that in Octave you want to avoid explicit loops, and the above formula
for e.g. x21 can be written as

  [i,j]=meshgrid(0:1,0:1);
  x21=sum(sum((d.^i.*(1-d).*(1-i).*(d/2).^j*(1-d/2).^(1-j)).*log(d.^i.*(1-d).*(1-i).*(d/2).^j.*(1-d/2).^(1-j))))

For short loops like yours, it doesn't really matter that much, but this style
is even easier to debug because you can print out the result of the _expression_
that is the argument to sum(sum()), and you'll see all the operands.

_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave



--
Never trust a spiritual leader who cannot dance. ~Mr. Miyagi, The Next Karate Kid
reply via email to

[Prev in Thread] Current Thread [Next in Thread]