Unterprogramm mit Arrays

martin5

Grünschnabel
Hallo Leute,

werke gerade an einem Programm herum das einem Gleichungen löst.
Ich möchte aber die Determinantenberechnung schön ein einem Unterprogramm verstauen (Funktion).
Aber wie?
Hätte es so versucht, leider wird dann die Variable a und b mehrfach deklariert...

Code:
void detdxdy(float, float, float, float, float, float, float &, float &, float &);
void detdxdy(float a[1][1], float a[1][2], float a[2][1], float a[2][2], float b[1], float b[2], float &det, float &dx, float &dy)
{
			det = a[1][1] * a[2][2] - a[2][1] * a[1][2];
			dx  = b[1]   * a[2][2] - b[2]    * a[1][2];
			dy  = b[2]   * a[1][1] - b[1]    * a[2][1];
}
}


Kann mir bitte wer helfen?

Grüße
Martin
 
Hi Martin,

weis nicht ob du schon ne Lösung hast.. aber versuch mal in der Funktion ohne Arrays zu arbeiten.. so hats bei mir mal funktioniert.. also umgefähr so


Code:
void detdxdy(float, float, float, float, float, float, float &, float &, float &);


void detdxdy(float a, float b, float c, float d, float e, float f, float &det, float &dx, float &dy)
{
			det = a * d - c * b;
			dx  = e   * d - f    * b;
			dy  = f   * a - e    * c;


Variablen dann nur noch vernünftig benennen ^^


frohe Weihnachten!
 
@martin5

Wieso übergibst du nicht einfach die Matrix als zweidimensionales Array und den Vektor als normales Array ? Dann noch ein Array mitgeben wo dx und dy gespeichert werden.

C++:
// gibt die Determinante einer 2*2 Matrix zurück und speichert dx,dy in einer Referenz
float detdxdy(const float** A, const float* B, float*& D);
{
  float det = (A[0][0] * A[1][1]) - (A[1][0] * A[0][1]);
  // dx und dy in D speichern
  D[0] = (B[0] * A[1][1]) - (B[1] * A[0][1]);  // dx
  D[1] = (A[0][0] * B[1]) - (A[1][0] * B[0]); // dy
  return det;
}

mfg
 
Danke für eure Antworten. Habs jetzt so gelöst, da mir Zeiger noch total fremd sind, aber danke trotzdem.

Code:
void detdxdy(float a[10][10],  float b[10],  float& det, float& dx, float& dy)
{
		det = a[1][1] * a[2][2] - a[2][1] * a[1][2];
		dx  = b[1]    * a[2][2] - b[2]    * a[1][2];
		dy  = b[2]    * a[1][1] - b[1]    * a[2][1];
}

Gruß
Martin
 
Zurück