i have to calculate the underlying area of a function, to get the function from the keyboard i want to use the library muparser but i get this error:
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:10: main] Error 1
the code main.cc is:
#include <iostream>
#include <muParser.h>
#include <cmath>
using namespace std;
double funzione(double x, mu::Parser& parser) {
parser.DefineVar("x", &x);
return parser.Eval();
}
double calcolaAreaTrapezi(double a, double b, int n, mu::Parser& parser) {
double h = (b - a) / n;
double result = 0.5 * (funzione(a, parser) + funzione(b, parser));
for (int i = 1; i < n; ++i) {
double x = a + i * h;
result += funzione(x, parser);
}
return result * h;
}
int main() {
mu::Parser parser;
// Input della funzione dall'utente
string espressione;
cout << "Inserisci la funzione in termini di x: ";
getline(cin, espressione); //getline input da tastiera di str con " "
parser.SetExpr(espressione); //input con parser
// Input dell'intervallo di integrazione [a, b] e del numero di trapezi n
double a, b;
int n;
cout << "Inserisci l'estremo inferiore a: ";
cin >> a;
cout << "Inserisci l'estremo superiore b: ";
cin >> b;
cout << "Inserisci il numero di trapezi n: ";
cin >> n;
// Calcolo e stampa dell'area
double area = calcolaAreaTrapezi(a, b, n, parser);
cout << "L'area sottostante alla curva è: " << area << endl;
return 0;
}
replit.nix:
{ pkgs }: {
deps = [
pkgs.clang_12
pkgs.ccls
pkgs.gdb
pkgs.gnumake
pkgs.muparser
];
buildInputs = [ pkgs.muparser ];
CPPFLAGS = "-I${pkgs.muparser}/include";
LDSFLAG = "-L${pkgs.muparser}/lib";
}
can anyone help me? thx