SlideShare a Scribd company logo
Object Oriented
Programming
C++
Assignments
INDEX
Sr. No. Title Date Sign Grade
1 Bisection Method
2 Regula-Falsi Method
3 Secant Method
4 Newton-Raphson Method
5 Gauss-Jordan Method
6 Gauss-Elimination Method
7 Method of Least Squares
8 Euler’s Method
9 Runge-Kutta Method
BISECTION METHOD
Program:
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
float f(float x)
{
return (x*sin(x)-1);
}
void bisect(float *x,float a,float b,int *itr)
{
*x=(a+b)/2;
++(*itr);
cout<<"Iteration No."<<setw(3)<<*itr<<"x="<<setw(7)
<<setprecision(5)<<*x<<endl;
}
int main()
{
int itr=0,maxitr;
float x,a,b,aerr,x1;
cout<<"Enter the value of a=t";
cin>>a;
cout<<"Enter the value of b=t";
cin>>b;
cout<<"Enter the Value of allowed error=t";
cin>>aerr;
cout<<"Enter the value of maximum iterations=t";
cin>>maxitr;
bisect(&x,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<<"After "<<itr<<" itrations, Our Desired root is"
<<"="<<setw(6)<<setprecision(4)<<x1<<endl;
return 0;
}
x=x1;
}
while(itr<maxitr);
cout<<"Solution does not converge"<<"iteration not sufficient"
<<endl;
return 1;
}
Output:
REGULA-FALSI METHOD
Program:
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
float f(float x)
{
return x*x*x-x-5;
}
void regula(float *x,float x0,float x1,float fx0,float fx1, int *itr)
{
*x=x0-((x1-x0)/(fx1-fx0))*fx0;
++(*itr);
cout<<"Iteration no."<<setw(3)<<*itr<<"x="<<setw(7)
<<setprecision(5)<<*x<<endl;
}
int main()
{
int itr=0,maxitr;
float x0,x1,x2,x3,aerr;
cout<<"Enter the value of x0=t";
cin>>x0;
cout<<"Enter the value of x1=t";
cin>>x1;
cout<<"Enter the value of allowed error=t";
cin>>aerr;
cout<<"Enter the value of maximum iteration=t";
cin>>maxitr;
regula(&x2,x0,x1,f(x0),f(x1),&itr);
do
{
if(f(x0)*f(x2)<0)
x1=x2;
else
x0=x2;
regula(&x3,x0,x1,f(x0),f(x1),&itr);
if(fabs(x3-x2)<aerr)
{
cout<<"After "<<itr<<" iterations,"<<"tOur desired root is="
<<setw(6)<<setprecision(4)<<x3<<endl;
return 0;
}
x2=x3;
}
while(itr<maxitr);
cout<<"Solution does not converge,"
<<"iteration not sufficient"<<endl;
return 1;
}
Output:
SECANT METHOD
Program:
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
float f(float x)
{
return x*x*x-exp(x);
}
void secant(float *x,float x0,float x1,float fx0,float fx1, int *itr)
{
*x=x1-((x1-x0)/(fx1-fx0))*fx1;
++(*itr);
cout<<"Iteration no."<<setw(3)<<*itr<<"x="<<setw(7)
<<setprecision(5)<<*x<<endl;
}
int main()
{
int itr=0,maxitr;
float x0,x1,x2,x3,aerr;
cout<<"Enter the value of x0=t";
cin>>x0;
cout<<"Enter the value of x1=t";
cin>>x1;
cout<<"Enter the value of allowed errors=t";
cin>>aerr;
cout<<"Enter the value of maximum iterations=t";
cin>>maxitr;
secant(&x2,x0,x1,f(x0),f(x1),&itr);
do
{
x0=x1;
x1=x2;
secant(&x3,x0,x1,f(x0),f(x1),&itr);
if(fabs(x3-x2)<aerr)
{
cout<<"After "<<itr<<" iterations, Our desired root is="
<<setw(6)<<setprecision(4)<<x3<<endl;
return 0;
}
x2=x3;
}
while(itr<maxitr);
cout<<"Solution does not converge,"
<<"iterations not sufficient"<<endl;
return 1;
}
Output:
NEWTON RAPHSON METHOD
Program:
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
float f(float x)
{
return cos(x)-x*x;
}
float df(float x)
{
return -sin(x)-2*x;
}
int main()
{
int itr,maxitr;
float h,x0,x1,aerr;
cout<<"Enter the value of x0=t";
cin>>x0;
cout<<"Enter the value of allowed error=t";
cin>>aerr;
cout<<"Enter the value of maximum iterations=t";
cin>>maxitr;
for(itr=1;itr<=maxitr;itr++)
{
h=f(x0)/df(x0);
x1=x0-h;
cout<<"Iteration no."<<setw(3)<<itr<<"x="<<setw(9)
<<setprecision(6)<<x1<<endl;
if(fabs(h)<aerr)
{
cout<<"After no. "<<setw(3)<<itr
<<" iterations,tOur desired root is="
<<setw(8)<<setprecision(6)<<x1;
return 0;
}
x0=x1;
}
cout<<"Iterations not sufficient,"
<<"Solution does not converge"<<endl;
return 1;
}
Output:
GAUSS-JORDAN METHOD
Program:
#include<iostream.h>
#include<iomanip.h>
#define N 3
int main()
{
float a[N][N+1],t;
int i,j,k;
cout<<"Enter the matrix elements row wise:-n";
for(i=0;i<N;i++)
{
for(j=0;j<N+1;j++)
{
cin>>a[i][j];
}
}
for(j=0;j<N;j++)
{
for(i=0;i<N;i++)
{
if(i!=j)
{
t=a[i][j]/a[j][j];
for(k=0;k<N+1;k++)
{
a[i][k]-=a[j][k]*t;
}
}
}
}
cout<<"The diagonal matrix is:- n";
for(i=0;i<N;i++)
{
for(j=0;j<N+1;j++)
{
cout<<setw(15)<<setprecision(4)<<a[i][j];
}
cout<<"n";
}
cout<<"n";
cout<<"The solution is:-n";
for(i=0;i<N;i++)
{
cout<<"x["<<i+1<<"]="<<setw(7)<<setprecision(3)
<<a[i][N]/a[i][i]<<endl;
}
return 0;
}
Output:
GAUSS ELIMINATION METHOD
Program:
#include<iostream.h>
#include<iomanip.h>
#include<math.h>
#define N 3
int main()
{
float a[N][N+1],x[N],t,s;
int i,j,k;
cout<<"Enter the matrix elements row wise:-n";
for(i=0;i<N;i++)
{
for(j=0;j<N+1;j++)
{
cin>>a[i][j];
}
}
for(j=0;j<N-1;j++)
{
for(i=j+1;i<N;i++)
{
t=a[i][j]/a[j][j];
for(k=0;k<N+1;k++)
{
a[i][k]-=a[j][k]*t;
}
}
}
cout<<"The upper triangular matrix is:- n";
for(i=0;i<N;i++)
{
for(j=0;j<N+1;j++)
{
cout<<setw(15)<<setprecision(4)<<a[i][j];
}
cout<<"n";
}
for(i=N-1;i>=0;i--)
{
s=0;
{
for(j=i+1;j<N;j++)
{
s+=a[i][j]*x[j];
}
x[i]=(a[i][N]-s)/a[i][i];
}
}
cout<<"n";
cout<<"The solution is:-n";
for(i=0;i<N;i++)
{
cout<<"x["<<i+1<<"]="<<setw(7)<<setprecision(3)<<x[i]<<endl;
}
return 0;
}
Output:
METHOD OF LEAST SQUARES
Program:
#include<iostream.h>
#include<iomanip.h>
int main()
{
float mat[3][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0}};
float t,a,b,c,x,y,xsq;
int i,j,k,n;
cout<<"Enter the no. of pairs of observed values:";
cin>>n;
mat[0][0]=n;
for(i=0;i<n;i++)
{
cout<<"Pair no.:"<<i+1<<"n";
cin>>x>>y;
xsq=x*x;
mat[0][1]+=x;
mat[0][2]+=xsq;
mat[1][2]+=x*xsq;
mat[2][2]+=xsq*xsq;
mat[0][3]+=y;
mat[1][3]+=x*y;
mat[2][3]+=xsq*y;
}
mat[1][1]=mat[0][2];
mat[2][1]=mat[1][2];
mat[1][0]=mat[0][1];
mat[2][0]=mat[1][1];
cout<<"The Matrix is:-n";
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
cout<<setw(10)<<setprecision(4)<<mat[i][j];
}
cout<<"n";
}
for(j=0;j<3;j++)
{
for(i=0;i<3;i++)
{
if(i!=j)
{
t=mat[i][j]/mat[j][j];
for(k=0;k<4;k++)
{
mat[i][k]-=mat[j][k]*t;
}
}
}
}
a=mat[0][3]/mat[0][0];
b=mat[1][3]/mat[1][1];
c=mat[2][3]/mat[2][2];
cout<<setprecision(4)
<<"a="<<setw(5)<<a<<"n"
<<"b="<<setw(5)<<b<<"n"
<<"c="<<setw(5)<<c<<"n";
return 0;
}
Output:
EULER’S METHOD
Program:
#include<iostream.h>
#include<iomanip.h>
float df(float x,float y)
{
return (y-x)/(y+x);
}
int main()
{
float x0,y0,h,x,x1,y1;
cout<<"Enter the values of x0,y0,h,x:n";
cin>>x0>>y0>>h>>x;
x1=x0;
y1=y0;
while(1)
{
if(x1>x)
{
return 0;
}
y1+=h*df(x1,y1);
x1+=h;
cout<<"when x="<<setw(3)<<setprecision(2)<<x1<<"t"
<<"y="<<setw(3)<<setprecision(4)<<y1<<"n";
}
}
Output:
RUNGE-KUTTA METHOD
Program:
#include<iostream.h>
#include<iomanip.h>
float f(float x,float y)
{
return x+y*y;
}
int main()
{
float x0,y0,h,xn,x,y,k1,k2,k3,k4,k;
cout<<"Enter the values of x0,y0,h,xn:n";
cin>>x0>>y0>>h>>xn;
x=x0;
y=y0;
while(1)
{
if(x==xn)
{
break;
}
k1=h*f(x,y);
k2=h*f(x+h/2,y+k1/2);
k3=h*f(x+h/2,y+k2/2);
k4=h*f(x+h,y+k3);
k=(k1+(k2+k3)*2+k4)/6;
x+=h;
y+=k;
cout<<"When x="<<setprecision(4)<<setw(4)<<x<<setw(8)
<<"y="<<setprecision(4)<<setw(4)<<y<<endl;
}
return 0;
}
Output:

More Related Content

What's hot (20)

PPTX
Presentation on Solution to non linear equations
Rifat Rahamatullah
 
PPTX
Newton Raphson
Nasima Akhtar
 
PDF
Ramsey number lower bounds
Smit Raj
 
PPTX
Shor’s algorithm the ppt
Mrinal Mondal
 
PPTX
Polynomials and Curve Fitting in MATLAB
Shameer Ahmed Koya
 
PPT
MATLAB : Numerical Differention and Integration
Ainul Islam
 
PPTX
Newton raphson
baxter89
 
PPTX
Applications of numerical methods
Daffodil International University
 
PPT
Newton raphson method
Bijay Mishra
 
PDF
A NEW STUDY OF TRAPEZOIDAL, SIMPSON’S1/3 AND SIMPSON’S 3/8 RULES OF NUMERICAL...
mathsjournal
 
PPTX
Secant method
Zahra Saman
 
PPTX
Secent method
ritu1806
 
PDF
Roots of Nonlinear Equations - Open Methods
Mohammad Tawfik
 
PPTX
Runge Kutta Method
ch macharaverriyya naidu
 
DOCX
Btech_II_ engineering mathematics_unit5
Rai University
 
PPTX
presentation on Euler and Modified Euler method ,and Fitting of curve
Mukuldev Khunte
 
PPT
Numerical method
Kumar Gaurav
 
PPT
Fourier series
Naveen Sihag
 
DOC
NUMERICAL METHODS MULTIPLE CHOICE QUESTIONS
naveen kumar
 
PPTX
SERIES SOLUTION OF ORDINARY DIFFERENTIALL EQUATION
Kavin Raval
 
Presentation on Solution to non linear equations
Rifat Rahamatullah
 
Newton Raphson
Nasima Akhtar
 
Ramsey number lower bounds
Smit Raj
 
Shor’s algorithm the ppt
Mrinal Mondal
 
Polynomials and Curve Fitting in MATLAB
Shameer Ahmed Koya
 
MATLAB : Numerical Differention and Integration
Ainul Islam
 
Newton raphson
baxter89
 
Applications of numerical methods
Daffodil International University
 
Newton raphson method
Bijay Mishra
 
A NEW STUDY OF TRAPEZOIDAL, SIMPSON’S1/3 AND SIMPSON’S 3/8 RULES OF NUMERICAL...
mathsjournal
 
Secant method
Zahra Saman
 
Secent method
ritu1806
 
Roots of Nonlinear Equations - Open Methods
Mohammad Tawfik
 
Runge Kutta Method
ch macharaverriyya naidu
 
Btech_II_ engineering mathematics_unit5
Rai University
 
presentation on Euler and Modified Euler method ,and Fitting of curve
Mukuldev Khunte
 
Numerical method
Kumar Gaurav
 
Fourier series
Naveen Sihag
 
NUMERICAL METHODS MULTIPLE CHOICE QUESTIONS
naveen kumar
 
SERIES SOLUTION OF ORDINARY DIFFERENTIALL EQUATION
Kavin Raval
 

Similar to Numerical Methods with Computer Programming (20)

PDF
C++ TUTORIAL 6
Farhan Ab Rahman
 
PDF
C++ TUTORIAL 9
Farhan Ab Rahman
 
PDF
Computer Oriented Numerical Methods Practical File
Harjinder Singh
 
PDF
C++ TUTORIAL 7
Farhan Ab Rahman
 
DOCX
Matlab lab manual
nmahi96
 
PPTX
Finding root of equation (numarical method)
Rajan Thakkar
 
PDF
C++ TUTORIAL 10
Farhan Ab Rahman
 
DOCX
Trabajo Scilab
alexistorres
 
DOCX
MolinaLeydi_FinalProject
Leydi Molina
 
PPTX
First part of my NYU Tandon course "Numerical and Simulation Techniques in Fi...
Edward D. Weinberger
 
DOCX
scientific computing
saurabhramteke7
 
PDF
C language numanal
aluavi
 
PDF
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
Parhamsagharchi
 
PPTX
Ee 3122 numerical methods and statistics sessional credit
Raihan Bin-Mofidul
 
PDF
1.pdf
Dhiraj Bhaskar
 
PDF
Numerical Study of Some Iterative Methods for Solving Nonlinear Equations
inventionjournals
 
PDF
Numerical methods course project report
Zeeshan Ali
 
PDF
Numerical Analysis
Mallela Niteesh Kumar Reddy
 
PPTX
Root Finding Methods in Numerical Analysis
Sufi Yasir Raza
 
C++ TUTORIAL 6
Farhan Ab Rahman
 
C++ TUTORIAL 9
Farhan Ab Rahman
 
Computer Oriented Numerical Methods Practical File
Harjinder Singh
 
C++ TUTORIAL 7
Farhan Ab Rahman
 
Matlab lab manual
nmahi96
 
Finding root of equation (numarical method)
Rajan Thakkar
 
C++ TUTORIAL 10
Farhan Ab Rahman
 
Trabajo Scilab
alexistorres
 
MolinaLeydi_FinalProject
Leydi Molina
 
First part of my NYU Tandon course "Numerical and Simulation Techniques in Fi...
Edward D. Weinberger
 
scientific computing
saurabhramteke7
 
C language numanal
aluavi
 
NUMERICAL METHODS WITH MATLAB : bisection,mueller's,newton-raphson,false poin...
Parhamsagharchi
 
Ee 3122 numerical methods and statistics sessional credit
Raihan Bin-Mofidul
 
Numerical Study of Some Iterative Methods for Solving Nonlinear Equations
inventionjournals
 
Numerical methods course project report
Zeeshan Ali
 
Numerical Analysis
Mallela Niteesh Kumar Reddy
 
Root Finding Methods in Numerical Analysis
Sufi Yasir Raza
 
Ad

More from Utsav Patel (14)

PPTX
Geometric Dimensioning and Tolerancing
Utsav Patel
 
PPTX
Energy Production from Slow Moving Water
Utsav Patel
 
PPTX
Geothermal Energy Power Plant
Utsav Patel
 
PPTX
The Himalayas Mountain Range - Breathtaking Beauty
Utsav Patel
 
PPTX
Gearless Power Transmission - Minor Project
Utsav Patel
 
PDF
Electricity Production from Slow Moving Water - Poster Presentation
Utsav Patel
 
PDF
Static and Fatigue Analysis of Pressure Vessel as per ASME Codes
Utsav Patel
 
PDF
ONGC Summer Training Report
Utsav Patel
 
PDF
Gearbox Design Data with Drawings
Utsav Patel
 
PDF
Heat and Mass Transfer Practical Manual (C Coded)
Utsav Patel
 
PDF
Design of Multi-plate clutch Report
Utsav Patel
 
PDF
Geothermal Energy Power Plant Report
Utsav Patel
 
PDF
Gearless Power Transmission - Project Report
Utsav Patel
 
PDF
Ammann Apollo India Pvt Ltd - Industrial Training Report
Utsav Patel
 
Geometric Dimensioning and Tolerancing
Utsav Patel
 
Energy Production from Slow Moving Water
Utsav Patel
 
Geothermal Energy Power Plant
Utsav Patel
 
The Himalayas Mountain Range - Breathtaking Beauty
Utsav Patel
 
Gearless Power Transmission - Minor Project
Utsav Patel
 
Electricity Production from Slow Moving Water - Poster Presentation
Utsav Patel
 
Static and Fatigue Analysis of Pressure Vessel as per ASME Codes
Utsav Patel
 
ONGC Summer Training Report
Utsav Patel
 
Gearbox Design Data with Drawings
Utsav Patel
 
Heat and Mass Transfer Practical Manual (C Coded)
Utsav Patel
 
Design of Multi-plate clutch Report
Utsav Patel
 
Geothermal Energy Power Plant Report
Utsav Patel
 
Gearless Power Transmission - Project Report
Utsav Patel
 
Ammann Apollo India Pvt Ltd - Industrial Training Report
Utsav Patel
 
Ad

Recently uploaded (20)

PDF
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
PDF
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
PDF
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
PDF
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
PPTX
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
PPTX
Precooling and Refrigerated storage.pptx
ThongamSunita
 
PPTX
Bitumen Emulsion by Dr Sangita Ex CRRI Delhi
grilcodes
 
PPTX
CST413 KTU S7 CSE Machine Learning Neural Networks and Support Vector Machine...
resming1
 
PDF
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
PPTX
Mobile database systems 20254545645.pptx
herosh1968
 
PDF
01-introduction to the ProcessDesign.pdf
StiveBrack
 
PPTX
CST413 KTU S7 CSE Machine Learning Clustering K Means Hierarchical Agglomerat...
resming1
 
PDF
How to Buy Verified CashApp Accounts IN 2025
Buy Verified CashApp Accounts
 
PDF
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
PPTX
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
 
PPTX
Work at Height training for workers .pptx
cecos12
 
PPTX
Computer network Computer network Computer network Computer network
Shrikant317689
 
PPTX
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
PDF
June 2025 Top 10 Sites -Electrical and Electronics Engineering: An Internatio...
elelijjournal653
 
PPT
FINAL plumbing code for board exam passer
MattKristopherDiaz
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
Rapid Prototyping for XR: Lecture 6 - AI for Prototyping and Research Directi...
Mark Billinghurst
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
Stability of IBR Dominated Grids - IEEE PEDG 2025 - short.pptx
ssuser307730
 
Precooling and Refrigerated storage.pptx
ThongamSunita
 
Bitumen Emulsion by Dr Sangita Ex CRRI Delhi
grilcodes
 
CST413 KTU S7 CSE Machine Learning Neural Networks and Support Vector Machine...
resming1
 
Validating a Citizen Observatories enabling Platform by completing a Citizen ...
Diego López-de-Ipiña González-de-Artaza
 
Mobile database systems 20254545645.pptx
herosh1968
 
01-introduction to the ProcessDesign.pdf
StiveBrack
 
CST413 KTU S7 CSE Machine Learning Clustering K Means Hierarchical Agglomerat...
resming1
 
How to Buy Verified CashApp Accounts IN 2025
Buy Verified CashApp Accounts
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
Bharatiya Antariksh Hackathon 2025 Idea Submission PPT.pptx
AsadShad4
 
Work at Height training for workers .pptx
cecos12
 
Computer network Computer network Computer network Computer network
Shrikant317689
 
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
June 2025 Top 10 Sites -Electrical and Electronics Engineering: An Internatio...
elelijjournal653
 
FINAL plumbing code for board exam passer
MattKristopherDiaz
 

Numerical Methods with Computer Programming