Cplusplus – die meistgelesenen Beiträge

Zahl mit Arduino an MySQL Datenbank senden?

Moin,

Vielleicht kann mir jemand helfen. Ich will, dass mein Arduino den Wert einer stinknormalen Variable an eine MySQL-Datenbank schickt. Ich bin mehr oder weniger am Verzweifeln, weil mir niemand helfen kann... Es kann doch nicht so schwer sein, ne blöde Zahl irgendwie in Form einer Variable an die Datenbank zu senden...

Ich benutze einen normales Arduino Uno, und ein W5100 ethernet shield

Mein bisheriger Ansatz war so: (Logindaten der Datenbank entfernt)

#include <Ethernet.h>

#include <MySQL_Connection.h>

#include <MySQL_Cursor.h>

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr('localhost'); 

char user[] = "root";       

char password[] = "secret";    

// Sample query

char INSERT_SQL[] = "INSERT INTO Test (Sensor) VALUES ('3')";

EthernetClient client;

MySQL_Connection conn((Client *)&client);

void setup() {

 Serial.begin(115200);

 while (!Serial);

 Ethernet.begin(mac_addr);

 Serial.println("Connecting...");

 if (conn.connect(server_addr, 3306, user, password)) {

  delay(1000);

 }

 else

  Serial.println("Connection failed.");

}

void loop() {

 delay(2000);

 Serial.println("Recording data.");

 

 MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);

 cur_mem->execute(INSERT_SQL);

 delete cur_mem;

}

SQL, HTML, Webseite, programmieren, Java, Cplusplus, Arduino, Datenbank, MySQL, PHP, Programmiersprache, Python, Softwareentwicklung, Webentwicklung, phpMyAdmin, Raspberry Pi

C++ Code für LGS?

Ich möchte mit einen C++-Programm alle LGS lösen können (endlich, unendlich und keine Lösungen). Ich habe auch einen Code. Endlich viele und keine Lösungen kann er recht gut (bisher), aber unendlich viele Lösungen kann er nicht anzeigen lassen (soll dann auch t einführen, nicht einfach einen Wert einsetzen).

Wo liegt der Fehler?

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

// Funktion zur Berechnung des Determinanten einer Matrix
double determinant(vector<vector<double>>& matrix, int n) {
  double det = 0;

  if (n == 1) {
    return matrix[0][0];
  }

  if (n == 2) {
    return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
  }

  for (int i = 0; i < n; i++) {
    vector<vector<double>> subMatrix(n - 1, vector<double>(n - 1));

    for (int j = 1; j < n; j++) {
      for (int k = 0; k < n; k++) {
        if (k < i) {
          subMatrix[j - 1][k] = matrix[j][k];
        }
        else if (k > i) {
          subMatrix[j - 1][k - 1] = matrix[j][k];
        }
      }
    }

    det += pow(-1, i) * matrix[0][i] * determinant(subMatrix, n - 1);
  }

  return det;
}
 
// Funktion zur Durchführung der Gauss-Jordan-Elimination
void gaussJordan(vector<vector<double>>& matrix, vector<double>& constants) {
  int n = matrix.size();

  for (int i = 0; i < n; i++) {
    int maxIndex = i;

    for (int j = i + 1; j < n; j++) {
      if (abs(matrix[j][i]) > abs(matrix[maxIndex][i])) {
        maxIndex = j;
      }
    }

    if (maxIndex != i) {
      swap(matrix[maxIndex], matrix[i]);
      swap(constants[i], constants[maxIndex]); // Korrektur hier
    }

    double factor = matrix[i][i];

    for (int j = i; j < n; j++) {
      matrix[i][j] /= factor;
    }

    constants[i] /= factor;

    for (int j = 0; j < n; j++) {
      if (j != i) {
        double factor = matrix[j][i];

        for (int k = i; k < n; k++) {
          matrix[j][k] -= factor * matrix[i][k];
        }

        constants[j] -= factor * constants[i];
      }
    }
  }
}

// Funktion zur Überprüfung der Invertierbarkeit und zur Lösung des LGS
vector<double> solveLinearSystem(vector<vector<double>>& matrix, vector<double>& constants) {
  int n = matrix.size();
  double det = determinant(matrix, n);

  // Überprüfung auf unendlich viele Lösungen
  bool allZero = true;

  for (double constant : constants) {
    if (constant != 0) {
      allZero = false;
      break;
    }
  }

  if (det == 0) {
    if (allZero) {
      cout << "Das LGS hat unendlich viele Lösungen." << endl;
      return {}; // Leerer Vektor, da unendlich viele Lösungen existieren
    }
    else {
      cout << "Das LGS hat keine Lösung." << endl;
      return {}; // Leerer Vektor, da keine Lösung existiert
    }
  }

  // Anwendung der Gauss-Jordan-Elimination
  gaussJordan(matrix, constants);

  vector<double> solution(n);

  for (int i = 0; i < n; i++) {
    solution[i] = constants[i];
  }

  return solution;
}

int main() {
  vector<vector<double>> matrix = {
    { 1, -3,  5 },
    { 2, -5,  12 },
    { 3, -11,  11 }
  };
  vector<double> constants = { 2, 1, 12 };

  vector<double> solution = solveLinearSystem(matrix, constants);

  if (!solution.empty()) {
    cout << "Die Lösung des LGS ist: ";

    for (int i = 0; i < solution.size(); i++) {
      cout << "x" << i + 1 << " = " << solution[i] << ", ";
    }

    cout << endl;
  }
  else {
    cout << "Das LGS hat keine Lösung." << endl;
  }

  return 0;
}
Schule, Mathematik, programmieren, Cplusplus, Mathematiker, Programmiersprache, Algorithmus, lineare Gleichungssysteme

Was soll ich alles auf Fiverr anbieten (Jugendlicher, Programmierer)?

Hi.

Also ich würde ganz gerne etwas Geld verdienen, vor allem durch's Programmieren. Problem: Ich mache meine Mittlere Reife erst in 2 1/2 Jahren, da ich durch Corona und Inkomepetenz 2. mal eine Klasse wiederholen musste.

Mir wurde mal vorgeschlagen, mich auf Fiverr zu registrieren. Jetzt frage ich mich aber, was ich am besten anbieten sollte. Ich erzähl hier einfach mal, was ich schon so für Zeug gemacht habe, damit ihr wisst, was ich so kann.

Ich hab mit folgenden Dingen schon gearbeitet (also relativ intensiv):

  • Neuronale Netzwerke (relativ "neu") [Tensorflow, Python]
  • Minecraft Plugins [Spigot API, Java]
  • Webseiten (static und und dynamic) [HTML, CSS, JavaScript, Python/PHP/C++]
  • Automatisierungen (vor allem Webseiten) [Selenium, Python]
  • Scrapper [BeatifulSoup, Python]
  • Discord API (z.B. um Daten über User zu kriegen)
  • Discord Bots [Python und Java, von Scratch und mit Library]
  • MySQL Datenbanken [Python, C#]
  • SQLite Datenbanken [Python, C#, Java]
  • WinForms [C#]
  • WPF [C#]
  • REST API's (um genau zu sein eigene gemacht und die Discord API verwendet)
  • win32.dll [Python, C++, C#]
  • YouTubeDLL [Python]
  • Spotify API (z.B. zum Song wechseln, oder Song Daten anzufragen)

Als übersicht, ich "kann" folgende Programmiersprachen (ich weiß, HTML und CSS sind keine Programmiersprachen) [Sortiert nach Skill]:

  • Python
  • C#
  • Java
  • PHP
  • HTML/CSS/JavaScript <- Alles relativ gleich gut
  • C++ (Simple Sachen, wie Web Server)

Wenn man beachtet, was ich kann. Was würdet ihr mir zum anbieten, auf Fiverr, empfehlen?

Danke im vorraus und lg.

Computer, Arbeit, Software, Technik, Geld, HTML, Webseite, Java, Jugendliche, JavaScript, Cplusplus, Minecraft, C Sharp, Freelancer, Jungs, Programmiersprache, Python, fiverr, Discord, Wirtschaft und Finanzen