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:


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;


   A= new double[numel2];
   b=new double[numel];
   pivot=new int[numel];
   for (i=0;i<numel;i++) {
      for (j=0;j<numel;j++) {
         A[j*numel+i]=2.0*(i+1)+(j+1); }}

   cout << "IERR=" << ierr << "\n";
      cout << b[j] <<"\n";}
   delete pivot;
   delete b;
   delete A;


>>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?

This article has been dead for over six months. Start a new discussion instead.