Faaizcm
Faaizcm
Faaizcm
#include <iostream>
#include <vector>
// Function to perform Gauss Elimination
std::vector<double> gauss_elimination(std::vector<std::vector<double>>& A, std::vector<double>&
B) { int n = A.size();
return X;
}
int main() {
// Example system of linear equations:
// 2x + y - z = 8
// -3x - y + 2z = -11
// -2x + y + 2z = -3 std::vector<std::vector<double>> A = {{2, 1, -1},
{-3, -1, 2},
{-2, 1, 2}};
std::vector<double> B = {8, -11, -3}; std::vector<double> solution = gauss_elimination(A,
B);
Practical 12
Aim: Write a program to implement Power method-
largest Eigen value.
//Faaiz Khan //00116407223
#include <iostream>
return result;
}
// Function to find the largest eigenvalue using the Power Method double
powerMethod(vector<vector<double>>& matrix, double epsilon = 1e-6, int maxIterations
=
1000) { int n = matrix.size(); vector<double> eigenVec(n, 1); //
Initial guess for eigenvector
eigenValue = 0;
for (int j = 0; j < n; ++j) { eigenValue +=
nextEigenVec[j] * eigenVec[j];
}
return eigenValue;
}
int main() { //
Example usage
vector<vector<double>> matrix = {{4, -2, 1},
{3, 6, -4},
{2, 1, 8}};
return 0;
}
Practical 13
int main()
{
// Number of values given int n =
4; float x[] = { 45, 50, 55,
60 };
cout << "\n Value at " << value << " is "
<< sum << endl;
return 0;
}
Practical 14
Aim: Write a program to implement Backward
interpolation.
//Faaiz Khan //00116407223
int main()
{
// number of values given int n =
5;
float x[] = { 1891, 1901, 1911,
1921, 1931 };
cout << "\n Value at " << value << " is "
<< sum << endl;
return 0; }
Practical 15
Aim: Write a program to implement Divided
difference interpolation.
//Faaiz Khan //00116407223
#include <iostream>
public:
DividedDifferenceInterpolation(const std::vector<double>& x, const
std::vector<double>& y) {
x_values = x;
y_values = y;
}
std::cout << "Interpolated value at x = " << x_interpolated << " is " << y_interpolated <<
std::endl;
return 0;
}
Practical 16
Aim: Write a program to implement
Lagrange’s interpolation.
//Faaiz Khan //00116407223
#include <iostream>
public:
// Constructor
LagrangeInterpolation(vector<double> x, vector<double> y) { x_values = x;
y_values = y; n = x.size();
}
int main() {
// Sample data points vector<double> x = {1,
2, 3, 4};
vector<double> y = {5, 9, 3, 7};
// Create an instance of LagrangeInterpolation LagrangeInterpolation interpolation(x,
y);
// Test interpolation at x = 2.5
double interpolated_value = interpolation.interpolate(2.5); cout << "Interpolated value
at x = 2.5: " << interpolated_value
<< endl;
return 0;
}
Practical 17
Aim: Write a program to implement
Trapezoidal rule.
//Faaiz Khan //00116407223
#include <iostream>
#include <cmath>
#include <functional> using
namespace std;
cout << "Approximation of integral using Trapezoidal Rule: " << integral << endl;
return 0;
}
Practical 18
Aim: Write a program to implement Simpson 1/3 rule
//Faaiz Khan //00116407223
#include <iostream>
#include <cmath>
#include <functional>
using namespace std;
cout << "Approximation of integral using Simpson's 1/3 Rule: " <<
integral << endl;
return 0;
}
Practical 19
Aim : Write a program to implement Simpson 3/8 rule.
//Faaiz Khan //00116407223
#include <iostream>
#include <cmath>
#include <functional> using
namespace std;
cout << "Approximation of integral using Simpson's 3/8 Rule: " <<
integral << endl;
return 0;
}