The LAPACK forum has moved to https://github.com/Reference-LAPACK/lapack/discussions.

[SOLVED]which function to do the same as matlab : x=a\b

Open discussion regarding features, bugs, issues, vendors, etc.

[SOLVED]which function to do the same as matlab : x=a\b

Postby pep_gentoo » Fri Sep 21, 2007 12:37 pm

Hello,

I've recently post a message in the forum because i'm trying to zgels to solve this problem:
matrix A = [1+i*1 2+i*1;
3+i*2 1+i*2;
2+i*3 2+i*1];
matrix B = [2+i*2;
1+i*3;
3+i*1];
x=a\b

answer for x is:
-9.23e-002 -1.076e-001i
1.43 2.61i

I've tried to use zgels to solve this system.
This is a mxn matrix full-range so should repect the usage of the function.

zgels('N',&m,&n,&nrhs,a,&lda,b,&ldb,x,&lwork,&result)

with m=3 n=2 nrhs=1 lda=3 ldb=3 and work = n+max(m,rhs)

but i can't manage get the good result...
I suspected that my array in C were not well written but i've been carefull to fill the memory with reverse order as fortran style...

when i launch my program mkl says taht parameter 9 was incorrect on entry to ZTRSM...
I don't know what to do now...

So my question is:
- is zgels the good function to use???

Thanks you a lot for any help!!
Last edited by pep_gentoo on Fri Sep 21, 2007 2:27 pm, edited 1 time in total.
pep_gentoo
 
Posts: 3
Joined: Thu Sep 20, 2007 11:25 am

Postby Julien Langou » Fri Sep 21, 2007 12:51 pm

Try this C code first.

Code: Select all
#include <stdio.h>

typedef struct {
        double real, imag;
}doublecomplex;

extern void zgels_( char *trans, int *m, int *n, int *nrhs, doublecomplex *a, int *lda,
   doublecomplex *b, int *ldb, doublecomplex *work, int *lwork, int *info );

int main ()
{

   int m=3, lda=3, ldb=3, n=2, nrhs=1, lwork=2*n, info;
   doublecomplex A[lda*n], b[ldb*nrhs], work[lwork];

   A[ 0].real =  1.0e+00; A[ 0].imag =  1.0e+00;
   A[ 1].real =  3.0e+00; A[ 1].imag =  2.0e+00;
   A[ 2].real =  2.0e+00; A[ 2].imag =  3.0e+00;
   A[ 3].real =  2.0e+00; A[ 3].imag =  1.0e+00;
   A[ 4].real =  1.0e+00; A[ 4].imag =  2.0e+00;
   A[ 5].real =  2.0e+00; A[ 5].imag =  1.0e+00;

   b[ 0].real =  2.0e+00; b[ 0].imag =  2.0e+00;
   b[ 1].real =  1.0e+00; b[ 1].imag =  3.0e+00;
   b[ 2].real =  3.0e+00; b[ 2].imag =  1.0e+00;

   zgels_( "N", &m, &n, &nrhs, A, &lda, b, &ldb, work, &lwork, &info);

   printf("x = [\n\t(%f,%f)\n\t(%f,%f)\n]\n",b[0].real,b[0].imag,b[1].real,b[1].imag);


   return 0;

}
Julien Langou
 
Posts: 835
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA

Postby pep_gentoo » Fri Sep 21, 2007 2:26 pm

Thank you so much julian!
Thank you a lot for you time.
Thx to your example i've seen where was my error!
There was 2 errors, i didn't understood that worlk argument was a temporary matrix, i was thinking it was the result. After my post, i 've rereaden the doc and seen my first error.
The second one was an allocation size error... hum...
Work was not enought long and i made the result false...
Anyway thank you a lot, without you i should'nt have made this work!
pep_gentoo
 
Posts: 3
Joined: Thu Sep 20, 2007 11:25 am


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 4 guests