Saturday, April 4, 2009

Auto generate a number in VB

Dim query As String
Dim query1 As String
Dim i As Integer
Dim obj_data_access As New data_access
Dim dt As DataTable
Dim ds As New System.Data.DataSet
Dim rowcount As Integer
Dim dv As DataView
Dim dp1 As String
Dim dp2 As String
dp1 = std_course.SelectedItem
dp2 = std_batch.SelectedItem
query = "select roll_no from student where course='" & dp1 & "' and batch='" & dp2 & "'"

ds = obj_data_access.retrieve(query, "student")
rowcount = ds.Tables("student").Rows.Count
If (rowcount = 0) Then
i = 1
Else
query1 = "select max(roll_no) from student where course='" & dp1 & "' and batch='" & dp2 & "'"

ds = obj_data_access.retrieve(query1, "student")
rowcount = ds.Tables("student").Rows.Count
i = ds.Tables(0).Rows(0).Item("roll_no")
i=i+1
End If


std_roll.Text = i

Saturday, November 1, 2008

Newtons Differentation.

void main()
{
int a[10][10],n,i,j,g,x,k;
float h,sum=0.0;
cout<<"Enter the value of n:";
cin>>n;
cout<<"Enter the values of X & Y in array:";
for(i=0;i<2;i++)
{
for(j=0;j{
cin>>a[j][i];
}
}

cout<<"Enter the common difference:";
cin>>h;

cout<<"Enter the value of X on which we have to find the solution:";
cinn>>x;

//make the forward difference table.
j=2;
g=n-1;
while(j < =n)
{
for(i=0; i < g;i++)
a[i][j]=a[i+1][j-1] - a[i][j-1];
j++; g--;
}


//searching that number in array at what position.
j=-1;
for(i=0; i < n; i++)
{
if( a[i][0]==x)
{
j++;
cout << j;
exit( 0 );
}
else
j++;
}

//now searching where it is in upper part or lower part and then computing it.

if( j < n/2)
{
k=n-j;
g=1;
for(i=j, l=2; l < =k; l++)
{
if(g%2==0)
{
sum - =(a[i][l])/g;
g++;
}
else
{
sum + = (a[i][l])/g;
g++;
}
}
}

else
{
g=1;
for(i=j-1, l=2; l < = j+1 ;l++, i--)
{
sum + = (a[i][l])/g;
g++;
}
}

sum=sum/h;

cout<<"Sum is:";
cout << sum;
getch();
}

Thursday, October 16, 2008

Program Of Simpsons 1/3 formulae.

void main()
{
int a[10];

cout<<:Enter the no. of terms:";
cin>>n;
cout<<"Enter the difference:";
cin>>h;

cout<<"Enter the values:";
for(i=1 ; i <= n;i++)
{
cin>>a[i];
}
if(n%2==1)
{
sum=y[1]+y[n];
for(i=2; i < =n-1;i++)
{
if(i%2==0)
sum + =4*y[i];
else
sum + =2*y[i];
}
sum = (sum*h)/3;
}

else
{
sum=y[1]+y[n-1];
for(i=2; i < = n-2; i++)
{
if(i%2==0)
sum + =4*y[i];
else
sum + =2*y[i];
}
sum=(sum*h)/3;
sum 2=((y[n-1]+y[n]) * h)/2;
sum=sum+sum2;
}

cout<<"Sum is:";
cout << sum;
getch();
}

Tuesday, October 14, 2008

Program of Inverse using Gauss Method.

//This loop is for making upper triangular .
Here I is a unit matrix and a is coefficient matrix.

for(k=0; k < n-1; k++)
{
for(p=k+1; p < n; p++)
{
if(a[k][k]==0 )
{
for(x=0; x < n;x++)
{
t=a[k][x];
a[k][x]=a[k+1][x];
a[k+1][x]=t;
}
continue;
}
}
i=0;
for(i=k+i; i < n-1;i++)
{
for(j=0; j < n-k;j++)
{
t[0]=a[k][k];
t[1]=a[i+1][k];
a[i+1][j+k]=(t[0]*a[i+1][j+k])-(t[1]*a[k][j+k]);
I[i+1][j+k]=(t[0]*I[i+1][j+k])-(t[1]*I[k][j+k]);
}
}
}

//Now assign value in the variables x[2][0],x[2][1],x[2][2] and so on.

for(k=n-1; k >=0;k--)
{
for(i=n-1; i > =0;i--)
{
num=I[k][i];
dem=a[k][k];
Sum=0;
for(j=0;j > n-1;j++)
{
if(k!=j)
num - =a[k][j]* X[j][i];
else
continue;
}
Sum=num/dem;
x[k][i]=Sum;
}
}
Cout<<"Inversed matrix is:";
for(i=0 ; i < n;i++)
{
for(j=0; j < n; j++)
cout << X[i][j];
}
getch();
}

Program of Determinant.

void main()
{
int sum=0;p=1,i,j,k,n,X[10][10];
cout<<:Enter the determinant values:";
for(i=0; i < n;i++)
{
for(j=0;j < n;j++)
cin>>X[i][j];
}

//main concept
for(k=0;k < n;k++)
{
for(i=0,j=k; i < n;i++, j--)
{
p=p*X[i][j];
if(j==n-1)
j=0;
}
sum + =p;
p=1;
}

for(k=1; k < =n;k++)
{
for(i=0,j=n-k; i < n; i++, j--)
{
p=p*X[i][j];
if(j==0)
j=n-1;
}
sum=sum-p;
p=1;
}
getch();
}

Friday, October 3, 2008

Gauss-Jordan Algorithm.

//This loop is for making upper triangular .
Here I is a unit matrix and a is coefficient matrix.

for(k=0; k < n-1; k++)
{
if(a[k][k]==0
&& k < n )
{
for(i=k; i < k+1;i++)
{
for(j=0; j < n;j++)
{
t=a[i][j];
t2=a[i+1][j];
a[i+1][j]=t;
a[i][j]=t2;
}
}
}
i=0;
for(i=k+i; i < n-1;i++)
{
for(j=0; j < n-k;j++)
{
t[0]=a[k][k];
t[1]=a[i+1][k];
a[i+1][j+k]=(t[0]*a[i+1][j+k])-(t[1]*a[k][j+k]);
I[i+1][j+k]=(t[0]*I[i+1][j+k])-(t[1]*I[k][j+k]);
}
}
}

//Now assign value in the variables x[2][0],x[2][1],x[2][2] and so on.

for(k=n-1; k >=0;k--)
{
for(i=n-1; i > =0;i--)
{
num=I[k][i];
dem=a[k][k];
Sum=0;
for(j=0;j > n-1;j++)
{
if(k!=j)
num - =a[k][j]* X[j][i];
else
continue;
}
Sum=num/dem;
x[k][i]=Sum;
}
}

Tuesday, September 30, 2008

Solution of linear equations.

First input the coefficient matrix and the constant matrix.
-> In this program array a is the coefficient matrix which is a 2 D matrix.
-> Constant matrix is array b which is a single collumn matrix.
-> Input the value of n from the user.
-> Take another array X which is also a single collumn matrix and is used to store the values of variables X,Y,Z and so on.


//This loop is for making upper triangular
for(k=0; k < n-1; k++)
{
for(p=k+1; p < n; p++)
{
if(a[k][k]==0 )
{
for(x=0; x < n;x++)
{
t=a[k][x];
a[k][x]=a[k+1][x];
a[k+1][x]=t;
}
continue;
}
}
i=0;
for(i=k+i; i < n-1;i++)
{
for(j=0; j < n-k;j++)
{
t[0]=a[k][k];
t[1]=a[i+1][k];
a[i+1][j+k]=(t[0]*a[i+1][j+k])-(t[1]*a[k][j+k]);
b[i+1][0]=(t[0]*b[i+1][0])-(t[1]*b[k][0]);
}
}
}

//Now assign value in the variables x[0][0],x[1][0],x[2][0]

for(i=n-1; i >= 0;i--)
{
num=b[i][0];
dem=a[i][i];
sum=0;
for(j=0; j < n;j++)
{
if(i!=j)
num-=a[i][j]*x[j][0];

else
continue;
}
sum=num/dem;
x[i][0]=sum;
}

Thus write another loop to print the values of variables.

Sunday, September 28, 2008

Jacobi Method Algorithm.

flag =1;

for(i=0; i < n;i++0)
{
t[i]=b[i]/a[i][i];
x[i]=t[i];
}

while ( flag==1)
{
for(i=0;i < n;i++)
{

x[i]=b[i]/a[i][i] ;

for(j=0; j < n;j++)

{
if(i != j)
x[i] - =(t[j]*a[i][j])/a[i][i];
else
continue;
}

}
for(i=0; i < n;i++)
{
if(x[i] - t[i] > = 0.005)
{
t[i]=x[i];
flag==1;
}
else
flag==0;
}

}

Gauss-Seidel Algorithm.

flag =1;

for(i=0; i < n;i++0)
{
x[i]=0;
t[i]=x[i];
}

while ( flag==1)
{
for(i=0;i < n;i++)
{

x[i]=b[i]/a[i][i] ;

for(j=0; j < n;j++)

{
if(i!=j)
x[i] - =(x[j]*a[i][j])/a[i][i];
else
continue;
}

}
for(i=0; i < n;i++)
{
if(x[i]-t[i] > =0.005)
{
flag==1;
t[i]=x[i];
}
else
flag==0;
}
}

Newton Raphson Algorithm.

Let the equation be f(x)=x*x*x-18.

So in newton raphson we take f(x) and f'(x) ,so here we have to find f'(x) we write a function,

double f2(double s)
{
return 3*s*s;
}

double f1(double s)
{
return pow(s,3)-18;
}

void main()
{
double a[30],e;
int i=2;
a[0]=0;
cout<<"Enter the value of x:";
cin>>a[1];

cout<<"Enter the value of epslon:";
cin>>e;

do
{
a[i]=a[i-1]-( f1(a[i-1]) / f2(a[i-1]));
cout<<"\n" << a[i];
i++;
}
while( fabs(a[i-1]-a[i-2]) > =e);
getch();
}

Saturday, September 27, 2008

Program of Upper Triangular

This is mainly the concept of the program what to do in upper triangular program.

We take 3 for loops

for(k=0; k < n-1;k++)
{
for(p=k+1; p < n; p++)
{
if(a[k][k]==0 )
{
for(x=0; x < n;x++)
{
t=a[k][x];
a[k][x]=a[k+1][x];
a[k+1][x]=t;
}
continue;
}
}
i=0;
for(i=k+i;i < n-1;i++)
{
for(j=0;j < n-k;j++)
{
t1=a[k][k];
t2=a[i+1][k];
a[i+1][j+k]=t1*a[i+1][j+k]-t2*a[k][j+k];
}
}
}

Now in this the the inner most loop which is j loop is for doing the row operation.
i loop is for going to the next row,and the k loop is for making the elements 0 in the next collumn ,i.e, making the elements 0 in the first collumn we have to make the elements 0 of the second collumn.

Saturday, September 13, 2008

How to find T States of 8085 Microprocessor.


How To Calculate Timing States In 8085 Microprocessor

CLK:-The clock is the machine clock it goes up and low.

A15-A8 :-These are the higher order address lines store only address,Here we put the higher order address.


AD7-AD0 :-These are the lower order address lines.This is a multi plexed Address/Data bus.Firstly we store lower order address in this and after that we put data in it.


ALE :- It is a positive going pulse which indicates that the bits on AD7-AD0 are address bits.This latches lower order bus and generate to seperate 8 address lines.


IO/M bar:-These are the status signals .Different signals give different results.



Opcode fetch (IO/M bar=0,S1=1,S0=1)
Memory Read (IO/M bar=0,S1=1,S0=0)
Memory Write (IO/M bar=0,S1=0,S0=1)
I/O Read (IO/M bar=1,S1=1,S0=0)
I/O Write (IO/M bar=1,S1=0,S0=1)
Interrupt Accow. (IO/M bar=1,S1=1,S0=1)


So this is the description of the timing diagram.Now we will know how to find the T states.

So for any instruction LDA,MVI,MOV ......etc.we have to fetch the operation code,for this the microprocessor goes to the memory location where it will find the machine code for that opcode.From this whatever has been there on the address goes through data bus to the instruction decoder which decodes the signal.

Lets take an example

MVI A,32H is the instruction.


So ,memory location 5000 in Hexa & machine code which is there for MVI is 00111110(assume only) ,ie 3E in Hexa.
For op code fetch the status signals are(IO/M=0,S1=1,S0=1),it places the memory address from program counter on the address bus and increment the program counter to 5001.Thus,50 H goes to higher order bus and 00H goes to lower order bus.The Ale signal goes high during T1 which latches
the lower order bus.At T2 the 8085 asserts RD bar signal,which enables the memory,and the memory places the byte 3E on the data bus.Then 8085 places opcode in the instruction register and disables RD bar signal.The fetch cycle is completed in T3 state.During T4 state 8085 decodes the opcode.
and finds out second byte to read.After the T3 state,the contents of the bus A15-A8 are unspecified and AD7-AD0 goes high impedance.
For opcode fetch 4T states required.


After the opcode fetch 8085 goes again to the memory and places the next address 5001 on the address bus and increments the program counter.The second signal identifies as memory read thus,the status signals are (IO/M=0,S1=1, S0=0),the same thing happen as
it has been for opcode accept the decode.So for reading 3T states are required.

AS general rule :-
If there is 1 byte instruction we will require minimum 4T states.
If there is 2 byte instruction we will require minimum 7T states.
If there is 3 byte instruction we will require minimum 10T states.

For opcode fetch 4T states.
read 3T state.
write 3T state.

Thus in above example which is 2 byte instruction we will require 4T states for opcode fetch and then 3T states for reading the data.Thus total 7T states.