cbnst code
cbnst code
#include <iostream>
#include <iomanip>
#include <cmath>
int main() {
double x0, y0, xn, h;
int n;
// Step size
h = (xn - x0) / n;
// Euler's Method
double x = x0;
double y = y0;
cout << fixed << setprecision(6);
cout << "\nStep\tx\ty" << endl;
// Final value
cout << "\nThe value of y at x = " << xn << " is approximately " << y << endl;
return 0;
}
Output:
13. WAP to implements a simple linear curve fitting method using
the least squares approach.
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
// Function to calculate the sum of the product of corresponding elements of two vectors
double sum_of_products(const vector<double>& v1, const vector<double>& v2) {
double total = 0;
for (size_t i = 0; i < v1.size(); ++i) {
total += v1[i] * v2[i];
}
return total;
}
int main() {
int n;
cout << "Enter the number of data points: ";
cin >> n;
return 0;
}
Output: