[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Easy about Matrices
From: |
avraham |
Subject: |
Re: Easy about Matrices |
Date: |
Tue, 19 Apr 2005 14:47:30 +0300 |
User-agent: |
Mutt/1.5.5.1+cvs20040105i |
On Mon, Apr 18, 2005 at 02:18:46PM -0700, Henry F. Mollet wrote:
> I don't understand fully. As outlined x will end up to be a zero matrix,
> whereas I thought one should end up with 2 matrices, pos values replaced
> with zeros in one, negative values replaced with zeros in the other?
> Henry
> octave:18> x = randn(2,4)
> x =
>
> -0.273788 -0.671445 -1.522762 0.170152
> -2.135687 1.040917 0.017514 -0.413427
>
> octave:19> x_positive = x(x<0)=0
> x_positive = 0
> octave:20> x
> x =
>
> 0.00000 0.00000 0.00000 0.17015
> 0.00000 1.04092 0.01751 0.00000
>
> octave:21> x_negative = x(x>=0)=0
> x_negative = 0
> octave:22> x
> x =
>
> 0 0 0 0
> 0 0 0 0
>
> % Trying the following:
> octave:27> x=xpos=xneg=randn(2,4)
> x =
>
> -0.77668 -0.21781 0.45580 -0.34135
> -0.57917 0.78780 1.97339 -0.79024
>
> octave:28> x_positive = xpos(xpos<0)=0
> x_positive = 0
> octave:29> xpos
> xpos =
>
> 0.00000 0.00000 0.45580 0.00000
> 0.00000 0.78780 1.97339 0.00000
>
> octave:30> x_negative = xneg(xneg>=0)=0
> x_negative = 0
> octave:31> xneg
> xneg =
>
> -0.77668 -0.21781 0.00000 -0.34135
> -0.57917 0.00000 0.00000 -0.79024
>
> octave:32> whos
>
> *** local user variables:
>
> prot type rows cols name
> ==== ==== ==== ==== ====
> rwd matrix 2 4 x
> rwd scalar 1 1 x_negative
> rwd scalar 1 1 x_positive
> rwd matrix 2 4 xneg
> rwd matrix 2 4 xpos
>
>
> on 4/18/05 11:06 AM, avraham at address@hidden wrote:
...
> > An alternative could be (example):
> > 684~> x = randn(12,100);
> > x_positive = x(x<0)=0;
> > x_negative = x(x>=0)=0;
> > The two arrays have the size of the original one, but the terms
> > of "wrong sign" are replaced by zeros.
> > Check:
> > y=x_positive+x_negative;
> > 694~> min(min(y-x))
> > ans = 0
> > 694~> max(max(y-x))
> > ans = 0
> >
> > In order to avoid plotting the points at y=0, one can use NaN
> > instead of 0: x_positive = x(x<0)=NaN; etc
> >
> > Cheers, Avraham
> >
> >
> >
> > -------------------------------------------------------------
> > Octave is freely available under the terms of the GNU GPL.
> >
> > Octave's home on the web: http://www.octave.org
> > How to fund new projects: http://www.octave.org/funding.html
> > Subscription information: http://www.octave.org/archive.html
> > -------------------------------------------------------------
> >
Thanks for the correction. The funny part is that, as I felt very
tired, I opened an octave terminal to check myself, before I
write. And then I copy-pasted from it.
I guess that I wrote the wrong answer and then checked
my answer in a way that did not reveal the mistake, but lulled me
in the belief, that despite tiredness, I wrote the right thing.
Next time I shall know better (which probably means that I'll
make a different mistake!).
Cheers, Avraham
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- Easy about Matrices, Alvaro Aguilera, 2005/04/18
- Re: Easy about Matrices, Quentin Spencer, 2005/04/18
- RE: Easy about Matrices, Frank Palazzolo, 2005/04/18
- Re: Easy about Matrices, avraham, 2005/04/18
- Re: Easy about Matrices, Mike Miller, 2005/04/18
- Re: Easy about Matrices, Geordie McBain, 2005/04/18
- Re: Easy about Matrices, Mike Miller, 2005/04/18
- Re: Easy about Matrices, Alvaro Aguilera, 2005/04/19
- Re: Easy about Matrices, Peter Bodin, 2005/04/19
- Re: Easy about Matrices, Alvaro Aguilera, 2005/04/19
- Re: Easy about Matrices, Peter Bodin, 2005/04/19
- Re: Easy about Matrices, Mike Miller, 2005/04/19