0% found this document useful (0 votes)
25 views23 pages

CMFILE

The document outlines several practical C++ programming exercises focused on numerical methods for finding roots of equations and interpolation. It includes objectives, algorithms, practical code examples, outputs, applications, and viva questions related to each method such as Bisection, Newton Raphson, Secant, and Newton's Divided Difference. Each section provides a structured approach to implementing these numerical techniques and their respective applications in various fields.

Uploaded by

Kush Goyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views23 pages

CMFILE

The document outlines several practical C++ programming exercises focused on numerical methods for finding roots of equations and interpolation. It includes objectives, algorithms, practical code examples, outputs, applications, and viva questions related to each method such as Bisection, Newton Raphson, Secant, and Newton's Divided Difference. Each section provides a structured approach to implementing these numerical techniques and their respective applications in various fields.

Uploaded by

Kush Goyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Date -

06/09/2024 PRACTICAL 1
o Objective: To write a C++ program to find the root of the equation (x3 - 4x – 5) using
Bisection method.

o Algorithm:
1. Calculate approx. root for every iteration using xi = (a + b) / 2
2. Display the approx. root for every iteration.
3. Calculate f(a).f(x1)
a. If f(a).f(x1) < 0, then a = a, b = x1 (exact root lies between a and x1).
b. If f(a).f(x1) > 0, then a = x1, b = b (exact root lies between x1 and b).
4. If |x1 - x| lies within the given acceptable error, then display x1 as root.
5. If the no. of iterations exceed the no. of max. iterations, then display solution doesn’t
converge and the given max. iterations are not sufficient.

o Practical Code:
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

float f(float x) {
return (x*x*x-4*x-9);
}
void bisect(float *x, float a, float b, int *itr) {
*x = (a + b)/2 ;
++(*itr);
cout << "Iteration no. " << *itr << ", x = " << *x << endl;
}
int main() {

int itr = 0, maxitr;


float x, a, b, aerr, x1;

cout << "\nEnter the values of a, b, allowed error, maximum iterations : " << endl;
cin >> a >> b >> aerr >> maxitr;

bisect(&x1, a, b, &itr);
do {
if (f(a) * f(x) < 0) b = x;
else a = x;
bisect(&x1, a, b, &itr);
if (fabs(x1-x) <aerr) {
cout << "\nAfter " << itr << " iterations, root " << "= " << setprecision(4) << x1 << endl;
return 0;
}
x = x1;
} while (itr<maxitr);
cout << "Solution does not converge, " << itr << " iterations not sufficient" << endl;

return 1;
}

o Output:
Enter the values of a, b, allowed error, maximum iterations :
2 3 0.01 15 Iteration no. 1, x = 2.5 Iteration no. 2, x = 1.5
Iteration no. 3, x = 2.25 Iteration no. 4, x = 2.625 Iteration no.
5, x = 2.8125 Iteration no. 6, x = 2.71875 Iteration no. 7, x =
2.67188 Iteration no. 8, x = 2.69531 Iteration no. 9, x =
2.70703 Iteration no. 10, x = 2.70117

After 10 iterations, root = 2.701

o Application:
a. Used to detect short segments in video content for a digital video library.
b. Used to determine the appropriate population size.
c. Used to locate and compute periodic orbits in a molecular system.

o Viva questions:
Q1. Define transcendental equations.
A1. An equation containing polynomials, logarithmic, trigonometric, and exponential
functions is known as transcendental equation.
Q2. What is the difference b/w Algebraic and Transcendental equations?
A2. The equations of the form f(x) = 0 where f(x) is purely a polynomial in x is called
an algebraic equation. But, if f(x) involves trigonometrical, arithmetic or exponential
terms in it, then it is called transcendental equation.
Q3. Write the methods that can be used to solve transcendental equations.
A3. Methods include –

a. Bisection Method (Bolzano Method)


b. Regula Falsi Method (False position method)
c. Newton-Raphson Method
d. Secant Method

Q4. Can the methods of solving transcendental equations also solve algebraic
equations?
A4. Yes, algebraic equations can be solved using methods used to solve
transcendental equations.

Q5. What is the rate of convergence of bisection method?


A5. Linear.
Q6. Formula for finding the no. of iterations in bisection method.

A6. n ≥ [ ( log(b−a) − logϵ ) / log2 ] [ n = no. of iterations ]

Q7. Which method out of Newton Raphson and Bisection method is faster?
A7. Newton Raphson Method is faster.

Q8. Write the statement of intermediate value theorem.


A8. The intermediate value theorem states that if f(x) is a continuous function whose
domain contains the interval [a, b], then it takes on any given value between f(a) and
f(b) at some point within the interval.
This implies that, if a continuous function has values of opposite sign inside an
interval, then it has a root in that interval.

Q9. What is the meaning of root of an equation?


A9. The value which satisfies an equation is known as its root.
Q10. What is the other name of bisection method?
A10. Bolzano Method.
Date -
13/09/2024 PRACTICAL 2
o Objective: To write a C++ program to find the root of the equation (xlog10x – 1.2)
using Newton Raphson method.

o Flow Chart:

Start

Define function f(x)

Define function df(x)

Get the values of


x0, aerr, maxitr

Loop for itr = 1 to maxitr

h = f(x0) / df(x0)
x1 = x0 - h

Print itr, x1 1

End loop (itr)


is Yes
fabs(h) < aerr Print solution
Print
“Solution
Stop does not
No
converge”
xo = x1

Stop
1
o Practical Code:
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

float f(float x) {
return x*log10(x) - 1.2;
}

float df(float x) {
return log10(x) + 0.43429;
}

int main() {
int itr, maxitr;
float h, x0, x1, aerr;
cout << "Enter x0, allowed error, maximum iterations : " << endl;
cin >> x0 >> aerr >> maxitr;
cout << fixed;
for (itr=1; itr<=maxitr; itr++) {
h = f(x0)/df(x0);
x1 = x0 - h;
cout << "Iteration no. " << itr << ", x = " << x1 << endl;
if (fabs(h) < aerr) {
cout << "After no. " << itr << "iterations, root = " << x1;
return 0;
}
x0 = x1;
}
cout << "Iterations not sufficient, solution does not converge" << endl;

return 1;
}
o Output:
Enter x0, allowed error, maximum iterations :
2 0.000001 10 Iteration no. 1, x = 2.813170
Iteration no. 2, x = 2.741109 Iteration no. 3, x
= 2.740646 Iteration no. 4, x = 2.740646

After 4 iterations, root = 2.740646

o Application:
a. Solving nonlinear equations such as Kepler’s equation a + bsin x = x for constants
a and b in celestial mechanics.
b. Computing 1/√x for video games. (This is needed to rescale vectors to have length
1.)
c. Solve equations that occur in GPS calculations.
d. Inverse kinematic problems (robotics, video games animation).
Date -
20/09/2024 PRACTICAL 3
o Objective: To write a C++ program to find the root of the equation (x3 - 2x – 5) using
Secant method.

o Algorithm:
1. Start
2. Define function as f(x)
3. Input initial guesses (x0 and x1), tolerable error (e) and maximum iteration (N)
4. Initialize iteration counter i = 1.
5. If f(xo) = f(x1) then print “Mathematical error” and goto (11) otherwise goto (6)
6. Calculate x2 = x1 – ( (x1 – x0)*f(x0) / (f(x1) - f(x0)) )
7. Increment iteration counter i = i + 1
8. If i >= N then print “Not convergent” and goto (11) otherwise goto (9)
9. If |f(x2)| > e then set x0 = x1, x1 = x2 and goto (5) otherwise goto (10)
10. Print root as x2
11. Stop

Practical Code:
o
#include<iostream>
#include<iomanip>
#include<math.h>
#define f(x) x*x*x - 2*x - 5
using namespace std;

int main() {
float x0, x1, x2, f0, f1, f2, e;
int step = 1, N;
cout << setprecision(6) << fixed;
cout << "Enter first guess : ";
cin >> x0;
cout << "Enter Second guess : ";
cin >> x1;
cout << "Enter tolerable error : ";
cin >> e;
cout << "Enter maximum iteration : ";
cin >> N;
cout << endl << "******" << endl;
cout << "Secant Method" << endl;
cout << "*****"<<endl;
do
{
f0 = f(x0);
f1 = f(x1);
if(f0==f1) {
cout << "Mathematical Error.";
exit(0);
}
x2 = x1 - ((x1-x0) * f1)/(f1-f0);
f2 = f(x2);
cout<<"Iteration "<<step<<" :\t x"<<step<<" = "<<x2<<" and f(x"<<step<<") = "<<f2<<endl;

x0 = x1;
f0 = f1;
x1 = x2;
f1 = f2;
step = step+1;
if(step > N+1) {
cout << "Not Convergent.";
exit(0);
}
} while(fabs(f2) > e);
cout << endl << "Root is: " << x2;
return 0;
}

o Output:
Enter First guess : 0 Enter
Second guess : 2 Enter tolerable
error : 0.000001 Enter maximum
iterations : 10 ****** Secant
Method ***** Iteration 1 :
Iteration 2 : Iteration 3 :
Iteration 4 : Iteration 5 :
Iteration 6 :
x1 = 2.500000 and f(x1) = 5.625000
x2 = 2.075472 and f(x2) = -0.210679
x3 = 2.090798 and f(x3) = -0.041807
x4 = 2.094592 and f(x4) = 0.000454
x5 = 2.094551 and f(x5) = -0.000002
x6 = 2.094552 and f(x6) = 0.000001

Root is : 2.094552

o Application:
a. Used to solve transcendental equations.
Date -
27/09/2024 PRACTICAL 4
Objective: To write a C++ program to implement Newton’s Divided Difference
o Formula for estimating value of f(x).

o Algorithm:
1. 2.Start
3. 4. 5. 6. 7. 8.
Input the number of observations.
Input allCode:
Practical the values of x.
Input all the values of y corresponding to the given values of x.
#include<iostream>
usingCalculate
namespace the divided
std; difference table.
Put the values in “Newton’s Divided Difference Formula”.
Print the calculated value.
Stop

float proterm(int i, float value, float x[]) {


float pro = 1;
for (int j = 0; j < i; j++) {
pro = pro * (value - x[j]);
}
return pro;
}

void dividedDiffTable(float x[], float y[][10], int n) {


for (int i = 1; i < n; i++) {
for (int j = 0; j < n - i; j++) {
y[j][i] = ( y[j][i - 1] - y[j + 1][i - 1] ) / (x[j] - x[i + j] );
}
}
}

float applyFormula(float value, float x[], float y[][10], int n) {


float sum = y[0][0];
for (int i = 1; i < n; i++) {
sum = sum + (proterm(i, value, x) * y[0][i]);
}
return sum;
}

int main() {
int n;
float k, sum, y[10][10];
cout<<"Enter the no. of observations : ";
cin>>n;
float x[n];

cout<<"Enter the different values of x\n";


for(int i=0; i<n; i++) {
cin >> x[i];
}

cout<<"Enter the corresponding values of y\n";


for(int i=0; i<n; i++) {
cin >> y[i][0];
}

cout << "Enter the value of 'k' for f(k) evaluation : ";
cin >> k;

dividedDiffTable(x, y, n);

cout << "\nValue at " << k << " is "<< applyFormula(k, x, y, n) << endl;
return 0;
}

o Output:
Enter the no. of observations : 5

Enter the different values of x


5 7 11 13 17

Enter the corresponding values of y


150 392 1452 2366 5202

Enter the value of 'k' for f(k) evaluation : 9


Value at 9 is 810

o Application:
a.Used for interpolation of values and determining a polynomial using the given
points (observations).
o Viva questions:

Q1. What is interpolation?


A1. Interpolation is a type of estimation, a method of constructing (finding) new data
points based on the range of a discrete set of known data points.

Q2. What are the different types of interpolation?


A2. Equal interval interpolation and Unequal interval interpolation.

Q3. What are the methods for equal interval interpolation?


A3. Newton’s (Forward and Backward) interpolation formula, Gauss (Forward and
Backward) interpolation formula, Sterling formula, Bessel’s formula.

Q4. What are the methods for unequal interval interpolation?


A4. Newton’s divided difference formula, Lagrange’s method, Hermite’s formula.

Q5. Are finished differences symmetric?


A5. Yes, the finished differences are symmetric.
Date -
04/10/2024 PRACTICAL 5
o Objective: To write a C++ program for solving numerical integration by Trapezoidal
rule.

o Algorithm:
1. Start
2. Define function f(x)
3. Read lower limit of integration, upper limit of integration and number of sub interval
4. Calculate: step size = (upper limit - lower limit)/number of sub interval
5. Set: integration value = f(lower limit) + f(upper limit)
6. Set: i = 1
7. If i > number of sub interval then goto
8. Calculate: k = lower limit + i * h
9. Calculate: Integration value = Integration Value + 2* f(k)
10. Increment i by 1 i.e. i = i+1 and go to step 7
11. Calculate: Integration value = Integration value * step size/2
12. Display Integration value as required answer
13. Stop
Theory
o

o Practical Code:
#include<iostream>
#include<math.h>
#define f(x) 1/(1+pow(x,2))

using namespace std;


int main() {
float lower, upper, integration=0.0, stepSize, k;
int i, subInterval;
cout << "Enter lower limit of integration: ";
cin >> lower;
cout << "Enter upper limit of integration: ";
cin >> upper;
cout << "Enter number of sub intervals: ";
cin >> subInterval;
stepSize = (upper - lower)/subInterval;
integration = f(lower) + f(upper);

for(i=1; i<= subInterval-1; i++) {


k = lower + i*stepSize;
integration = integration + 2 * (f(k));
}
integration = integration * stepSize/2;
cout<< endl<<"Required value of integration is: "<< integration;

return 0;
}
Output:
o Enter lower limit of integration: 0
Enter upper limit of integration: 1
Enter number of sub intervals: 6
Required value of integration is: 0.784241

Application:
o a. Used for solving complex integration problems.
Date -
18/10/2024 PRACTICAL 6
o Objective: To write a C++ program for solving numerical integration by Simpson 1/3
rule.

o Algorithm:
1. Start
2. Define function f(x)
3. Read lower limit of integration, upper limit of integration and number of sub interval
4. Calculate: step size = (upper limit - lower limit)/number of sub interval
5. Set: integration value = f(lower limit) + f(upper limit)
6. Set: i = 1
7. If i > number of sub interval then goto
8. Calculate: k = lower limit + i * h
9. If i mod 2 =0 then Integration value = Integration Value + 2* f(k)
Otherwise Integration Value = Integration Value + 4 * f(k)
End If
10. Increment i by 1 i.e. i = i+1 and go to step 7
11. Calculate: Integration value = Integration value * step size/3
12. Display Integration value as required answer
13. Stop
Theory:
o

o Practical Code:
#include<iostream>
#include<math.h>
#define f(x) 1/(1+pow(x,2))
using namespace std;

int main() {
float lower, upper, integration=0.0, stepSize, k;
int i, subInterval;
cout<<"Enter lower limit of integration: ";
cin>>lower;
cout<<"Enter upper limit of integration: ";
cin>>upper;
cout<<"Enter number of sub intervals: ";
cin>>subInterval;
stepSize = (upper - lower)/subInterval;
integration = f(lower) + f(upper);

for(i=1; i<= subInterval-1; i++) {


k = lower + i*stepSize;
if(i%2==0) { integration = integration + 2 * f(k) ; }
else { integration = integration + 4 * f(k) ; }
}
integration = integration * stepSize/3;
cout<< endl <<"Required value of integration is: "<< integration;
return 0;
}

o Output:
Enter lower limit of integration: 0
Enter upper limit of integration: 1
Enter number of sub intervals: 6
Required value of integration is: 0.785398

Application:
o a. Used for solving complex integration problems.
Date -
25/10/2024 PRACTICAL 7
o Objective: To write a C++ program for solving numerical integration by Simpson 3/8
rule.

o Algorithm:
1. Start
2. Define function f(x)
3. Read lower limit of integration, upper limit of integration and number of sub interval
4. Calculate: step size = (upper limit - lower limit)/number of sub interval
5. Set: integration value = f(lower limit) + f(upper limit)
6. Set: i = 1
7. If i > number of sub interval then goto
8. Calculate: k = lower limit + i * h
9. If i mod 3 =0 then Integration value = Integration Value + 2* f(k)
Otherwise Integration Value = Integration Value + 3 * f(k)
End If
10. Increment i by 1 i.e. i = i+1 and go to step 7
11. Calculate: Integration value = Integration value * step size*3/8
12. Display Integration value as required answer
13. Stop
Theory:
o

o Practical Code:
#include<iostream>
#include<math.h>
#define f(x) 1/(1+pow(x,2))
using namespace std;

int main() {
float lower, upper, integration=0.0, stepSize, k;
int i, subInterval;
cout<<"Enter lower limit of integration: ";
cin>>lower;
cout<<"Enter upper limit of integration: ";
cin>>upper;
cout<<"Enter number of sub intervals: ";
cin>>subInterval;
stepSize = (upper - lower)/subInterval;
integration = f(lower) + f(upper);
for(i=1; i<= subInterval-1; i++) {
k = lower + i*stepSize;
if(i%3==0) { integration = integration + 2 * (f(k)); }
else { integration = integration + 3 * (f(k)); }
}

integration = integration * stepSize*3.0/8.0;

cout<< endl <<"Required value of integration is: "<< integration;

return 0;
}
Output:
o Enter lower limit of integration: 0
Enter upper limit of integration: 1
Enter number of sub intervals: 6
Required value of integration is: 0.785396

Application:
o a. Used for solving complex integration problems.
Date -
01/11/2024 PRACTICAL 8
Objective: To write a C++ program for finding the inverse of a system of linear
o equations using Gauss Jordan method.

o Algorithm:
1. Start
2. Read Order of Matrix (n).
3. Read Matrix (A) of Order (n).
4. Augment and Identity Matrix of Order n to Matrix A.
5. Apply Gauss Jordan Elimination on Augmented Matrix (A).
6. Perform Row Operations to Convert the Principal Diagonal to 1.
7. Display the Inverse Matrix.
8. Stop.

o Practical Code:
#include<iostream>
#include<iomanip>
#include<math.h>
#include<stdlib.h>
#define SIZE 10
using namespace std;

int main() {
float a[SIZE][SIZE], x[SIZE], ratio;
int i,j,k,n;
cout<< setprecision(3)<< fixed;
cout<<"Enter order of matrix: ";
cin>>n;
cout<<"Enter coefficients of Matrix: " << endl;
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
cout<<"a["<< i<<"]["<< j<<"]= ";
cin>>a[i][j];
}
}
cout<< endl<<"\n\nGiven Matrix is:"<< endl;
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) cout<< a[i][j]<<"\t";
cout<< endl;
}
for(i=1;i<=n;i++) {
for(j=1;j<=n;j++) {
if(i==j) a[i][j+n] = 1;
else a[i][j+n] = 0;
}
}

for(i=1;i<=n;i++) {
if(a[i][i] == 0.0) {
cout<<"Mathematical Error!";
exit(0);
}
for(j=1;j<=n;j++) {
if(i!=j) {
ratio = a[j][i]/a[i][i];
for(k=1;k<=2*n;k++) a[j][k] = a[j][k] - ratio*a[i][k];
}
}
}
for(i=1;i<=n;i++) {
for(j=n+1;j<=2*n;j++) a[i][j] = a[i][j]/a[i][i];
}
cout<< endl<<"Inverse Matrix is:"<< endl;
for(i=1;i<=n;i++) {
for(j=n+1;j<=2*n;j++) cout<< a[i][j]<<"\t";
cout<< endl;
}
return(0);
}

o Output:
Enter order of matrix: 2
Enter coefficients of Matrix:
a[1][1]= 1 a[1][2]= 2 a[2][1]=
3 a[2][2]= 4 Given Matrix is:
1.000 2.000 3.000 4.000

Inverse Matrix is:


-2.000 1.000
1.500 -0.500

o Application:
a. Used for system of linear equations.
Date -
11/10/2024 PRACTICAL 9
o Objective: To write a C++ program for finding the solution of equations using Gauss
Elimination method.

o Algorithm:
1. Start
2. Read Number of Unknowns: n
3. Read Augmented Matrix (A) of n by n+1 Size
4. Transform Augmented Matrix (A) to Upper Triangular Matrix by Row Operations.
5. Obtain Solution by Back Substitution.
6. Display Result.
7. Stop

o Practical Code:
#include<iostream>
#include<iomanip>
#include<math.h>
#include<stdlib.h>
#define SIZE 10
using namespace std;

int main() {
float a[SIZE][SIZE], x[SIZE], ratio;
int i,j,k,n;
cout<< setprecision(3)<< fixed;
cout<<"Enter number of unknowns: ";
cin>>n;
cout<<"Enter Coefficients of Augmented Matrix: "<< endl;
for(i=1;i<=n;i++) {
for(j=1;j<=n+1;j++) {
cout<<"a["<< i<<"]["<< j<<"]= ";
cin>>a[i][j];
}
}
for(i=1;i<=n-1;i++) {
if(a[i][i] == 0.0) {
cout<<"Mathematical Error!";
exit(0);
}
for(j=i+1;j<=n;j++) {
ratio = a[j][i]/a[i][i];
for(k=1;k<=n+1;k++) {
a[j][k] = a[j][k] - ratio*a[i][k];
}
}
}
x[n] = a[n][n+1]/a[n][n];
for(i=n-1;i>=1;i--) {
x[i] = a[i][n+1];
for(j=i+1;j<=n;j++) {
x[i] = x[i] - a[i][j]*x[j];
}
x[i] = x[i]/a[i][i];
}

cout<< endl<<"Solution: "<< endl;


for(i=1;i<=n;i++) {
cout<<"x["<< i<<"] = "<< x[i]<< endl;
}

return 0;
}
Output:
o
Enter number of unknowns: 3 Enter
Coefficients of Augmented Matrix: a[1]
[1]= 2 a[1][2]= -1 a[1][3]= 3 a[1][4]= 9
a[2][1]= 1 a[2][2]= 1 a[2][3]= 1 a[2][4]= 6
a[3][1]= 1 a[3][2]= -1 a[3][3]= 1 a[3][4]= 2

Solution:
x[1] = 1.000
x[2] = 2.000
x[3] = 3.000

o Application:
a. Used for solving system of linear equations.
Date -
01/11/2024 PRACTICAL 10
o Objective: To write a C++ program for solving Ordinary Differential Equations by
Runge-Kutta method.

o Algorithm:
1. Start
2. Define function f(x,y)
3. Read values of initial condition(x0 and y0), number of steps (n) and calculation point (xn)
4. Calculate step size (h) = (xn - x0)/n
5. Set i=0
6. Loop

k1 = h * f(x0, y0)
k2 = h * f(x0+h/2, y0+k1/2)
k3 = h * f(x0+h/2, y0+k2/2)
k4 = h * f(x0+h, y0+k3)

k = (k1+2*k2+2*k3+k4)/6

yn = y0 + k

i=i+1
x0 = x0 + h
y0 = yn

While i < n
7. Display yn as result
8. Stop

o Practical Code:
#include <iostream>
#include <iomanip>
#define f(x,y) (x*x+y*y)/10
using namespace std;

int main() {
float x0, y0, xn, h, yn, k1, k2, k3, k4, k;
int i, n;

cout<<"Enter Initial Condition"<< endl;


cout<<"x0 = ";
cin>> x0;
cout<<"y0 = ";
cin >> y0;
cout<<"Enter calculation point xn = ";
cin>>xn;
cout<<"Enter number of steps: ";
cin>> n;

h = (xn-x0)/n;
cout<< setw(5) ;
cout<<"\nx0\t\t\ty0\t\t\tyn\n";
cout<<"------------------------------\n";
for(i=0; i < n; i++) {
k1 = h * (f(x0, y0));
k2 = h * (f((x0+h/2), (y0+k1/2)));
k3 = h * (f((x0+h/2), (y0+k2/2)));
k4 = h * (f((x0+h), (y0+k3)));
k = (k1+2*k2+2*k3+k4)/6;
yn = y0 + k;
cout<< setw(5) ;
cout << setprecision(6);
cout<< x0<<"\t\t"<< y0<<"\t\t"<< yn<< endl;
x0 = x0+h;
y0 = yn;
}
cout<<"\nValue of y at x = "<< xn<< " is " << yn;

return 0;
}
Output:
o
Enter Initial Condition x0 = 0 y0
= 1 Enter calculation point xn =
0.4 Enter number of steps: 2

x0 y0 yn
-------------------------------------------------
0 1 1.02068
0.2 1.02068 1.04384

Value of y at x = 0.4 is 1.04384

o Application:
a. Used for solving ordinary differential equations.

You might also like