The code is written in C++ and Mathematica.
To compile the C++ code, use the following command:
g++ -o <output_file> <input_file>.cpp
To run the compiled C++ code, use the following command:
./<output_file>
To run the Mathematica code, open the file in Mathematica and run the code.
The code in this folder is for the first set of problems. The equation to be solved is:
We first use the x=g(x) method (fixed point iteration) to solve the equation. To do that we need to simplify the equation to the form x=g(x).
or
or
We can then select a starting point and iterate the function until we reach the desired accuracy.
fixed_1.cpp
uses the first form of the equation with
fixed_2.cpp
uses the second form of the equation with
fixed_3.cpp
uses the third form of the equation with
We can then use the Newton-Raphson method to find the roots of the equation. The Newton-Raphson method uses the formula:
where
For our equation, the derivative is:
which we can plug into the formula to get
newton.cpp
uses the Newton-Raphson method to find all 3 roots of the equation. The user can select the starting point to find the desired root (requires recompilation).
We also had to solve the system of equations:
using the Newton-Raphson method.
newton_system.cpp
uses the Newton-Raphson method to find the solution to the system of equations. The starting point is
set1.nb
contains the Mathematica code for the first set of problems.
The code in this folder is for the second set of problems. The system of equations to be solved is:
gauss.cpp
uses the Gauss-Seidel method to solve the system of equations. The starting point is
We also had to find the Lagrange polynomial for the following points:
which are part of the function
In the following image, we can see the real function in red, the Lagrange polynomial in blue, and the Hermite polynomial in grey. We notice that the Hermite polynomial is a better approximation of the real function.
set2.nb
contains the Mathematica code for the second set of problems.
For the third set of problems, we had to calculate the following integral:
simpson.cpp
uses the Simpson's rule to calculate the integral. The code uses
We also had to solve the integral:
simpson2.cpp
uses the Simpson's rule to calculate the integral. The code uses
For the fourth set of problems, we had to solve the following differential equation:
where
rk2.cpp
uses the Runge-Kutta method of order 2 to solve the differential equation. The code outputs the values at RK2.txt
to be used for plotting.
rk4.cpp
uses the Runge-Kutta method of order 4 to solve the differential equation. The code outputs the values at RK4.txt
to be used for plotting.
The following images show the solutions to the differential equation using the Runge-Kutta method of order 2 and 4. With orange being the real solution and blue the approximated solution.
We also had to solve the following differential equation:
where
rk_shooting.cpp
uses the shooting method to solve the differential equation. The code uses the Runge-Kutta method of order 2 to solve the differential equation. The code outputs the values at RK2_shooting.txt
to be used for plotting. The values of y get to infinity, which is not correct, but was the intended result, to show that the method does not converge.
For the fifth set of problems, we had to solve the boundary value problem:
with the boundary conditions: $ u(x, y) = 1.0$ in all the boundaries.
liebmann.cpp
uses the Liebmann method to solve the boundary value problem. The code outputs the values at matrix.txt
to be used for plotting.
liebmann.nb
contains the Mathematica code for the Liebmann method.
The following images show the solution to the boundary value problem using the Liebmann method.
We also had to solve the wave equation:
with
lax.cpp
uses the Lax-Wendroff method to solve the wave equation. The code outputs the values at wave.txt
to be used for plotting.
The following images show the solution to the wave equation using the Lax-Wendroff method. With light blue is the wave at