Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2d array multiplication 1

Status
Not open for further replies.

aaadetos

Programmer
Nov 21, 2004
54
US
Hi, I have the ffg code, where I hope to muliply the 3 arrays specified, but on running Printarray(), i'm not getting what I expect. Help please!
Code:
// Q2_new.cpp : Defines the entry point for the console application.
//

#include <math>
#include "stdafx.h"
#include <iostream>
using namespace std;

double theta, phi, t, p;	//azimuth and dip angles respectively
double lambda1 = 0.5;
double lambda2 = 2;
const double pi = 3.142857;
const int rows = 3;
const int cols = 3;

//---------------------------------------------------------
//Code to convert the angles to radians, acceptable in C++
//---------------------------------------------------------
double rad_t(double t)
{
	theta = (t*pi)/180;
	return theta;
}

double rad_p(double p)
{
	phi= (p*pi)/180;
	return phi;
}

//-----------------------------------------------------------
//Initializing the matrices
//-----------------------------------------------------------
//array that holds the dip angle, phi
double dip_array [3][3] = {{cos(phi),0,-sin(phi)},{0,1,0},{sin(phi),0,cos(phi)}};	

//array that holds the azimuth angle, theta
double azim_array [3][3] = {{sin(theta),cos(theta),0},{-cos(theta),sin(theta),0},{0,0,1}};	

//array that holds the anisotropy ratios
double lambda_array [3][3] = {{lambda1,0,0},{0,1,0},{0,0,lambda2}};	

//----------------------------------------------------------------

void printarray (double arg[][3]) 
{
  for (int n=0; n<3; n++)
    cout << arg[n] << " ";
  cout << "\n";
}


int main(int argc, char* argv[])
{
	cout<<"ANISOTROPY MODELLING.\n";
	cout<<"Please enter a real number between 0 and 360 for the azimuth angle, theta, then press the 'Enter' key.\n";
	cin>>t;
	rad_t(t);'\n\n.';

	cout<<"Please enter a real number between 0 and 360 for the dip angle, phi, then press the 'Enter' key.\n";
	cin>>p;
	rad_p(p);

	printarray(dip_array);
	printarray(azim_array);
	printarray(lambda_array);

	return 0;
}

 
Still can't figure out why the arrays aren't yielding the proper values:
Code:
// Q2_new.cpp : Defines the entry point for the console application.
//

#include <math>
#include "stdafx.h"
#include <iostream>
using namespace std;

double theta, phi, t, p;	//azimuth and dip angles respectively
double lambda1 = 0.5;
double lambda2 = 2;
double a11,a12,a21,a22,d11,d13,d31,d33;
const double pi = 3.142857;
const int rows = 3;
const int cols = 3;

//---------------------------------------------------------
//Code to convert the angles to radians, acceptable in C++
//---------------------------------------------------------
//Dip Angle,p
double a(double p)
{
	d11 = cos((p*pi)/180);
	return d11;
}

double b(double p)
{
	d13 = -1*sin((p*pi)/180);
	return d13;
}

double c(double p)
{
	d31 = sin((p*pi)/180);
	return d31;
}

double d(double p)
{
	d33 = cos((p*pi)/180);
	return d33;
}


//Azimuth Angles, t
double e(double t)
{
	a11 = sin((t*pi)/180);
	return a11;
}

double f(double t)
{
	a12 = cos((t*pi)/180);
	return a12;
}

double g(double t)
{
	a21 = -1*cos((t*pi)/180);
	return a21;
}

double h(double t)
{
	a22 = sin((t*pi)/180);
	return a22;
}

//-----------------------------------------------------------
//Initializing the matrices
//-----------------------------------------------------------
//array that holds the dip angle, phi
double dip_array [3][3] = {{a(p),0,d13},{0,1,0},{d31,0,d33}};	

//array that holds the azimuth angle, theta
double azim_array [3][3] = {{a11,a12,0},{a21,a22,0},{0,0,1}};	

//array that holds the anisotropy ratios
double lambda_array [3][3] = {{lambda1,0,0},{0,1,0},{0,0,lambda2}};	

//----------------------------------------------------------------

void printarray (double arg[][3]) 
{
  for (int i=0; i<3; i++)//for each row
  {
	  for (int j=0; j<3; j++)	//for each column value
		  cout << arg[i][j] << " ";
	  cout << "\n";
  }
}


int main(int argc, char* argv[])
{
	
	cout<<"ANISOTROPY MODELLING.\n";
	cout<<"Please enter a real number between 0 and 360 for the azimuth angle, theta, then press the 'Enter' key.\n\n";
	cin>>t;

	cout<<"Please enter a real number between 0 and 360 for the dip angle, phi, then press the 'Enter' key.\n\n";
	cin>>p;

	a(p);
	b(p);
	c(p);
	d(p);
	e(t);
	f(t);
	g(t);
	h(t);

	printarray(dip_array);"\n.";
	printarray(azim_array);
	printarray(lambda_array);

	return 0;
}

 
i'm not getting what I expect.
WHAT you expect?

No such header <math>: it's <cmath>...
 
math.h does contain sin() and cos(); and when you do a random check, say cout<<a(p);, i actually get the correct value. but the correct values are not turning up in my arrays. Please check and see. Why is this?
 
Ok....I moved the initialization to after I called the functions, not before. So the arrays are reading correctly now. This was the problem.
 
New Problem: Now I'm doing the multiplication, where I'm trying to multiply the arrays in this order:
Code:
lambda_array*dip_array*azim_array*r_array
what am i doing wrong? all my values in the final range array, fr_array are all zero, which shouldn't be the case...
Here's the code.
Code:
// Q2_new.cpp : Defines the entry point for the console application.
//

#include <math>
#include "stdafx.h"
#include <iostream>
using namespace std;

double theta, phi, t, p;	//azimuth and dip angles respectively
double lambda1 = 0.5;
double lambda2 = 2;
double a11,a12,a21,a22,d11,d13,d31,d33;
const double pi = 3.142857;
const int rows = 3;
const int cols = 3;

//---------------------------------------------------------
//Initializing the arrays to zero
//---------------------------------------------------------
	//array that holds the dip angle, phi
	double dip_array [3][3] = {0};	

	//array that holds the azimuth angle, theta
	double azim_array [3][3] = {0};	

	//array that holds the anisotropy ratios
	double lambda_array [3][3] = {0};	

	//array that holds the original range values
	double r_array [3] = {0};

	//array that holds final range values
	double fr_array [3][3] = {0};	


//---------------------------------------------------------
//Code to convert the angles to radians, acceptable in C++
//---------------------------------------------------------
//Dip Angle,p
double a(double p)
{
	d11 = cos((p*pi)/180);
	return d11;
}

double b(double p)
{
	d13 = -1*sin((p*pi)/180);
	return d13;
}

double c(double p)
{
	d31 = sin((p*pi)/180);
	return d31;
}

double d(double p)
{
	d33 = cos((p*pi)/180);
	return d33;
}


//Azimuth Angles, t
double e(double t)
{
	a11 = sin((t*pi)/180);
	return a11;
}

double f(double t)
{
	a12 = cos((t*pi)/180);
	return a12;
}

double g(double t)
{
	a21 = -1*cos((t*pi)/180);
	return a21;
}

double h(double t)
{
	a22 = sin((t*pi)/180);
	return a22;
}


void printarray (double arg[][3]) 
{
  for (int i=0; i<rows; i++)//for each row
  {
	  for (int j=0; j<cols; j++)	//for each column value
		  cout << arg[i][j] << " ";
	  cout << "\n";
  }
}

void printarray2(double arg[]) 
{
  for (int i=0; i<rows; i++)//for each row
  {
	  //for (int j=0; j<3; j++)	//for each column value
		  cout << arg[i] << " ";
	  cout << "\n";
  }
}

	//code for multiplication of the dip and azim matrices
	void mult(double fr_array[3][3])
	{
		for(int i=0;i<rows;i++)	//for each row
		{
			for(int j=0;j<cols;j++)	//for each column
			{
				for(int k=0;k<cols;k++)	//for each column
				{
					for(int l=0;l<cols;l++)	//for each column
					{
					//	fr_array [i][j] += dip_array [i][k]*azim_array [k][j];
						fr_array [i][j] += lambda_array [i][l]*dip_array [l][k]*azim_array[k][j];
						fr_array [i][j] += fr_array[i][j]*r_array[i];
					}
				}
			}
		}
	}




int main(int argc, char* argv[])
{
	
	cout<<"ANISOTROPY MODELLING.\n";
	cout<<"\nPlease enter a real number between 0 and 360 for the azimuth angle, theta, then press the 'Enter' key.\n\n";
	cin>>t;

	cout<<"\nPlease enter a real number between 0 and 360 for the dip angle, phi, then press the 'Enter' key.\n\n";
	cin>>p;

	a(p);
	b(p);
	c(p);
	d(p);
	e(t);
	f(t);
	g(t);
	h(t);

	//-----------------------------------------------------------
	//Initializing the matrices
	//-----------------------------------------------------------
	//array that holds the dip angle, phi
	double dip_array [3][3] = {{d11,0,d13},{0,1,0},{d31,0,d33}};	

	//array that holds the azimuth angle, theta
	double azim_array [3][3] = {{a11,a12,0},{a21,a22,0},{0,0,1}};	

	//array that holds the anisotropy ratios
	double lambda_array [3][3] = {{lambda1,0,0},{0,1,0},{0,0,lambda2}};	

	//array that holds the original range values
	double r_array [3] = {4,8,3.94};


	//----------------------------------------------------------------

	//code to check that the arrays are properly initialized in the matrices for any theta,phi
	cout<<"\nThe dip array is:\n";
	printarray(dip_array);

	cout<<"\nThe azimuth array is:\n";
	printarray(azim_array);

	cout<<"\nThe anisotropy array is:\n";
	printarray(lambda_array);

	cout<<"\nThe original range array is:\n";
	printarray2(r_array);

	//----------------------------------------------------------------

	mult(fr_array);
	cout<<"\nThe final range array is:\n";
	printarray(fr_array);



	return 0;
}

You can use 60 degrees for theta and phi, for check, since cos(60) = 0.5, sin(60) = 0.866....


 
changing my function prototype doesn't correct the problem. Can someone please help me out? Am I not multiplying the arrays correctly? Here's the new code for a more simplistic case:
Code:
// Q2_new.cpp : Defines the entry point for the console application.
//

#include <math>
#include "stdafx.h"
#include <iostream>
using namespace std;

double theta, phi, t, p;	//azimuth and dip angles respectively
double lambda1 = 0.5;
double lambda2 = 2;
double a11,a12,a21,a22,d11,d13,d31,d33;
const double pi = 3.142857;
const int rows = 3;
const int cols = 3;

//---------------------------------------------------------
//Initializing the arrays to zero
//---------------------------------------------------------
	//array that holds the dip angle, phi
	double dip_array [3][3] = {0};	

	//array that holds the azimuth angle, theta
	double azim_array [3][3] = {0};	

	//array that holds the anisotropy ratios
	double lambda_array [3][3] = {0};	

	//array that holds the original range values
	double r_array [3] = {0};

	//array that holds final range values
	double fr_array [3][3] = {0};	

	//array that holds final range values
	double fr_array2 [3] = {0};	



//---------------------------------------------------------
//Code to convert the angles to radians, acceptable in C++
//---------------------------------------------------------
//Dip Angle,p
double a(double p)
{
	d11 = cos((p*pi)/180);
	return d11;
}

double b(double p)
{
	d13 = -1*sin((p*pi)/180);
	return d13;
}

double c(double p)
{
	d31 = sin((p*pi)/180);
	return d31;
}

double d(double p)
{
	d33 = cos((p*pi)/180);
	return d33;
}


//Azimuth Angles, t
double e(double t)
{
	a11 = sin((t*pi)/180);
	return a11;
}

double f(double t)
{
	a12 = cos((t*pi)/180);
	return a12;
}

double g(double t)
{
	a21 = -1*cos((t*pi)/180);
	return a21;
}

double h(double t)
{
	a22 = sin((t*pi)/180);
	return a22;
}


void printarray (double arg[][3]) 
{
  for (int i=0; i<rows; i++)//for each row
  {
	  for (int j=0; j<cols; j++)	//for each column value
		  cout << arg[i][j] << " ";
	  cout << "\n";
  }
}

void printarray2(double arg[]) 
{
  for (int i=0; i<rows; i++)//for each row
  {
	  //for (int j=0; j<3; j++)	//for each column value
		  cout << arg[i] << " ";
	  cout << "\n";
  }
}

	//code for multiplication of the dip and azim matrices
/*	void mult(double fr_array2 [3])
	{
		for(int i=0;i<rows;i++)	//for each row
		{
			for(int j=0;j<cols;j++)	//for each column
			{
				for(int k=0;k<cols;k++)	//for each column
				{
					for(int l=0;l<cols;l++)	//for each column
					{
					//	fr_array [i][j] += dip_array [i][k]*azim_array [k][j];
						fr_array [i][j] += lambda_array [i][l]*dip_array [l][k]*azim_array[k][j];
						fr_array2 [i] += fr_array[i][j]*r_array[i];
					}
				}
			}
		}
	}*/

	//code for multiplication of the matrices
	void mult(double *fr_array2)
	{
		for(int i=0;i<rows;i++)	//for each row
		{
			for(int j=0;j<cols;j++)	//for each column
			{
				fr_array2 [i] += azim_array[i][j]*r_array[i];
			}
		}
	}


int main(int argc, char* argv[])
{
	
	cout<<"ANISOTROPY MODELLING.\n";
	cout<<"\nPlease enter a real number between 0 and 360 for the azimuth angle, theta, then press the 'Enter' key.\n\n";
	cin>>t;

	cout<<"\nPlease enter a real number between 0 and 360 for the dip angle, phi, then press the 'Enter' key.\n\n";
	cin>>p;

	a(p);
	b(p);
	c(p);
	d(p);
	e(t);
	f(t);
	g(t);
	h(t);

	//-----------------------------------------------------------
	//Initializing the matrices
	//-----------------------------------------------------------
	//array that holds the dip angle, phi
	double dip_array [3][3] = {{d11,0,d13},{0,1,0},{d31,0,d33}};	

	//array that holds the azimuth angle, theta
	double azim_array [3][3] = {{a11,a12,0},{a21,a22,0},{0,0,1}};	

	//array that holds the anisotropy ratios
	double lambda_array [3][3] = {{lambda1,0,0},{0,1,0},{0,0,lambda2}};	

	//array that holds the original range values
	double r_array [3] = {4,8,3.94};


	//----------------------------------------------------------------

	//code to check that the arrays are properly initialized in the matrices for any theta,phi
	cout<<"\nThe dip array is:\n";
	printarray(dip_array);

	cout<<"\nThe azimuth array is:\n";
	printarray(azim_array);

	cout<<"\nThe anisotropy array is:\n";
	printarray(lambda_array);

	cout<<"\nThe original range array is:\n";
	printarray2(r_array);

	//----------------------------------------------------------------

	mult(fr_array2);
	cout<<"\nThe final range array is:\n";
	printarray2(fr_array2);

	return 0;
}





 
Well correct me if Im wrong here, but I think one issue is that PI is 3.1415926535898 I cant remember past that atm so..
 
I think in your mult prototype you need to pass by reference:


void mult(double &fr_array2)

otherwise you are just copying the global fr_array2 array to the local array fr_array2, modifying the local fr_array2, and then printing the elements of the unchanged global fr_array2. Note that these two arrays have different scopes.

 
my bad, I can't compile code on my internet box, so I can't run your code. The prototype was right:

void mult(double *fr_array2)

but you need to pass the array like this:

mult(&fr_array2);

 
See, these are the problems you get when you use too many global variables, and give them the same names as your local variables.

The problem for you is the local variables in main(), which are set up to contain all your values are NOT the ones used by your mult function to do all the work. Your mult function is using the ones filled with zeros.

Code:
g++ -Wshadow -W -Wall -ansi -pedantic -O2 xxx.cpp
xxx.cpp: In function `int main()':
xxx.cpp:327: warning: declaration of `dip_array' shadows a global declaration
xxx.cpp:222: warning: shadowed declaration is here

Try this code, passing the arrays to the function, rather than assuming everything is global.
Code:
#include <cmath>
#include <iostream>
using namespace std;

const double pi = 3.1415926535898;  // Much better value for PI
const int rows = 3;
const int cols = 3;

//---------------------------------------------------------
//Code to convert the angles to radians, acceptable in C++
//---------------------------------------------------------
//Dip Angle,p
double a(double p)
{
    return cos((p*pi)/180);
}

double b(double p)
{
    return -1*sin((p*pi)/180);
}

double c(double p)
{
    return sin((p*pi)/180);
}

double d(double p)
{
    return cos((p*pi)/180);
}


//Azimuth Angles, t
double e(double t)
{
    return sin((t*pi)/180);
}

double f(double t)
{
    return cos((t*pi)/180);
}

double g(double t)
{
    return -1*cos((t*pi)/180);
}

double h(double t)
{
    return sin((t*pi)/180);
}


void printarray (double arg[][cols])
{
  for (int i=0; i<rows; i++)//for each row
  {
      for (int j=0; j<cols; j++)    //for each column value
          cout << arg[i][j] << " ";
      cout << "\n";
  }
}

void printarray2(double arg[])
{
  for (int i=0; i<rows; i++)//for each row
  {
      cout << arg[i] << " ";
      cout << "\n";
  }
}

//code for multiplication of the matrices
void mult(double *fr_array2, double azim_array[][cols], double r_array[] )
{
    for(int i=0;i<rows;i++)    //for each row
    {
        for(int j=0;j<cols;j++)    //for each column
        {
            fr_array2[i] += azim_array[i][j]*r_array[i];
//            All these print 0 in YOUR code
//            cout << "fr_array2[i]="<< fr_array2[i]<<" ";
//            cout << "azim_array[i][j]="<<azim_array[i][j]<<" ";
//            cout << "r_array[i]="<<r_array[i];
//            cout << endl;
        }
    }
}


int main(void)
{
    double lambda1 = 0.5;
    double lambda2 = 2;
    double t,p;

    cout<<"ANISOTROPY MODELLING.\n";
    cout<<"\nPlease enter a real number between 0 and 360 for the azimuth angle, ";
    cout<<"theta, then press the 'Enter' key.\n\n";
    cin>>t;

    cout<<"\nPlease enter a real number between 0 and 360 for the dip angle, phi, ";
    cout<<"then press the 'Enter' key.\n\n";
    cin>>p;

    //-----------------------------------------------------------
    //Initializing the matrices
    //-----------------------------------------------------------
    //array that holds the dip angle, phi
    double dip_array [3][3] = {{a(p),0,b(p)},{0,1,0},{c(p),0,d(p)}};

    //array that holds the azimuth angle, theta
    double azim_array [3][3] = {{e(t),f(t),0},{g(t),h(t),0},{0,0,1}};

    //array that holds the anisotropy ratios
    double lambda_array [3][3] = {{lambda1,0,0},{0,1,0},{0,0,lambda2}};

    //array that holds the original range values
    double r_array [3] = {4,8,3.94};

    //array that holds final range values
    double fr_array2 [3] = {0};

    //----------------------------------------------------------------

    //code to check that the arrays are properly initialized in the matrices for any theta,phi
    cout<<"\nThe dip array is:\n";
    printarray(dip_array);

    cout<<"\nThe azimuth array is:\n";
    printarray(azim_array);

    cout<<"\nThe anisotropy array is:\n";
    printarray(lambda_array);

    cout<<"\nThe original range array is:\n";
    printarray2(r_array);

    //----------------------------------------------------------------

    mult(fr_array2,azim_array,r_array);
    cout<<"\nThe final range array is:\n";
    printarray2(fr_array2);

    return 0;
}

Gives these results
Code:
$ ./a.out
ANISOTROPY MODELLING.

Please enter a real number between 0 and 360 for the azimuth angle, theta, then press the 'Enter' key.

20

Please enter a real number between 0 and 360 for the dip angle, phi, then press the 'Enter' key.

30

The dip array is:
0.866025 0 -0.5
0 1 0
0.5 0 0.866025

The azimuth array is:
0.34202 0.939693 0
-0.939693 0.34202 0
0 0 1

The anisotropy array is:
0.5 0 0
0 1 0
0 0 2

The original range array is:
4
8
3.94

The final range array is:
5.12685
-4.78138
3.94

--
 
Thanks a lot guys. I really appreciate it. B4 I saw Salem's post, I'd already implemented this formulation, which runs consistently with Excel/hand calculations for the matrix multiplication. I still don't quite understand why the values were becoming '0' in mult()[saw this when i ran in "debug" mode], but when the code in mult() was implemented directly in main(), I got appreciable results. Here it is:
Code:
// Q2.cpp : Defines the entry point for the console application.
//

#include <math>
#include "stdafx.h"
#include <iostream>
using namespace std;

double t, p;	//azimuth and dip angles respectively
double lambda1 = 0.5;
double lambda2 = 2;
double a11,a12,a21,a22,d11,d13,d31,d33;
const double pi = 3.142857;
const int rows = 3;
const int cols = 3;

double range,f_range;

//---------------------------------------------------------
//Initializing the arrays to zero
//---------------------------------------------------------
	//array that holds the dip angle, phi
	double dip_array [3][3] = {0};	

	//array that holds the azimuth angle, theta
	double azim_array [3][3] = {0};	

	//array that holds the anisotropy ratios
	double lambda_array [3][3] = {0};	

	//array that holds the original range values
	double r_array [3] = {0};

	//array that holds final range values
	double fr_array [3][3] = {0};	

	//array that holds final range values
	double fr_array2 [3] = {0};	



//---------------------------------------------------------
//Code to convert the angles to radians, acceptable in C++
//---------------------------------------------------------
//Dip Angle,p
double a(double p)
{
	d11 = cos((p*pi)/180);
	return d11;
}

double b(double p)
{
	d13 = -1*sin((p*pi)/180);
	return d13;
}

double c(double p)
{
	d31 = sin((p*pi)/180);
	return d31;
}

double d(double p)
{
	d33 = cos((p*pi)/180);
	return d33;
}


//Azimuth Angles, t
double e(double t)
{
	a11 = sin((t*pi)/180);
	return a11;
}

double f(double t)
{
	a12 = cos((t*pi)/180);
	return a12;
}

double g(double t)
{
	a21 = -1*cos((t*pi)/180);
	return a21;
}

double h(double t)
{
	a22 = sin((t*pi)/180);
	return a22;
}


void printarray (double arg[][3]) 
{
  for (int i=0; i<rows; i++)//for each row
  {
	  for (int j=0; j<cols; j++)	//for each column value
		  cout << arg[i][j] << " ";
	  cout << "\n";
  }
}

void printarray2(double arg[]) 
{
  for (int i=0; i<rows; i++)//for each row
  {
	  //for (int j=0; j<3; j++)	//for each column value
		  cout << arg[i] << " ";
	  cout << "\n";
  }
}

int main(int argc, char* argv[])
{
	
	cout<<"ANISOTROPY MODELLING.\n";
	cout<<"\nPlease enter a real number between 0 and 360 for the azimuth angle, theta, then press the 'Enter' key.\n\n";
	cin>>t;

	cout<<"\nPlease enter a real number between 0 and 360 for the dip angle, phi, then press the 'Enter' key.\n\n";
	cin>>p;

	a(p);
	b(p);
	c(p);
	d(p);
	e(t);
	f(t);
	g(t);
	h(t);

	//-----------------------------------------------------------
	//Loading the matrices
	//-----------------------------------------------------------
	//array that holds the dip angle, phi
	double dip_array [3][3] = {{d11,0,d13},{0,1,0},{d31,0,d33}};	

	//array that holds the azimuth angle, theta
	double azim_array [3][3] = {{a11,a12,0},{a21,a22,0},{0,0,1}};	

	//array that holds the anisotropy ratios
	double lambda_array [3][3] = {{lambda1,0,0},{0,1,0},{0,0,lambda2}};	

	//array that holds the original range values
	double r_array [3] = {4,8,3.94};


	//----------------------------------------------------------------

	//code to check that the arrays are properly initialized in the matrices for any theta,phi
	cout<<"\nThe dip array is:\n";
	printarray(dip_array);

	cout<<"\nThe azimuth array is:\n";
	printarray(azim_array);

	cout<<"\nThe anisotropy array is:\n";
	printarray(lambda_array);

	cout<<"\nThe original range array is:\n";
	printarray2(r_array);

	//----------------------------------------------------------------

	//Matrix multiplication code
	for(int i=0;i<rows;i++)	//for each row
		{
			for(int j=0;j<cols;j++)	//for each column
			{
				for(int k=0;k<cols;k++)	//for each column
				{
					for(int l=0;l<cols;l++)	//for each column
					{
						fr_array2 [i] += lambda_array[i][l]*dip_array[l][k]*azim_array[k][j]*r_array[j];
					}
				}
			}
		}
	
	//Print the final range array	
	cout<<"\nThe final range array is:\n";
	printarray2(fr_array2);

	//code for determining the value of the range
	for(i=0;i<rows;i++)
	{
		range += pow(fr_array2[i],2);
		f_range = pow(range,0.5);//f_range = sqrt(sq.of range in x,y,z dir) 
	}

	//Print the final range value
	cout<<"\nThe final range value - given the specified azimuth and dip angles - is:\n";
	cout<<"Range = "<<f_range<<endl;


	return 0;
}




 
Where do you get that weird pi from?

pi != 3.142857

/Per
[sub]
www.perfnurt.se[/sub]
 
That was a typo. PI wasn't my problem anyway...and frankly, i don't need such high accuracy for PI...
Code:
double PI = 3.141592653589793238462643383279502884197;
is not necessary for me. but thanks for pointing it out.
 
> I still don't quite understand why the values were becoming '0' in mult()
So can I take that as you didn't read my explanation at all?
Or that you read it, but didn't understand it?

Because you seem to have paid scant regard to anything I've said in your next attempt.

I could explain, but I'm not convinced it would actually do any good [sad]

--
 
Salem,
>>Thanks a lot guys. I really appreciate it. B4 I saw Salem's post, I'd already implemented this formulation, which runs consistently with Excel/hand calculations for the matrix multiplication.<<

My next implementation was created b4 i saw your post. i was in the process of posting that i'd found some solution to what was perplexing with mult()...which was before i actaully read ur post.

But i do understand your post. You said it all in the 1st 2 paragraphs and even ran the code to show me the output i'd get if it wasn't using the zeroes..[Thank you for your time!!]>>See, these are the problems you get when you use too many global variables, and give them the same names as your local variables.

The problem for you is the local variables in main(), which are set up to contain all your values are NOT the ones used by your mult function to do all the work. Your mult function is using the ones filled with zeros.<<

Effectively, the cause of the problem was the global definitions/declarations of the arrays, which was conflicting with the local definitions in main().

I keep upgrades of all my code; and your implementation is a superior implementation with what may be a "flaw", where the arrays arte not initialized to "0" in the first place....But yes, I understand it. And thank you!

What I don't understand is why "while()" didn't work here:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top