Boost logo

Ublas :

Subject: Re: [ublas] different size for matrix addition
From: Andrea Cassioli (cassioliandre_at_[hidden])
Date: 2010-06-16 04:12:34


Hi,
I'd like just to point out that, strictly speaking, matrix addition is
defined only for matrices with the same dimensions. What Kraus maybe
need is to use from the very beginning with a big empty matrix and
then use subranges to add contributions inside:

#include "boost/numeric/ublas/matrix.hpp"
#include "boost/numeric/ublas/matrix_proxy.hpp"

#include "boost/numeric/ublas/io.hpp"
#include <iostream>

int main(){
    using namespace boost::numeric::ublas;

    matrix<double> x(2,2,1.0);
    matrix<double> z(3,3,0.0);

    subrange(z,0,2,0,2)+=x;
    std::cout<<z<<std::endl;

    return 0;
}

I hope it helps....

Cheers, Andrea Cassioli

On Wed, Jun 16, 2010 at 9:43 AM, Kraus Philipp
<philipp.kraus_at_[hidden]> wrote:
> Hi David, thanks for the fast answer.
> Am 16.06.2010 um 09:34 schrieb David Bellot:
>
> better to give the same size to x and y, filling x with extra zeros.
>
> I can't do this, because I need a "grow up" for my matrix. I have a
> symmetric matrix with NxN
> elements and in a next step the matrix must grow up to (N+1)x(N+1)
>
> here z takes the size of y but is filled with wrong indices due to x having
> a smaller size.
>
> By the way, I have never been so confortable with the idea of assuming zeros
> when adding 2 matrices of different sizes :-)
>
> That's only a test and my elements of x and y aren't be zero in reality
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
> Sent to: cassioliandre_at_[hidden]
>

-- 
Andrea Cassioli