For this assignment you will write a wrapper routine for the LAPACK routine DGESV to solve the system of equations Ax=b (where A is a num by num matrix, and x and b are vectors of length num). A wrapper is a routine that reformats (or supplements) it's arguements in order to call another routine. Your prototype will be:

C++

void wdgesv(double **A,double b[],long int num,double x[],long int ier)

and example code given

#include <iostream>
#include <stdlib.h>
 
using namespace std;

extern "C" void  dgesv_(int *n, int *nrhs, double *a, int *lda, int *ipiv, 
double *b, int *ldb, int *info );

int main() {

   double *A, *b;
   int *pivot;
   int numel, numel2, icount,mcount=0,i,j,il,jl,ierr,nrhs;
   double zero;

   numel=11;
   numel2=numel*numel;
   nrhs=1;

   A= new double[numel2];
   b=new double[numel];
   pivot=new int[numel];
   for (i=0;i<numel;i++) {
      b[i]=(i+1)/10;
      for (j=0;j<numel;j++) {
         A[j*numel+i]=2.0*(i+1)+(j+1); }}
   
   dgesv_(&numel,&nrhs,A,&numel,pivot,b,&numel,&ierr);

   cout << "IERR=" << ierr << "\n";
   for(j=0;j<numel;j++){
      cout << b[j] <<"\n";}
 
   delete pivot;
   delete b;
   delete A;

}

Recommended Answers

All 2 Replies

>>line 20: b=(i+1)/10;

This is odd coming from a professor. All values of i that are less than 10 will result in a value of 0. Values of i between 10 and 19 are 1, etc. Why would you want to initialize an array with those kinds of numbers?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.