C++ Code for Laplace Transform

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

using namespace std;

// Function to compute the Laplace Transform of a function f(t) at s
double laplaceTransform(const vector<double>& t, const vector<double>& f, double s) {
    double integral = 0.0;
    int n = t.size();

    for (int i = 0; i < n; ++i) {
        integral += f[i] * exp(-s * t[i]);
    }

    return integral;
}

int main() {
    // Sample data
    vector<double> t = {0, 1, 2, 3, 4}; // Sample time values
    vector<double> f = {1, 2, 3, 4, 5}; // Sample function values

    // Compute the Laplace Transform at s = 1.5
    double s = 1.5;
    double result = laplaceTransform(t, f, s);

    // Output the result
    cout << "Laplace Transform at s = " << s << ": " << result << endl;

    return 0;
}