Showing posts with label labs. Show all posts
Showing posts with label labs. 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, June 12, 2013

Determinant Calculation of Nth Order Square Matrix| Cramer's Rule Implementation in C

Determinant calculation of a square matrix is widely used in solving many applied Mathematics problems. Some of them are while solving a set of linear equations using Cramer's rule (iff they have unique solutions), calculation of inverse matrix, Eigen values/ Eigen vectors problem and so on.

The determinant of a square matrix A∈Rn×n is the real number det(A) defined as follows:

det(A) = SUMperm [sign(ν1,ν2,...,νn)a1ν1a2ν2...anνn]
.

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

C Source Codes for Implementing Linked List

The linked list can be implemented using the pointer structure in C so that we can

  • add an element
  • delete an element
  • search for an element
  • concatenate two linked list
  • Invert a linked list
  • Display elements in the list


//Program to demonstrate linked list operations

# include<stdio.h>
# include<conio.h>
# include "malloc.h"
struct node
{
int data;
struct node *link;
};