help-gsl
[Top][All Lists]
Advanced

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

Re: [Help-gsl] return value of matrix operations


From: Marco Maggi
Subject: Re: [Help-gsl] return value of matrix operations
Date: Fri, 26 Feb 2010 08:53:10 +0100

"kamaraju kusumanchi" wrote:
> This  function  adds  the  elements  of matrix  b  to  the
> elements of matrix  a, a'(i,j) = a(i,j) +  b(i,j). The two
> matrices must have the same dimensions.
>
> Where is the result a' stored?

It is stored in a, as the following program shows:

/* gcc -o proof proof.c $(gsl-config --cflags --libs) */

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_matrix.h>

int
main (void)
{
  gsl_matrix    *a, *b;

  a = gsl_matrix_alloc(1, 1); assert(a);
  b = gsl_matrix_alloc(1, 1); assert(b);
  {
    gsl_matrix_set(a, 0, 0, 10);
    gsl_matrix_set(b, 0, 0,  2);
    printf("matrix A before:\n");
    gsl_matrix_fprintf(stdout, a, "%f");
    printf("\nmatrix B before:\n");
    gsl_matrix_fprintf(stdout, b, "%f");
    gsl_matrix_add(a, b);
    printf("\nmatrix A after:\n");
    gsl_matrix_fprintf(stdout, a, "%f");
    printf("\nmatrix B after:\n");
    gsl_matrix_fprintf(stdout, b, "%f");
  }
  gsl_matrix_free(a);
  gsl_matrix_free(b);
  exit(EXIT_SUCCESS);
}

HTH
-- 
Marco Maggi




reply via email to

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