Showing posts with label numerical methods. Show all posts
Showing posts with label numerical methods. Show all posts

## Wednesday, June 19, 2013

### Random Numbers Generation & Chi-Squared Test for their Uniformity in C++

Continuous uniformly distributed random numbers means the set of random numbers where probability of any number in any integral within a certain range of values is proportional to the ratio of the interval size to the range. The generated random numbers require to be independent & uniform in distribution. There are many different methods to generate the random numbers.
They are:
• Random numbers from table.
• From hardwired device.
• Using pseudo Number generation.

In linear congruential method, we use one initial number (rcalled seed) and few constants. Using the seed and the formula,
ri+1 = (ri ×a + b) (modulo m)

## Wednesday, May 29, 2013

### Solution of Ordinary Differential Equation using Runge-Kutta Method | RK4 method for ODE Solution in C

In numerical analysis, the Runge–Kutta methods are an important family of implicit and explicit iterative methods for the approximation of solutions of ordinary differential equations. These techniques were developed around 1900 by the German mathematicians C. Runge and M. W. Kutta.

There are many variants of the Runge-Kutta method, but the most widely used one is the following known as RK-4 method:
Given
y' = f(x,y)
y(xn) = yn
we compute in turn
k1 = hf(xn,yn)
k 2 = hf (xn+h/2,yn+k1/2)
k3 = hf (xn+h/2,yn+k2/2)
k4 = hf(xn + h, yn + k3)
yn+1 = yn + (k1 + 2*k2 + 2*k3 + k4 )/6

This algorithm can be implemented  using the following source code in C:

## Friday, May 24, 2013

### Gauss Jordan Method Implementation with C Source Code

In linear algebra, Gaussian Jordan method is an algorithm for solving systems of linear equations. It is usually understood as a sequence of operations performed on the associated matrix of coefficients. This method can also be used to find the rank of a matrix, to calculate the determinant of a matrix, and to calculate the inverse of an invertible square matrix.

We can implement this method in C using the following source code:
``//Implementation of Gauss Jordan Method, @author: +Jivan Nepali, @URL: codeplustech``
`````` #include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define Max 10
int main()
{
float a[Max][Max+1],t,det=1;
int i,j,k,N;
printf("Enter the number of unknowwns : ");
scanf("%d",&N);
``````

## Saturday, May 18, 2013

### Newton-Raphson Method in C with source codes

Newton-Raphson method is a method for finding successively better roots (zeros) of a real valued function
x: f(x) = 0.

The algorithm can be implemented in C as follows:

``````#include<stdio.h>
#include<math.h>
#include<conio.h>
#define h pow(10,-6)
#define error pow(10,-6)
double f(double x)
{
return(x*x-4);
}
double df(double x)
{
return 2*x;
}``````