SlideShare une entreprise Scribd logo
1  sur  16
Télécharger pour lire hors ligne
A Report on Computational Physics
By
Yagya Dev Bhardwaj
Int. M.Sc B.Ed Physics
4th Sem 2015IMSBPH023
Submitted to
Dr. Rakesh Kumar
Assistant Professor
Department of Physics
Central University Of Rajasthan
Contents
1 Introduction 3
2 Root Finding Method 3
2.1 Newton Raphson Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Bisection Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Integration Method 7
3.1 Trapezoidal Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Simpson’s 1/3 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Simpson’s 3/8 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4 Differentiation Method 12
4.1 Euler’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2
1 Introduction
Computational physics provides a means to solve complex numerical problems.In
itself it will not give any insight into a problem (after all, a computer is only as
intelligent as its user), but it will enable you to attack problems which otherwise
might not be solvable. A typical introductory physics problem is to calculate the
motion of a cannon ball in two dimensions. This problem is always treated
without air resistance. One of the difficulties of physics is that the moment one
goes away from such an idealized system, the task rapidly becomes rather
complicated. If we want to calculate the solution with real-world elements things
become rather difficult. A way out of this mess is to use the methods of
computational physics to solve this linear differential equation.
Physics is deeply connected to mathematics and
requires a lot of calculation skills. If one is only interested in a conceptual
understanding of the field, or an estimate of the outcome of an experiment,
simple calculus will probably suffice. We can solve the problem of a cannon ball
without air resistance or Coriolis force with very elementary math, but once we
include these effects, the solution becomes quite a bit more complicated. Physics,
being an experimental science, also requires that the measured results are
statistically significant, meaning we have to repeat an experiment several times,
necessitating the same calculation over and over again and comparing the results.
This then leads to the question of how to present your results. It is much easier
to determine the compatibility of data points from a graph, rather than to try to
compare say 1000 numbers with each other and determine whether there is a
significant deviation. Computational language have been used in physics research
for many years and there is a plethora of programs and packages on the Web
which can be used to solve different problems. In this report I trying to use as
many of these available solutions as possible and not reinvent the wheel. Some of
these packages have been written in C program. As I stated above, physics relies
heavily on graphical representations. Usually,the scientist would save the results
from some calculations into a file, which then can be read and used for display by
a graphics package like gnuplot.
2 Root Finding Method
The roots of a quadratic polynomial ax2
+ bx + c with a = 0 are given
by the formula
−b ±
√
b2 − 4ac
2a
The problem of finding the roots of a quadratic equation is a particular case of nonlinear
equations f(x) = 0. The function f(x) can be a polynomial, transcendental, or a combination
of different functions, like f(x) = exp(x)+log(x)−cos(x). In science we encounter many forms
of nonlinear equations besides the quadratic ones. As a rule, it is difficult or not feasible to
find analytic solutions. A few lines of computer code can find numerical solutions instantly.
You may already have some experience with solving nonlinear equations with a programmable
graphical calculator. In the following, let f(x) be a function of a single real variable x, and we
will look for a real root on an interval [a,b].
3
2.1 Newton Raphson Method
This method is also called Newton’s method. This method is also a chord
method in which we approximate the curve near a root, by a straight line. Let x0 be an initial
approximation to the root of f(x) = 0. Then, (x0, f0), where f0 = f(x0), is a point on the
curve. Draw the tangent to the curve . We approximate the curve in the neighborhood of the
root by the tangent to the curve at the point. The point of intersection of the tangent with
the x-axis is taken as the next approximation to the root. The process is repeated until the
required accuracy is obtained. The equation of the tangent to the curve y = f(x) at the point
(x0, f0) is given by
y − f(x0) = (x − x0)f (x0)
where f (x0) is the slope of the tangent to the curve . Setting y = 0 and solving for x, we get
x = x0 −
f(x0)
f (x0)
, f (x0) = 0
The next approximation to the root is given by
x1 = x0 −
f(x0)
f (x0)
, f (x0) = 0
We repeat the procedure. The iteration method is defined as
xn+1 = xn −
f(xn)
f (xn)
, f (n0) = 0
This method is called the Newton-Raphson method or simply the Newton’s method. The
method is also called the tangent method.
PROGRAMMING CODE
#include<stdio.h>
#include<math.h>
float f(float x)
4
{
return x*log10(x) - 1.2;
}
float df (float x)
{
return log10(x) + 0.43429;
}
int main()
{
int i, max;
float h, x0, x1, error;
printf("nEnter x0, allowed error and maximum iterationsn");
scanf("%f %f %d", &x0, &error, &max);
for (i=1; i<=max; i++)
{
h=f(x0)/df(x0);
x1=x0-h;
printf(" At Iteration no. %3d, x = %9.6fn", i, x1);
if (fabs(h) < error)
{
printf("After %3d iterations, root = %8.6fn", i, x1);
return 0;
}
x0=x1;
}
printf(" The required solution does not converge or iterations are insufficientn");
return 1;
}
2.2 Bisection Method
The Bisection method is the simplest but most robust method. This
method never fails. Let f(x) be a continuous function on [a b] that changes sign between x
= a and x = b, i.e. f(a)f(b) < 0. In this case there is at least one real root on the interval
[a ,b]. The bisectional procedure begins with dividing the initial interval [a b] into two equal
intervals with the middle point at x1 = (a − b)/2 There are three possible cases for the product
of f(a)f(x1)
f(a)f(x1) =



< 0 there is a root[a, x1];
> 0 there is a root[x1, b];
= 0 then x1 is a root.
We can repeat the bisectional procedure for a new interval where the function f(x) has a root.
On each bisectional step we reduce by two the interval where the solution occurs. After n steps
the original interval will be reduced to the interval(b − a)/2n
. The bisectional procedure is
repeated until (b − a)/2n
is less than the given tolerance.
5
PROGRAMMING CODE FOR BISECTION METHOD
#include<stdio.h>
float fn(float);
void main()
{
float a,b,c;
int i;
printf("enter the initial root valuesn");
scanf("%ft%f",&a,&b);
if(fn(a)*fn(b)<0)
{
for(i=0;i<=20;i++)
{
c=(a+b)/2;
if(fn(c)==0)
{
printf("the root is=%f",c);
break;
}
else
{
if(fn(a)*fn(c)<0)
b=c;
else
a=c;
}
printf("%fn",c);
}
}
else
6
printf("the interval vales are incorrect");
}
float fn(float x)
{
float f;
f=(x*x)-1;
return f;
}
3 Integration Method
The need often arises for evaluating the definite integral of a function
that has no explicit antiderivative or whose antiderivative is not easy to obtain. The basic
method involved in approximating
b
a
f(x) dx.
is called numerical quadrature. It uses a sum n
i=1 aif(xi) to approximate
b
a
f(x) dx.
3.1 Trapezoidal Method
This rule is also called the trapezoidal rule. Let the curve y = f(x), a x
b, be approximated by the line joining the points (a, f(a)), (b, f(b)) on the curve. Using the
Newton’s forward difference formula, the linear polynomial approximation to f(x)
7
interpolating at the points (a, f(a)), (b, f(b)), is given by
f(x) = f(x0) +
1
h
f(x0), f (x0) = 0
I =
b
a
f(x), dx.
x0+nh
x0
f(x)dx=h
2
[(y0 + yn) + 2(y1 + y2 + ......... + yn−2)]
PROGRAMMING CODE FOR
I =
b
a
x2
dx.
#include<stdio.h>
float fn(float);
void main()
{
float a,b,n,r,t,h,s=0;
int i;
printf("enter the value of limitsn");
printf("enter the lower limit a=n");
scanf("%f",&b);
printf("enter the upper limit b=n");
scanf("%f",&b);
printf("number of steps n=n");
scanf("%f",&n);
h=(b-a)/n;
for(i=1;i<=(n-1);i++)
{
fn(a+i*h);
t=fn(a+(i*h));
s=s+t;
printf("%fn",t);
}
r=(h/2)*(fn(a)+(2*s)+fn(b));
printf("%ft%ft%ft%fn",h,fn(a),fn(b),s);
printf("result of integration is=%fn",r);
}
float fn(float x)
{
float f;
f=(x*x);
return f;
}
3.2 Simpson’s 1/3 Method
The trapezoidal rule was based on approximating the integrand by a first
order polynomial, and then integrating the polynomial over interval of integration.
8
Simpson’s 1/3 rule is an extension of Trapezoidal rule where the integrand
is approximated by a second order polynomial Just like in multiple-segment trapezoidal rule,
one can subdivide the interval [a,b] into n segments and apply Simpson’s 1/3 rule repeatedly
over every two segments. Divide interval [a,b] into n equal segments, so that the segment width
is given by General form for the integration using this method is as followed
x0+nh
x0
f(x)dx=h
3
[(y0 + yn) + 4(y1 + y3 + ....... + yn−1 + 2(y2 + y4 + ..... + yn−2)]
PROGRAMMING CODE
#include<stdio.h>
#include<math.h>
int main()
{
float x[10],y[10],sum=0,h,temp;
int i,n,j,k=0;
float fact(int);
printf("nhow many record you will be enter: ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("nnenter the value of x%d: ",i);
scanf("%f",&x[i]);
printf("nnenter the value of f(x%d): ",i);
scanf("%f",&y[i]);
}
h=x[1]-x[0];
n=n-1;
sum = sum + y[0];
for(i=1;i<n;i++)
{
if(k==0)
{
sum = sum + 4 * y[i];
k=1;
}
9
else
{
sum = sum + 2 * y[i];
k=0;
}
}
sum = sum + y[i];
sum = sum * (h/3);
printf("nn I = %f ",sum);
}
3.3 Simpson’s 3/8 Method
The Approximate Int(f(x), x = a..b, method = simpson[3/8], opts) com-
mand approximates the integral of f(x) from a to b by using Simpson’s 3/8 rule. This rule is
also known as Newton’s 3/8 rule. The first two arguments (function expression and range) can
be replaced by a definite integral.
x0+nh
x0
f(x)dx=3h
8
[(y0 + yn) + 3(y1 + y2 + y4 + y5 + .... + yn−1) + 2(y3 + y6 + ....yn−3)]
While using this method the number of sub intervals should be taken as multiple of 3.
PROGRAMMING CODE FOR
I =
b
a
e−x2
dx.
#include<stdio.h>
#include<math.h>
float fn(float);
int main()
{
int i,n;
float sum1,sum2,sum3,I,h,b,a,y[100],x[100];
printf("write the value of nn");
scanf("%d",&n);
10
printf("enter the value of b or upper limitn");
scanf("%f",&b);
printf("enter the value of a or lower limitn");
scanf("%f",&a);
h= (b-a)/n ;
x[0]=a;
y[0]=F(x[0]);
x[n]=b;
y[n]=F(x[n]);
printf("x t f(x)n");
printf("%f t %fn",x[0],y[0]);
for(i=1;i<n;i++)
{
x[i]= x[i-1]+ h;
y[i]= F(x[i]);
printf("%f t %fn n",x[i],y[i]);
}
printf("%f t %fn",x[n],y[n]);
sum1=0;
for(i=1;i<n;i=i+3)
{
sum1 = sum1 +3*y[i];
}
sum2=0;
for(i=2;i<n;i=i+3)
{
sum2 = sum2 +3*y[i];
}
sum3=0;
for(i=3;i<n;i=i+3)
{
sum3 = sum2 + 2*y[i];
}
I= ((3*h)*(y[n]+y[0]+sum1+sum2+sum3))/8 ;
printf("value of integration of given by = %f",I);
}
float fn(float x)
{
float f;
f= exp(-(x*x));
return f;
}
Question-Evaluate
6
0
1
1+x2 dx by using
1. Trapezoidal Rule,
2. Simpson 1/3 Rule,
11
3.Simpson 3/8 Rule
solution Divide the interval (0,6)into six parts each of width h=1.The values of f(x) = 1
1+x2
are given below
x f(x)
0 1
1 0.5
2 0.2
3 0.1
4 0.0588
5 0.0385
6 0.027
1. By Trapezoidal rule,
6
0
1
1+x2 dx = h
2
[(y0 + y6) + 2(y1 + y2 + y3 + y4 + y5]
=6
2
[(1 + 0.027) + 2(0.5 + 0.2 + 0.1 + 0.0588 + 0.0385)]
=1.4108
2. By Simpson 1/3 Rule
6
0
1
1+x2 dx = h
3
[(y0 + y6) + 4(y1 + y3 + y5) + 2(y2 + y4)]
=6
3
[(1 + 0.027) + 4(0.5 + 0.1 + 0.0385) + 2(0.2 + 0.0588)]
=1.3662
3.By Simpson 3/8 Rule
6
0
1
1+x2 dx = 3h
8
[(y0 + y6) + 3(y1 + y2 + y4 + y5) + 2y3]
=3
8
[(1 + 0.027) + 3(0.5 + 0.2 + 0.0588 + 0.0385) + 2(0.1)]
=1.3571
4 Differentiation Method
Numerical differentiation deals with the following problem:we are given
the function y = f(x) and wish to obtain one of its derivatives at the point x = xk. The
term“given” means that we either have an algorithm for computing the function, or possess a
set of discrete data points (xi , yi ), i = 0, 1, . . . , n. In either case, we have access to a finite
number of (x, y) data pairs from which to compute the derivative. Numerical differentiation is
related to interpolation,means of finding the derivative is to approximate the function locally
by a polynomial and then differentiate it.
An equally effective tool is the Taylor series expansion of f(x) about the point
xk, which has the advantage of providing us with information about the error involved in the
approximation. Numerical differentiation is not a particularly accurate process.
The derivative of the function f at x0 is
f (x0) = lim
h→0
f(x0 + h) − f(x0)
h
12
This formula gives an obvious way to generate an approximation to f(x0); simply compute
f(x0 + h) − f(x0)
h
for small values of h.
4.1 Euler’s Method
In mathematics and computational science, the Euler method is a first-
order numerical procedure for solving ordinary differential equations (ODEs) with a given initial
value. It is the most basic explicit method for numerical integration of ordinary differential
equations.
This can be described as a technique of developing a piecewise linear approximation to the
solution.In the initial value problem .the starting point of the solution curve and the slope of
the curve at the starting point are given.With this information the method extrapolates the
solution curve using the specified step size.
Example’s:-
1. Simple Harmonic Motion
Equation of motion are:
d2
x
dt2
= −kx (1)
y =
dx
dt
(2)
dy
dt
= −kx (3)
PROGRAMMING CODE
#include<stdio.h>
void main()
{
float x0,y0,h,k,x,y,i;
x0=0.1; //intialisation
y0=0.2;
h=0.001;
k=1;
FILE*fp;
fp=fopen("SHM.dat","w");
for(i=0;i<=50000;i++)
{
x=x0+h*y0;
y=y0+h*(-k)*x0;
x0=x;
y0=y;
13
fprintf(fp,"%ft%ft%fn",i,x,y);
}
fclose(fp);
}
-0.25
-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
0.25
-0.25 -0.2 -0.15 -0.1 -0.05 0 0.05 0.1 0.15 0.2 0.25
y
x
"SHM.dat" us 2:3
2. The Lorenz Attractor
Equation’s of Motion are:-
dx
dt
= σ(y − x) (4)
dy
dt
= (r − z)(x − y) (5)
dz
dt
= (xy − bz) (6)
PROGRAMMING CODE
#include<stdio.h>
void main()
{
float x0,y0,z0,h,x,y,z,r,a,b,i;
x0=0.02; //intialisation
14
y0=0.3;
z0=0.2;
h=0.01;
a=10;
b=2.66;
r=28;
FILE*fp;
fp=fopen("lorenz.dat","wS");
for(i=0;i<=10000;i++)
{
x=x0+h*(a*(y0-x0));
y=y0+h*((r-z0)*x0-y0);
z=z0+h*(x0*y0-b*z0);
x0=x;
y0=y;
z0=z;
fprintf(fp,"%ft%ft%ft%fn",i,x,y,z);
}
fclose(fp);
}
15
-20 -15 -10 -5 0 5 10 15 20 25-30
-20
-10
0
10
20
30
0
10
20
30
40
50
60
z
lorenz attractor
"lorenz.dat" us 2:3:4
x
y
z
16

Contenu connexe

Tendances

Chapter 2 solving nonlinear equations
Chapter 2 solving nonlinear equationsChapter 2 solving nonlinear equations
Chapter 2 solving nonlinear equationsssuser53ee01
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration methodshashikant pabari
 
Applications of numerical methods
Applications of numerical methodsApplications of numerical methods
Applications of numerical methodsTarun Gehlot
 
Ch2 probability and random variables pg 81
Ch2 probability and random variables pg 81Ch2 probability and random variables pg 81
Ch2 probability and random variables pg 81Prateek Omer
 
Regulafalsi_bydinesh
Regulafalsi_bydineshRegulafalsi_bydinesh
Regulafalsi_bydineshDinesh Kumar
 
Double Robustness: Theory and Applications with Missing Data
Double Robustness: Theory and Applications with Missing DataDouble Robustness: Theory and Applications with Missing Data
Double Robustness: Theory and Applications with Missing DataLu Mao
 
Iteration method-Solution of algebraic and Transcendental Equations.
Iteration method-Solution of algebraic and Transcendental Equations.Iteration method-Solution of algebraic and Transcendental Equations.
Iteration method-Solution of algebraic and Transcendental Equations.AmitKumar8151
 
Numerical solutions of algebraic equations
Numerical solutions of algebraic equationsNumerical solutions of algebraic equations
Numerical solutions of algebraic equationsAvneet Singh Lal
 
Numerical
NumericalNumerical
Numerical1821986
 

Tendances (19)

probability assignment help (2)
probability assignment help (2)probability assignment help (2)
probability assignment help (2)
 
Statistics Assignment Help
Statistics Assignment HelpStatistics Assignment Help
Statistics Assignment Help
 
Diffusion Homework Help
Diffusion Homework HelpDiffusion Homework Help
Diffusion Homework Help
 
Chapter 2 solving nonlinear equations
Chapter 2 solving nonlinear equationsChapter 2 solving nonlinear equations
Chapter 2 solving nonlinear equations
 
Newton cotes integration method
Newton cotes integration  methodNewton cotes integration  method
Newton cotes integration method
 
1 6
1 61 6
1 6
 
Mechanical Engineering Assignment Help
Mechanical Engineering Assignment HelpMechanical Engineering Assignment Help
Mechanical Engineering Assignment Help
 
Applications of numerical methods
Applications of numerical methodsApplications of numerical methods
Applications of numerical methods
 
Ch2 probability and random variables pg 81
Ch2 probability and random variables pg 81Ch2 probability and random variables pg 81
Ch2 probability and random variables pg 81
 
Regulafalsi_bydinesh
Regulafalsi_bydineshRegulafalsi_bydinesh
Regulafalsi_bydinesh
 
Double Robustness: Theory and Applications with Missing Data
Double Robustness: Theory and Applications with Missing DataDouble Robustness: Theory and Applications with Missing Data
Double Robustness: Theory and Applications with Missing Data
 
Numerical method
Numerical methodNumerical method
Numerical method
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
Iteration method-Solution of algebraic and Transcendental Equations.
Iteration method-Solution of algebraic and Transcendental Equations.Iteration method-Solution of algebraic and Transcendental Equations.
Iteration method-Solution of algebraic and Transcendental Equations.
 
Numerical solutions of algebraic equations
Numerical solutions of algebraic equationsNumerical solutions of algebraic equations
Numerical solutions of algebraic equations
 
Numerical
NumericalNumerical
Numerical
 
OPERATIONS RESEARCH
OPERATIONS RESEARCHOPERATIONS RESEARCH
OPERATIONS RESEARCH
 
Signal Processing Homework Help
Signal Processing Homework HelpSignal Processing Homework Help
Signal Processing Homework Help
 
Digital Signal Processing Assignment Help
Digital Signal Processing Assignment HelpDigital Signal Processing Assignment Help
Digital Signal Processing Assignment Help
 

Similaire à Numerical differentation with c

Numerical Study of Some Iterative Methods for Solving Nonlinear Equations
Numerical Study of Some Iterative Methods for Solving Nonlinear EquationsNumerical Study of Some Iterative Methods for Solving Nonlinear Equations
Numerical Study of Some Iterative Methods for Solving Nonlinear Equationsinventionjournals
 
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...Stephen Faucher
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuacionesNatalia
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuacionesNatalia
 
Newton raphson method
Newton raphson methodNewton raphson method
Newton raphson methodBijay Mishra
 
Non linearequationsmatlab
Non linearequationsmatlabNon linearequationsmatlab
Non linearequationsmatlabsheetslibrary
 
Solution of non-linear equations
Solution of non-linear equationsSolution of non-linear equations
Solution of non-linear equationsZunAib Ali
 
Non linearequationsmatlab
Non linearequationsmatlabNon linearequationsmatlab
Non linearequationsmatlabZunAib Ali
 
HOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptxHOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptxSayedulHassan1
 
Introduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdfIntroduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdfJifarRaya
 
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)Minhas Kamal
 
HOME ASSIGNMENT omar ali.pptx
HOME ASSIGNMENT omar ali.pptxHOME ASSIGNMENT omar ali.pptx
HOME ASSIGNMENT omar ali.pptxSayedulHassan1
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus AhsanIrshad8
 
B02110105012
B02110105012B02110105012
B02110105012theijes
 
The International Journal of Engineering and Science (The IJES)
 The International Journal of Engineering and Science (The IJES) The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)theijes
 
Roots of equations
Roots of equationsRoots of equations
Roots of equationsMileacre
 

Similaire à Numerical differentation with c (20)

Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Numerical Study of Some Iterative Methods for Solving Nonlinear Equations
Numerical Study of Some Iterative Methods for Solving Nonlinear EquationsNumerical Study of Some Iterative Methods for Solving Nonlinear Equations
Numerical Study of Some Iterative Methods for Solving Nonlinear Equations
 
Lecture6
Lecture6Lecture6
Lecture6
 
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...
A Comparison Of Iterative Methods For The Solution Of Non-Linear Systems Of E...
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuaciones
 
Raices de ecuaciones
Raices de ecuacionesRaices de ecuaciones
Raices de ecuaciones
 
Newton raphson method
Newton raphson methodNewton raphson method
Newton raphson method
 
Secant method
Secant methodSecant method
Secant method
 
Non linearequationsmatlab
Non linearequationsmatlabNon linearequationsmatlab
Non linearequationsmatlab
 
Solution of non-linear equations
Solution of non-linear equationsSolution of non-linear equations
Solution of non-linear equations
 
Non linearequationsmatlab
Non linearequationsmatlabNon linearequationsmatlab
Non linearequationsmatlab
 
HOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptxHOME ASSIGNMENT (0).pptx
HOME ASSIGNMENT (0).pptx
 
Introduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdfIntroduction to comp.physics ch 3.pdf
Introduction to comp.physics ch 3.pdf
 
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
Numerical Method Analysis: Algebraic and Transcendental Equations (Non-Linear)
 
HOME ASSIGNMENT omar ali.pptx
HOME ASSIGNMENT omar ali.pptxHOME ASSIGNMENT omar ali.pptx
HOME ASSIGNMENT omar ali.pptx
 
The Fundamental theorem of calculus
The Fundamental theorem of calculus The Fundamental theorem of calculus
The Fundamental theorem of calculus
 
B02110105012
B02110105012B02110105012
B02110105012
 
The International Journal of Engineering and Science (The IJES)
 The International Journal of Engineering and Science (The IJES) The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)
 
Roots of equations
Roots of equationsRoots of equations
Roots of equations
 
Bisection method
Bisection methodBisection method
Bisection method
 

Dernier

Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfSumit Kumar yadav
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfrohankumarsinghrore1
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfmuntazimhurra
 
Green chemistry and Sustainable development.pptx
Green chemistry  and Sustainable development.pptxGreen chemistry  and Sustainable development.pptx
Green chemistry and Sustainable development.pptxRajatChauhan518211
 
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxRizalinePalanog2
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
Creating and Analyzing Definitive Screening Designs
Creating and Analyzing Definitive Screening DesignsCreating and Analyzing Definitive Screening Designs
Creating and Analyzing Definitive Screening DesignsNurulAfiqah307317
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)Areesha Ahmad
 
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Monika Rani
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPirithiRaju
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencySheetal Arora
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptxAlMamun560346
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPirithiRaju
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfSumit Kumar yadav
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksSérgio Sacani
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Lokesh Kothari
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...ssifa0344
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bSérgio Sacani
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...chandars293
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)Areesha Ahmad
 

Dernier (20)

Botany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdfBotany 4th semester file By Sumit Kumar yadav.pdf
Botany 4th semester file By Sumit Kumar yadav.pdf
 
Forensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdfForensic Biology & Its biological significance.pdf
Forensic Biology & Its biological significance.pdf
 
Biological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdfBiological Classification BioHack (3).pdf
Biological Classification BioHack (3).pdf
 
Green chemistry and Sustainable development.pptx
Green chemistry  and Sustainable development.pptxGreen chemistry  and Sustainable development.pptx
Green chemistry and Sustainable development.pptx
 
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Creating and Analyzing Definitive Screening Designs
Creating and Analyzing Definitive Screening DesignsCreating and Analyzing Definitive Screening Designs
Creating and Analyzing Definitive Screening Designs
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls AgencyHire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
Hire 💕 9907093804 Hooghly Call Girls Service Call Girls Agency
 
Seismic Method Estimate velocity from seismic data.pptx
Seismic Method Estimate velocity from seismic  data.pptxSeismic Method Estimate velocity from seismic  data.pptx
Seismic Method Estimate velocity from seismic data.pptx
 
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdfPests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
Pests of cotton_Borer_Pests_Binomics_Dr.UPR.pdf
 
Zoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdfZoology 4th semester series (krishna).pdf
Zoology 4th semester series (krishna).pdf
 
Formation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disksFormation of low mass protostars and their circumstellar disks
Formation of low mass protostars and their circumstellar disks
 
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
Labelling Requirements and Label Claims for Dietary Supplements and Recommend...
 
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
TEST BANK For Radiologic Science for Technologists, 12th Edition by Stewart C...
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
High Class Escorts in Hyderabad ₹7.5k Pick Up & Drop With Cash Payment 969456...
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 

Numerical differentation with c

  • 1. A Report on Computational Physics By Yagya Dev Bhardwaj Int. M.Sc B.Ed Physics 4th Sem 2015IMSBPH023 Submitted to Dr. Rakesh Kumar Assistant Professor Department of Physics Central University Of Rajasthan
  • 2. Contents 1 Introduction 3 2 Root Finding Method 3 2.1 Newton Raphson Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2.2 Bisection Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3 Integration Method 7 3.1 Trapezoidal Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 Simpson’s 1/3 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.3 Simpson’s 3/8 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4 Differentiation Method 12 4.1 Euler’s Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 2
  • 3. 1 Introduction Computational physics provides a means to solve complex numerical problems.In itself it will not give any insight into a problem (after all, a computer is only as intelligent as its user), but it will enable you to attack problems which otherwise might not be solvable. A typical introductory physics problem is to calculate the motion of a cannon ball in two dimensions. This problem is always treated without air resistance. One of the difficulties of physics is that the moment one goes away from such an idealized system, the task rapidly becomes rather complicated. If we want to calculate the solution with real-world elements things become rather difficult. A way out of this mess is to use the methods of computational physics to solve this linear differential equation. Physics is deeply connected to mathematics and requires a lot of calculation skills. If one is only interested in a conceptual understanding of the field, or an estimate of the outcome of an experiment, simple calculus will probably suffice. We can solve the problem of a cannon ball without air resistance or Coriolis force with very elementary math, but once we include these effects, the solution becomes quite a bit more complicated. Physics, being an experimental science, also requires that the measured results are statistically significant, meaning we have to repeat an experiment several times, necessitating the same calculation over and over again and comparing the results. This then leads to the question of how to present your results. It is much easier to determine the compatibility of data points from a graph, rather than to try to compare say 1000 numbers with each other and determine whether there is a significant deviation. Computational language have been used in physics research for many years and there is a plethora of programs and packages on the Web which can be used to solve different problems. In this report I trying to use as many of these available solutions as possible and not reinvent the wheel. Some of these packages have been written in C program. As I stated above, physics relies heavily on graphical representations. Usually,the scientist would save the results from some calculations into a file, which then can be read and used for display by a graphics package like gnuplot. 2 Root Finding Method The roots of a quadratic polynomial ax2 + bx + c with a = 0 are given by the formula −b ± √ b2 − 4ac 2a The problem of finding the roots of a quadratic equation is a particular case of nonlinear equations f(x) = 0. The function f(x) can be a polynomial, transcendental, or a combination of different functions, like f(x) = exp(x)+log(x)−cos(x). In science we encounter many forms of nonlinear equations besides the quadratic ones. As a rule, it is difficult or not feasible to find analytic solutions. A few lines of computer code can find numerical solutions instantly. You may already have some experience with solving nonlinear equations with a programmable graphical calculator. In the following, let f(x) be a function of a single real variable x, and we will look for a real root on an interval [a,b]. 3
  • 4. 2.1 Newton Raphson Method This method is also called Newton’s method. This method is also a chord method in which we approximate the curve near a root, by a straight line. Let x0 be an initial approximation to the root of f(x) = 0. Then, (x0, f0), where f0 = f(x0), is a point on the curve. Draw the tangent to the curve . We approximate the curve in the neighborhood of the root by the tangent to the curve at the point. The point of intersection of the tangent with the x-axis is taken as the next approximation to the root. The process is repeated until the required accuracy is obtained. The equation of the tangent to the curve y = f(x) at the point (x0, f0) is given by y − f(x0) = (x − x0)f (x0) where f (x0) is the slope of the tangent to the curve . Setting y = 0 and solving for x, we get x = x0 − f(x0) f (x0) , f (x0) = 0 The next approximation to the root is given by x1 = x0 − f(x0) f (x0) , f (x0) = 0 We repeat the procedure. The iteration method is defined as xn+1 = xn − f(xn) f (xn) , f (n0) = 0 This method is called the Newton-Raphson method or simply the Newton’s method. The method is also called the tangent method. PROGRAMMING CODE #include<stdio.h> #include<math.h> float f(float x) 4
  • 5. { return x*log10(x) - 1.2; } float df (float x) { return log10(x) + 0.43429; } int main() { int i, max; float h, x0, x1, error; printf("nEnter x0, allowed error and maximum iterationsn"); scanf("%f %f %d", &x0, &error, &max); for (i=1; i<=max; i++) { h=f(x0)/df(x0); x1=x0-h; printf(" At Iteration no. %3d, x = %9.6fn", i, x1); if (fabs(h) < error) { printf("After %3d iterations, root = %8.6fn", i, x1); return 0; } x0=x1; } printf(" The required solution does not converge or iterations are insufficientn"); return 1; } 2.2 Bisection Method The Bisection method is the simplest but most robust method. This method never fails. Let f(x) be a continuous function on [a b] that changes sign between x = a and x = b, i.e. f(a)f(b) < 0. In this case there is at least one real root on the interval [a ,b]. The bisectional procedure begins with dividing the initial interval [a b] into two equal intervals with the middle point at x1 = (a − b)/2 There are three possible cases for the product of f(a)f(x1) f(a)f(x1) =    < 0 there is a root[a, x1]; > 0 there is a root[x1, b]; = 0 then x1 is a root. We can repeat the bisectional procedure for a new interval where the function f(x) has a root. On each bisectional step we reduce by two the interval where the solution occurs. After n steps the original interval will be reduced to the interval(b − a)/2n . The bisectional procedure is repeated until (b − a)/2n is less than the given tolerance. 5
  • 6. PROGRAMMING CODE FOR BISECTION METHOD #include<stdio.h> float fn(float); void main() { float a,b,c; int i; printf("enter the initial root valuesn"); scanf("%ft%f",&a,&b); if(fn(a)*fn(b)<0) { for(i=0;i<=20;i++) { c=(a+b)/2; if(fn(c)==0) { printf("the root is=%f",c); break; } else { if(fn(a)*fn(c)<0) b=c; else a=c; } printf("%fn",c); } } else 6
  • 7. printf("the interval vales are incorrect"); } float fn(float x) { float f; f=(x*x)-1; return f; } 3 Integration Method The need often arises for evaluating the definite integral of a function that has no explicit antiderivative or whose antiderivative is not easy to obtain. The basic method involved in approximating b a f(x) dx. is called numerical quadrature. It uses a sum n i=1 aif(xi) to approximate b a f(x) dx. 3.1 Trapezoidal Method This rule is also called the trapezoidal rule. Let the curve y = f(x), a x b, be approximated by the line joining the points (a, f(a)), (b, f(b)) on the curve. Using the Newton’s forward difference formula, the linear polynomial approximation to f(x) 7
  • 8. interpolating at the points (a, f(a)), (b, f(b)), is given by f(x) = f(x0) + 1 h f(x0), f (x0) = 0 I = b a f(x), dx. x0+nh x0 f(x)dx=h 2 [(y0 + yn) + 2(y1 + y2 + ......... + yn−2)] PROGRAMMING CODE FOR I = b a x2 dx. #include<stdio.h> float fn(float); void main() { float a,b,n,r,t,h,s=0; int i; printf("enter the value of limitsn"); printf("enter the lower limit a=n"); scanf("%f",&b); printf("enter the upper limit b=n"); scanf("%f",&b); printf("number of steps n=n"); scanf("%f",&n); h=(b-a)/n; for(i=1;i<=(n-1);i++) { fn(a+i*h); t=fn(a+(i*h)); s=s+t; printf("%fn",t); } r=(h/2)*(fn(a)+(2*s)+fn(b)); printf("%ft%ft%ft%fn",h,fn(a),fn(b),s); printf("result of integration is=%fn",r); } float fn(float x) { float f; f=(x*x); return f; } 3.2 Simpson’s 1/3 Method The trapezoidal rule was based on approximating the integrand by a first order polynomial, and then integrating the polynomial over interval of integration. 8
  • 9. Simpson’s 1/3 rule is an extension of Trapezoidal rule where the integrand is approximated by a second order polynomial Just like in multiple-segment trapezoidal rule, one can subdivide the interval [a,b] into n segments and apply Simpson’s 1/3 rule repeatedly over every two segments. Divide interval [a,b] into n equal segments, so that the segment width is given by General form for the integration using this method is as followed x0+nh x0 f(x)dx=h 3 [(y0 + yn) + 4(y1 + y3 + ....... + yn−1 + 2(y2 + y4 + ..... + yn−2)] PROGRAMMING CODE #include<stdio.h> #include<math.h> int main() { float x[10],y[10],sum=0,h,temp; int i,n,j,k=0; float fact(int); printf("nhow many record you will be enter: "); scanf("%d",&n); for(i=0; i<n; i++) { printf("nnenter the value of x%d: ",i); scanf("%f",&x[i]); printf("nnenter the value of f(x%d): ",i); scanf("%f",&y[i]); } h=x[1]-x[0]; n=n-1; sum = sum + y[0]; for(i=1;i<n;i++) { if(k==0) { sum = sum + 4 * y[i]; k=1; } 9
  • 10. else { sum = sum + 2 * y[i]; k=0; } } sum = sum + y[i]; sum = sum * (h/3); printf("nn I = %f ",sum); } 3.3 Simpson’s 3/8 Method The Approximate Int(f(x), x = a..b, method = simpson[3/8], opts) com- mand approximates the integral of f(x) from a to b by using Simpson’s 3/8 rule. This rule is also known as Newton’s 3/8 rule. The first two arguments (function expression and range) can be replaced by a definite integral. x0+nh x0 f(x)dx=3h 8 [(y0 + yn) + 3(y1 + y2 + y4 + y5 + .... + yn−1) + 2(y3 + y6 + ....yn−3)] While using this method the number of sub intervals should be taken as multiple of 3. PROGRAMMING CODE FOR I = b a e−x2 dx. #include<stdio.h> #include<math.h> float fn(float); int main() { int i,n; float sum1,sum2,sum3,I,h,b,a,y[100],x[100]; printf("write the value of nn"); scanf("%d",&n); 10
  • 11. printf("enter the value of b or upper limitn"); scanf("%f",&b); printf("enter the value of a or lower limitn"); scanf("%f",&a); h= (b-a)/n ; x[0]=a; y[0]=F(x[0]); x[n]=b; y[n]=F(x[n]); printf("x t f(x)n"); printf("%f t %fn",x[0],y[0]); for(i=1;i<n;i++) { x[i]= x[i-1]+ h; y[i]= F(x[i]); printf("%f t %fn n",x[i],y[i]); } printf("%f t %fn",x[n],y[n]); sum1=0; for(i=1;i<n;i=i+3) { sum1 = sum1 +3*y[i]; } sum2=0; for(i=2;i<n;i=i+3) { sum2 = sum2 +3*y[i]; } sum3=0; for(i=3;i<n;i=i+3) { sum3 = sum2 + 2*y[i]; } I= ((3*h)*(y[n]+y[0]+sum1+sum2+sum3))/8 ; printf("value of integration of given by = %f",I); } float fn(float x) { float f; f= exp(-(x*x)); return f; } Question-Evaluate 6 0 1 1+x2 dx by using 1. Trapezoidal Rule, 2. Simpson 1/3 Rule, 11
  • 12. 3.Simpson 3/8 Rule solution Divide the interval (0,6)into six parts each of width h=1.The values of f(x) = 1 1+x2 are given below x f(x) 0 1 1 0.5 2 0.2 3 0.1 4 0.0588 5 0.0385 6 0.027 1. By Trapezoidal rule, 6 0 1 1+x2 dx = h 2 [(y0 + y6) + 2(y1 + y2 + y3 + y4 + y5] =6 2 [(1 + 0.027) + 2(0.5 + 0.2 + 0.1 + 0.0588 + 0.0385)] =1.4108 2. By Simpson 1/3 Rule 6 0 1 1+x2 dx = h 3 [(y0 + y6) + 4(y1 + y3 + y5) + 2(y2 + y4)] =6 3 [(1 + 0.027) + 4(0.5 + 0.1 + 0.0385) + 2(0.2 + 0.0588)] =1.3662 3.By Simpson 3/8 Rule 6 0 1 1+x2 dx = 3h 8 [(y0 + y6) + 3(y1 + y2 + y4 + y5) + 2y3] =3 8 [(1 + 0.027) + 3(0.5 + 0.2 + 0.0588 + 0.0385) + 2(0.1)] =1.3571 4 Differentiation Method Numerical differentiation deals with the following problem:we are given the function y = f(x) and wish to obtain one of its derivatives at the point x = xk. The term“given” means that we either have an algorithm for computing the function, or possess a set of discrete data points (xi , yi ), i = 0, 1, . . . , n. In either case, we have access to a finite number of (x, y) data pairs from which to compute the derivative. Numerical differentiation is related to interpolation,means of finding the derivative is to approximate the function locally by a polynomial and then differentiate it. An equally effective tool is the Taylor series expansion of f(x) about the point xk, which has the advantage of providing us with information about the error involved in the approximation. Numerical differentiation is not a particularly accurate process. The derivative of the function f at x0 is f (x0) = lim h→0 f(x0 + h) − f(x0) h 12
  • 13. This formula gives an obvious way to generate an approximation to f(x0); simply compute f(x0 + h) − f(x0) h for small values of h. 4.1 Euler’s Method In mathematics and computational science, the Euler method is a first- order numerical procedure for solving ordinary differential equations (ODEs) with a given initial value. It is the most basic explicit method for numerical integration of ordinary differential equations. This can be described as a technique of developing a piecewise linear approximation to the solution.In the initial value problem .the starting point of the solution curve and the slope of the curve at the starting point are given.With this information the method extrapolates the solution curve using the specified step size. Example’s:- 1. Simple Harmonic Motion Equation of motion are: d2 x dt2 = −kx (1) y = dx dt (2) dy dt = −kx (3) PROGRAMMING CODE #include<stdio.h> void main() { float x0,y0,h,k,x,y,i; x0=0.1; //intialisation y0=0.2; h=0.001; k=1; FILE*fp; fp=fopen("SHM.dat","w"); for(i=0;i<=50000;i++) { x=x0+h*y0; y=y0+h*(-k)*x0; x0=x; y0=y; 13
  • 14. fprintf(fp,"%ft%ft%fn",i,x,y); } fclose(fp); } -0.25 -0.2 -0.15 -0.1 -0.05 0 0.05 0.1 0.15 0.2 0.25 -0.25 -0.2 -0.15 -0.1 -0.05 0 0.05 0.1 0.15 0.2 0.25 y x "SHM.dat" us 2:3 2. The Lorenz Attractor Equation’s of Motion are:- dx dt = σ(y − x) (4) dy dt = (r − z)(x − y) (5) dz dt = (xy − bz) (6) PROGRAMMING CODE #include<stdio.h> void main() { float x0,y0,z0,h,x,y,z,r,a,b,i; x0=0.02; //intialisation 14
  • 16. -20 -15 -10 -5 0 5 10 15 20 25-30 -20 -10 0 10 20 30 0 10 20 30 40 50 60 z lorenz attractor "lorenz.dat" us 2:3:4 x y z 16