Professional Documents
Culture Documents
Masters of Computer Application: PRACTICAL FILE-Numerical Computing (MCA407)
Masters of Computer Application: PRACTICAL FILE-Numerical Computing (MCA407)
Submitted in Partial fulfilment of the requirement for the award of the degree
INDEX
Aditya Agrawal 1894094 MCA- IV
Satyam Shivankur 1894123 MCA-IV
S.No Practical Date Page Teache
No. rSign
1. Bisection Method
2. Lagrange's Interpolation.
3. Euler Method
else
a = c;
String sign=(func(c)>=0)?"+ve":"-ve";
System.out.println(String.format("%-5s %-15s %-15s %-15s %-15s %-15s",
k,a,b,c,func(c),sign));
}
String sign=(func(c)>=0)?"+ve":"-ve";
System.out.println(String.format("%-5s %-15s %-15s %-15s %-15s %-15s",
k+1,a,b,c,func(c),sign));
//prints value of c upto 4 decimal places
System.out.printf("\nThe value of root is : %.4f",c);
System.out.println();
}
};
// Driver code
public static void main(String[] args) {
// creating an array of 4 known data points
Data f[] = {new Data(0, 2), new Data(1, 3),new Data(2, 12), new Data(5, 147)};
// Printing approximation
System.out.println("\nApproximate solution at x = "+ x + " is " + y);
}
// Driver program
public static void main(String args[]) {
Euler obj = new Euler();
// Initial Values
float x0 = 0;
float y0 = 1;
float h = 0.025f;
// Initialize result
int k=0;
double c = a;
System.out.println(String.format("%-5s %-25s %-15s %-15s %-15s %-25s %-15s %-
30s", "k","x_k","x_k+1","f(x_k)","f(x_k+1)","x_k+2","f(x_k+2)","sign"));
System.out.println();
for (int i = 0; i < MAX_ITER; i++){
// Find the point that touches x axis
c = (a * func(b) - b * func(a)) / (func(b) - func(a));
c=(double)Math.round(c*100000)/100000;
k++;
String sign=(func(c)>=0)?"+ve":"-ve";
System.out.println(String.format("%-5s %-15s %-15s %-15s %-15s %-15s %-15s
%-15s", i,a,b,func(a),func(b),c,func(c),sign));
}
String sign=(func(c)>=0)?"+ve":"-ve";
System.out.println(String.format("%-5s %-15s %-15s %-15s %-15s %-15s %-15s %-
15s", k+1,a,b,func(a),func(b),c,func(c),sign));
System.out.printf("\nThe value of root is : %.4f\n",c);
}
// Driver program
public static void main(String[] args) {
// Initial values assumed
double a = -200, b = 300;
regulaFalsi(a, b);
}
}
OUTPUT:
// Driver code
public static void main (String[] args) {
// Initial values assumed
double x0 = -20;
newtonRaphson(x0);
}
}
OUTPUT:
Aditya Agrawal 1894094 MCA- IV
Satyam Shivankur 1894123 MCA-IV
6. Secant method.
Aditya Agrawal 1894094 MCA- IV
Satyam Shivankur 1894123 MCA-IV
class Secant{
// check if x0 is root of
// equation or not
c = func(x1) * func(x0);
return y1;
}
// Driver Code
public static void main (String[] args) {
double x0 = 0, y = 1, x = 2, h = 0.2;
System.out.println("\nThe value of y at x=2 is : "+ rungeKutta(x0, y, x, h));
}
}
OUTPUT:
Aditya Agrawal 1894094 MCA- IV
Satyam Shivankur 1894123 MCA-IV
Aditya Agrawal 1894094 MCA- IV
Satyam Shivankur 1894123 MCA-IV
8. Runge Kutta method for 4th order Differential Equations.
class RK4th{
double dydx(double x, double y) {
return ((x - y) / 2);
}
9. Taylor Method.
class
Aditya Agrawal 1894094 MCA- IV
Satyam Shivankur 1894123 MCA-IV
Aditya Agrawal 1894094 MCA- IV
Satyam Shivankur 1894123 MCA-IV