Wednesday, June 27, 2012

Eight queen problem with solution in visual prolog (artificial intelligence)


Eight queens problem
Eight queens problem is a constraint satisfaction problem. The task is to place eight queens in the 64 available squares in such a way that no queen attacks each other. So the problem can be formulated with variables x1,x2,x3,x4,x5,x6,x7,x8 and y1,y2,y3,y4,y5,y6, y7,y8; the xs represent the rows and ys the column. Now a solution for this problem is to assign values for x and for y such that the constraint is satisfied.
The problem can be formulated as
P={(x1,y1),(x2,y2),……………………..(x8,y8)}
where (x1,y1) gives the position of the first queen and so on.

So it can be clearly seen that the domains for xi and yi are
Dx = {1,2,3,4,5,6,7,8}and Dy ={1,2,3,4,5,6,7,8} respectively.

The constraints are
i. No two queens should be in the same row,
i.e  yi≠yj for i=1 to 8;j=1 to 8;i≠j
ii. No two queens should be in the same column,
i.e  xi≠xj for i=1 to 8;j=1 to 8;i≠j
iii. There should not be two queens placed on the same diagonal line
i.e  (yi-yj) ≠ ±(xi-xj).

Now a solution to this problem is an instance of P wherein the above mentioned constraints are satisfied.

code in prolog

PREDICATES
DOMAINS
cell=c(integer, integer)
list=cell*
int_list=integer*

PREDICATES
solution(list)
member(integer,int_list)
nonattack(cell,list)

CLAUSES
solution([]).

solution([c(X,Y)|Others]):-
solution(Others),
member(Y,[1,2,3,4,5,6,7,8]),
nonattack(c(X,Y),Others).

nonattack(_,[]).
nonattack(c(X,Y),[c(X1,Y1)|Others]):-
Y<>Y1,
Y1-Y<>X1-X,
Y1-Y<>X-X1,
nonattack(c(X,Y),Others).

member(X,[X|_]).
member(X,[_|Z]):-
member(X,Z).


GOAL
solution([c(1,A),c(2,B),c(3,C),c(4,D),c(5,E),c(6,F),c(7,G),c(8,H)]).

Monday, June 25, 2012

How to start using google map API in android programming projects

Google map api is very impportant tool which we can use in our project.For the beginners it is quite important to know some of the terms and things which is important before starting Api .

Firstly ,before we use API in our programme we must have the API key.so we must generate the API key in the beginning and we should submit it to the google.after then it gives us some code which we should paste in our programme and we can get the nice google map in our screen.

STEPS FOR GENERATING KEY:


1.  first go to the command prompt.
2 <C:\program files \java \jdk1.6.0_21\bin> keytool -list -alias androiddebugkey -keystore debug.keystore
        -storepass android -keypass android
          note:  jdk1.6.0_21 is the jdk version installed in my computer ,you may have another one so be                      
                    careful .First check in your computer at the location C:\program files\java
  










3.Then the MD5 fingerprint code is generated.But if your jdk version is 1.7 then MD5 fingerprint is not generated but we need MD5 so put -v behind list to get the MD5 code


4 Then go to the Android Maps API Key Signup page enter the md5 fingerprint provided .Then the site will generate the code .place this code in your program to get the google map view.
       

Sunday, June 3, 2012

how to append two list in visual prolog programming


Visual Prolog Program to append two list.


Here the two list are taken by the predicate “append” and returns the appended list. To append two list a list is broken continuously until the last empty list is encountered and finally the other list is appended or joined at the end of first recursively. The code to append is given as follows:

DOMAINS
int_list=Integer *

PREDICATES
append(int_list,int_list,int_list)
CLAUSES

append([],X,Z):-
Z=X.
append([H|T],X,Y):-
append(T,X,Z),Y=[H|Z].
GOAL
append([1,2,3,4,5],[6,7,8,9],X).

how to find factorial in visual prolog programming


Visual Prolog Program to find the factorial of a number.




To find the factorial of a number in Visual Prolog, the number is decreased and the predicate “factorial” is continuously until a Zero is encountered when it returns a value 1. Then the predicate multiplies the returned value and the decremented number continuously. Thus, the factorial of a number is found. The visual prologue code to find the factorial of a number is given below:

PREDICATES
factorial(Integer,Integer)
Clauses
factorial(0,1).
factorial(X,Y):-
X<>0,S=X-1,factorial(S,Y1),Y=X*Y1.

Goal
factorial(5,X).

how to find the length of the list in Visual Prolog



Visual Prolog Program to find length of a list.

In this program the predicate length takes integer list and output a integer which is the length of list. Here the predicate length is called repeatedly or recursively until a last empty list is encountered and the 0 value is returned which is then continuously incremented to find the length.

%to find the length of the list

DOMAINS
int_list=Integer*

PREDICATES
length(int_list,integer)

CLAUSES
length([],0).
length([H|T],L):-
length(T,L1),L=L1+1.
GOAL
length([1,2,3,4,5,6],X).


output


How to find the hcf using Visual Prolog programming

Visual prolog is a software of artificial intelligence(AI).Before  we start the programming in the visual prolog ,we should install the programand we must write the code in it.and the thing we should consider is wemust save thefile in .PRO file and be placed at the location where it is stored in C: drive.(C: VIP/BIN/WIN/32).

Here is the code  to find the HCF of two numbers in visual prolog:

%TO FIND THE HCF OF TWO NUMBERS



PREDICATES
hcf(integer, integer, integer)

CLAUSES
hcf(X, Y, X):-
Y mod X = 0.
hcf(X,Y,Z):-
S = Y mod X,S<>0, hcf(S, X, Z).

GOAL
hcf(5,10,X).

OUTPUT:
To find the output press the G button on the top of the software. the output of the above program looks like this


CONCEPT:
here the concept is that when the  number is divided exactly by  the smaller number or the divisor,then the divisor is the required hcf.
and if there is remainder in the division, then the hcf of the remainder and the previous divisor is found repeadtly until the remainder is 0,

in the above example,10 %5 is 0 so the HCF is 5.
in 20 and 30, 30%20=10
since remainder is not 0,we should find now HCF of 20 and 10 ,here remiander is 0.so HCF is 10.





CODE OF PIC 16F877A FOR MAKING DVM USING MICRO C PROGRAMMING IDE


NOTE:  This is the programming code written for pic 16877 for making digital voltmeter.The IDE used for this program is micro c programming.we should also know that this code is written in C language whereas pic doesnot understand C,it only knows the Hex code so it must be first converted to hex code and then it is burned to the pic.

The design is performed in proteus

all the  things within /.........../ are the comments.




/*************display in LCD using 8-bit, 2 line mode*******/
#include <htc.h>

#define data PORTB
#define RS RD0
#define EN RD1
float result,val;
int val1,val2;
__CONFIG(HS & WDTDIS & PWRTEN & BORDIS & LVPDIS);

void delay_ms(int n )
{
           TMR1H=0xEC;        // EC77H=60535d
        TMR1L=0x77;
        T1CKPS1=0;
        T1CKPS0=0;
        TMR1CS=0;
        TMR1IF=0;
        TMR1ON=1;
           while(n>0)
           {
                while(!TMR1IF)  { }
                TMR1IF=0;
                TMR1H=0xEC;
                TMR1L=0x77;
                n--;
        }
}
void delay_100us(int n )      
{
           TMR1H=0xFE;      
        TMR1L=0x0C;
        T1CKPS1=0;
        T1CKPS0=0;
        TMR1CS=0;
        TMR1IF=0;
        TMR1ON=1;
           while(n>0)
           {
                while(!TMR1IF)  { }
                TMR1IF=0;
                TMR1H=0xFE;      
                TMR1L=0x0C;
                n--;
        }
}


void LCD_Write(unsigned char value,int rs)
{
        data = value;
        RS = rs;                                //if rs=0; command is sent to LCD otherwise data to be displayed is sent
        EN = 1;
        delay_ms(1);
        EN = 0;

}

void LCD_clear(void)
{
        LCD_Write(0x01,0);                //this clears LCD
}

void LCD_goto(unsigned char row,unsigned char column)
{
        if(row==1){
                LCD_Write(0x80+column,0);        //
        }
        else if(row==2){
                LCD_Write(0xC0+column,0);
        }


}
void LCD_num(int n)
{

    if(n<=9)
    {
            LCD_Write(48+n,1);
         }
         else if(n<=99)
         {
                 LCD_Write((n/10)+48,1);
                 LCD_Write((n%10)+48,1);
        }
        else if(n<=999)
        {
                LCD_Write((n/100)+48,1);
                LCD_Write(((n%10)/10)+48,1);
                LCD_Write((n%10)%10+48,1);
        }
}
void init_ADC()
{
        PCFG3=0;        PCFG2=0;  PCFG2=0;  PCFG0=0;                //Configures all the pins of PORTA and PORTB as ANALOG pins.

        /*For correct A/D conversions, the A/D conversion clock must be selected to ensure a minimum
        TAD time of 1.6 ms as shown in parameter 130 of the “Electrical Specifications” section.*/

        ADCS1=1;        ADCS0=0;        //this gives  32*Tosc=1.6 us
        ADFM=1;                                //Left justified format viz 6 LSBs of ADRESL regsiter are read as ‘0’.
        //Result will be held at ADRESH and ADRESL register
}
void initLCD(void)
{
        //PORT configuration
        TRISB = 0x00;
        TRISD=0x00;
        //////////////////

        LCD_Write(0x30,0);
//        data = 0x3;         // 8 bit mode
        EN=1; EN = 0;
        LCD_Write(0x38,0);
        delay_ms(1);
        LCD_Write(0x0C,0);    //dispaly on , no cursor blinking
        delay_ms(1);
        LCD_Write(0x01,0);    // clear dispaly screen


        delay_ms(1);
        LCD_Write(0x06,0);
        delay_ms(1);
        LCD_clear();
        LCD_goto(1,1);
        LCD_goto(1,1);        //1st row 1st column
    LCD_Write('D',1);delay_ms(100); LCD_Write('I',1);delay_ms(100); LCD_Write('G',1);delay_ms(100); LCD_Write('I',1);delay_ms(100);
        LCD_Write('T',1);delay_ms(100);LCD_Write('A',1);delay_ms(100);LCD_Write('L',1);delay_ms(100);LCD_Write(' ',1);delay_ms(100);
        LCD_Write('V',1);delay_ms(100);LCD_Write(' ',1);delay_ms(100);LCD_Write('M',1);delay_ms(100);LCD_Write('E',1);delay_ms(100);
    LCD_Write('T',1);delay_ms(100); LCD_Write('E',1);delay_ms(100); LCD_Write('R',1);
        LCD_goto(2,1);
    LCD_Write('D',1);  LCD_Write('C',1);  LCD_Write(' ',1);  LCD_Write('V',1);  LCD_Write('O',1);  LCD_Write('L',1);  LCD_Write('T',1);  LCD_Write('=',1);

}
/************Analog to digital conversion will occur here**********/
void ADC()
{
        ADON=1;                                         //A/D converter module is powered up
        /**********************channel one********************/
        CHS2=0; CHS1=0; CHS0=0;        // selecting pin A0 as input pin where analog signal will appear
        delay_ms(3);
    ADGO  = 1;                                         //ADGO WILL BE  RESET  BY  SYSTEM AUTOMATICALLY ONCE   ADC   IS   COMPLETE
        while(ADGO);
    result=(ADRESH<<8)+ADRESL;
    LCD_goto(2,9);
    if(result<511||result>512)
     {
         if(result>512.0)
           {//        LCD_goto(2,9);
            LCD_Write(' ',1);
             result=result-511.5;
   
        }
        else if(result<511.0)
         {//LCD_goto(2,9);
          LCD_Write('-',1);   //displaying negative sign
          result=result-511.5;
           result=-(result);
       }
       result=result*30/511.5;
       val1=(int)result;
       LCD_num(val1);
       LCD_Write('.',1);   //displaying dot sign
       val=result-val1;
       val=val*1000;
       val2=(int)(val);
       LCD_num(val2);
}
  else
    {result=0;
     LCD_Write(' ',1);
     LCD_Write(' ',1);
     result=result*30/511.5;
     val1=(int)result;
     LCD_num(val1);
     LCD_Write('.',1);   //displaying dot sign
     val=result-val1;
     val=val*1000;
     val2=(int)(val);
     LCD_num(val2);}



}

void main(void)
{        TRISB=0x00;                //Configuring all pins of B port as output.
        PORTB=0x00;                //output at all pins will be low
        TRISA=0xff;                        //Configuring all pins of A port as input
        TRISD0=TRISD1=0;
        RD0=RD1=0;
        initLCD();
        init_ADC();
while(1)
 {
        ADC();                //call ADC convert
}
}

how to solve duplicate location while installing ADT(plugin) in eclipse IDE


PROBLEM:    during the installation of ADT in the eclipse IDE,The small window appears with message "duplicate location".each time this message appears and installation is not allowed and can't be completed:

solution:
   in the website,we can find several solution to this problem.we may get  annoyed due to several answer and our problem may not be solved,i also got same problem while installing plugin.i searched this problem in the net but i could not found the best solution.

with a lot of work in it ,i fix this problem.here is the solution to this problem.it could solve your problem in an easier way:

1:  firstly if you have got the ellipse IDE ,that is compatiable without installation. in this case delete the eclipse folder
2. unzip the zip folder which we have downloaded earlier.
3. after this install the ADT ,doing this it wont ask for duplicate location again.

HOW TO START ANDROID APPS PROJECT/INSTALLATION OF SDK


This post is especially for those who are new to the android field.The first  thing we must know before starting the android project is we must install some of the kit like JDK,SDK and Android ADT plugins.

Here are the steps we should follow for the installation of the required kits:


Step 1. Preparing Your Development Computer

Before getting started with the Android SDK,system requirement must be fulfilled. In particular, you might need to install the JDK, if you don't have it already.

.


Step 2. Downloading the SDK Starter Package

The SDK starter package is not a full development environment—it includes only the core SDK Tools, which you can use to download the rest of the SDK packages (such as the latest Android platform).

If you haven't already, get the latest version of the SDK starter package from the SDK download page.

If you downloaded a .zip or .tgz package (instead of the SDK installer), unpack it to a safe location on your machine. By default, the SDK files are unpacked into a directory named android-sdk-<machine-platform>.

If you downloaded the Windows installer (.exe file), run it now and it will check whether the proper Java SE Development Kit (JDK) is installed (installing it, if necessary), then install the SDK Tools into a default location (which you can modify).

Make a note of the name and location of the SDK directory on your system—you will need to refer to the SDK directory later, when setting up the ADT plugin and when using the SDK tools from the command line.


Step 3. Installing the ADT Plugin for Eclipse

Android offers a custom plugin for the Eclipse IDE, called Android Development Tools (ADT), that is designed to give you a powerful, integrated environment in which to build Android applications. It extends the capabilites of Eclipse to let you quickly set up new Android projects, create an application UI, debug your applications using the Android SDK tools, and even export signed (or unsigned) APKs in order to distribute your application. In general, developing in Eclipse with ADT is a highly recommended approach and is the fastest way to get started with Android.

If you'd like to use ADT for developing Android applications, install it now. Read Installing the ADT Plugin for step-by-step installation instructions, then return here to continue the last step in setting up your Android SDK.

If you prefer to work in a different IDE, you do not need to install Eclipse or ADT. Instead, you can directly use the SDK tools to build and debug your application. The Introduction to Android application development outlines the major steps that you need to complete when developing in Eclipse or other IDEs.




Step 4. Adding Platforms and Other Packages

The last step in setting up your SDK is using the Android SDK Manager (a tool included in the SDK starter package) to download essential SDK packages into your development environment.

The SDK uses a modular structure that separates the major parts of the SDK—Android platform versions, add-ons, tools, samples, and documentation—into a set of separately installable packages. The SDK starter package, which you've already downloaded, includes only a single package: the latest version of the SDK Tools. To develop an Android application, you also need to download at least one Android platform and the associated platform tools. You can add other packages and platforms as well, which is highly recommended.

If you used the Windows installer, when you complete the installation wizard, it will launch the Android SDK Manager with a default set of platforms and other packages selected for you to install. Simply click Install to accept the recommended set of packages and install them. You can then skip to Step 5, but we recommend you first read the section about the Available Packages to better understand the packages available from the Android SDK Manager.
.


FOR DETAIL INFORMATION PLEASE REFER THE OFFICIAL SITE
http://developer.android.com/sdk/installing.html

MINOR ENGINEERING PROJECTS LIST


 Major Projects
1. Calendar
2. Mero Radio(Broadcasting Service Automation System)
3. Music Organizer and Recommender
4. MBNS(Mobile Based Navigation System)
5. Forecasting Share Markets using Neural Networks
6. Health Cost Prediction
7. Web Office
8. Clustering Search Engine
9. Real Time Face Tracking and Recognition
10. Artificial Neural Network Based Stock Prediction
11. Recognition of Human Iris Patterns for Biometric Identification
12. Machine-Human Dialog
13. Illumination Invariant Face Recognition System
14. Semantic Course Study Helper
15. IOE Network Manager
16. Image Clustering
17. Raid on Code Private(ROCOP)-A plagiarism Detection System
18. Facial Composition using Interactive Genetic Algorithm
19. Low Resolution Image Enhancement System
20. Speaker Verification for Remote Authentication
21. Machine Learning Network Security
22. P2P Live Video Conferencing
23. Short Term Electrical Load Using Artificial Neural Network
24. Travel Planner
25. Banking Analytics
26. Event Log Classification
27. QuickRead
28. Devanagari Optical Character Recognition(D-OCR)
29. A Mobile Application Controlled by Camera Movement
30. Appresing tweets based on google hot trends- A tweet missing and view analysis
31. Voice of the voiceless(Nepali sign language to speech convertor)
32. Host Based Intrusion Detection System
33. Tele Tutor
34. Adult Image Detection
35. MIS of doece Pulchowk campus
36. AHP Based Multicriteria Decision Support System
37. Irish Recognition and Identification System
38. Intelligent Network Intrusion Detection System
39. Automatic Speaker Recognition System
40. Vehicle Fare Generation using Map Processing
41. IPv6 Tunneling with embedded authenticate system
42. Intelligent Heart Attack Predictor
43. Dynamic Knowledge Based Search Engine
44. Semanticpedia-data linking and searching through semantic technology
45. Network Traffic Shaping
Minor Projects-2068
1. EasySync
2. Social Linked Data Management System
3. Sketch Pad
4. Credit Information Bureau (CIB) information system
5. Clipboard Manager
6. Online Assignment Submitter
7. IOE Pulchowk Website (pcampus.edu.np)
8. File clustering and content-based searching
9. Digital Library System
10. GBT (GPS Based Travel)
11. Sampaadak
12. Smart News Aggregation
13. Virtual classroom
14. Easy Cash (personal expense manager)
15. Social software client
Other Projects


1. Attendance Management System
2. Automation of Stock market operations
3. IR Based video streaming on mobile phones
4. Online recruitment system(ORS)
5. College management software
6. Online Help Desk (OHD) for the facilities in the campus
7. Pocket Dictionary
8. Voice over IP
9. Virtual Router
10. Canteen Automation
11. Billing Systems
12. Discussion Forums
13. Spam filter for Search Engine
14. Online Auctioning Shop for a campus/organization
15. File system simulation
16. Intelligent car transportation system
17. Online Library management System
18. Online Sales and Inventory management System
19. Safe and secure Internet banking system
20. Online application for the Training and Placement Dept. of the college
21. Student Project Allocation management with online Testing System (SPM)
22. Online Tickets reservation system for Cinema halls.
23. Time table generation system for a college
24. Defect Tracking System (DTS)
25. Online Auction System
26. Budget Approval System
27. Online Learning System
28. Online Health Monitoring System
29. Text to Speech Technology
30. Virtual Class Room
31. Graphical Representation Of Online Shares & Stocks
32. Smart Device Controller
33. Intrusion Detection System & Bandwidth Limitation
34. Optical Character Recognition system
35. Voice Controlled application for blinds
36. Task Management System
37. Image Processing Techniques for the Detection and Removal of Cracks in Digitized Paintings
38. Online Handwritten Script Recognition
39. Workflow Mining: Discovering Process Models from Event Logs
40. Neural Network-Based Face Detection
41. Retrieving Files Using Content Based Searching and presenting it in Carousel view
42. Dynamic Signature Verification Using Pattern Recognition
43. Digital Water Marking For Video Piracy Detection
44. Shortest Node Finder In Wireless Ad-Hoc Networks
45. Image Stream Transfer Using Real-Time Transmission Protocol
46. Hiding binary data in HTML documents
47. Call Center Management System
48. Election software
49. Online Customer Care
50. Truth Discovery with Multiple Conflicting Information Providers on Web
51. Modeling & Automated Containment of Worms
52. Credit Card Fraud Detection Using Hidden Markov Models
53. Modern English Spell Checking tool Design & Implementation
54. E-Commerce Shopping cart for B2B Implementation
55. Advanced instant Messenger & Message Broadcasting
56. Secure Electronic Transaction System
57. ATM (Automated Teller Machine) Simulator for  Banking System
58. Data Recovery Using Trap Architecture a Java Project.
59. Suspicious e-mail Detection Java Project
60. Employee Attendance Monitoring System Project
61. Online Examination Test Generator
62. Corporate Address Book
63. Telephone Billing System
Some Project Areas:
· Mobile Computing
· Networking
· Secure Computing
· Wireless Communication
· ADHOC / MANETS / Mesh Networks
· Grid Computing
· Image Processing
· Pattern Analysis
· Network Security
· Wireless Sensor Networks
· Data Mining
· Cryptography
· Learning Technologies
· Multimedia
· Knowledge and Data Engineering
· Web Applications
· Information Forensics and Security
· Communication Systems

SOURCE CODE FOR GAUSS ELIMINATION METHOD FOR FINDING THE SOLUTION OF LINEAR EQUATION


Gauss elimination method is one of the method of finding the solution of linear equationsin terms of matrix.
At first the equations are written in the form of matrix.Then the equations are solved.

HERE IS THE SOURCE CODE:



#include<stdlib.h>
#include<stdio.h>
#include<math.h>
int main()
{
        float **a,*temp,app,sum,mult;
        int i,j,k,n,p;
//take no of terms
        printf("Enter n : ");scanf("%d",&n);
//memory allocation
        a = (float**)malloc(n*sizeof(float*));
        for(i = 0; i < n; i++)
            a[i] = (float*)malloc(n*sizeof(float));
        temp = (float*)malloc(n*sizeof(float));
//take input from user
        printf("Enter the elements of augmended matrix rowwise\n");
        for(i=0;i<n;i++)
            for(j=0;j<=n;j++)
                scanf("%f",&a[i][j]);
//generation of scalar matrix
       for(i=0;i<(n);i++){
            app = a[i][i];
//initialization of p
            p = i;
//find largest no of the columns and row no. of largest no.
            for(k = i+1; k < n; k++)
            if(fabs(app) < fabs(a[k][i])){
               app = a[k][i] ;
               p = k;
            }
//swaping the elements of diagonal row and row containing largest no
            for(j = 0; j <= n; j++)
            {
                temp[j] = a[p][j];
                a[p][j] = a[i][j];
                a[i][j] = temp[j];
            }
//calculating triangular matrix
            for(j=i+1;j<n;j++){
                mult = a[j][i]/a[i][i];
                for(k=0;k<=n;k++)
                    a[j][k] -= mult*a[i][k];
            }
       }
//for calculating value of z,y,x via backward substitution method
        for(i=n-1;i>=0;i--)
        {
            sum = 0;
            for(j=i+1;j<n;j++)
                sum += a[i][j]*temp[j];
            temp[i] = (a[i][n]-sum)/a[i][i];
        }
        printf("****The matrix is : ***\n");
        for(i=0;i<n;i++){
            for(j=0;j<=n;j++)
                printf("%.2f\t",a[i][j]);
            printf("\n");
        }
//display solution
        printf("-------------The solution is ----------\n");
        for(i=0;i<n;i++)
        printf("X[%d] = %.2f\n",i+1,temp[i]);
//free allocated memory
        for(i = 0; i < n; i++)
            free(a[i]);
        free(a);
        free(temp);
    return 0;
}

NEWTON'S BACKWARD INTERPOLATION TABLE GENERATION SOURCE CODE IN NUMERICAL METHOD


Here is the source code for the generation of backward interpolation sourcecode.
note:   The IDE used is codeblocks andcode  is in C language format.so the file must be saved in .c format

+++++++++++++++++++
#include<stdio.h>
#include
<math.h>
int main()

{
    float x[10],y[15][15];
    int n,i,j;
//no. of items
    printf("Enter n : ");
    scanf("%d",&n);
    printf("X\tY\n");
    for(i = 0;i<n;i++){
            scanf("%f %f",&x[i],&y[i][0]);
    }
    //forward difference table
    for(j=1;j<n;j++)
        for(i=0;i<(n-j);i++)
            y[i][j] = y[i+1][j-1] - y[i][j-1];
    printf("\n***********Forward Difference Table ***********\n");
//display Forward Difference Table
    for(i=0;i<n;i++)
    {
        printf("\t%.2f",x[i]);
        for(j=0;j<(n-i);j++)
            printf("\t%.2f",y[i][j]);
        printf("\n");
    }
    //backward difference table
    for(j=1;j<n;j++)
//for j = 0 initially input is taken so we start from j=1
        for(i=n-1;i>(j-1);i--)
            y[i][j] = y[i][j-1] - y[i-1][j-1];
    printf("\n***********Backward Difference Table ***********\n");
//display Backward Difference Table
    for(i=0;i<n;i++)
    {
        printf("\t%.2f",x[i]);
        for(j=0;j<=i;j++)
            printf("\t%.2f",y[i][j]);
        printf("\n");
    }
return 0;
}

Saturday, June 2, 2012

CODE FOR DRAWING A 3d CUBE IN GRAPHICS WITH C++ BUILDER


in drawing a 2d object ,it is easy and can be done simply by joining lines.However 3d drawing is not as easy as 2d.we must be aware of projection in this case .At  first 3d object's coordinate should be given and this coordinate is projected in to 2d ,Thus we see a 3d view in a 2d plane.


HERE IS THE SOURCE CODE FOR DRAWING 3D CUBE

/////  This code is for initializing structure//////

struct point
{
int x;
int y;
int z;
};

struct point1
{
float x;
float y;
float z;
}

////  rotation of the 3d point////
point yrotate(point p1,int theta)
{
point p3; float angle;
angle=M_PI*theta/180;
p3.x=p1.x*cos(angle)+p1.z*sin(angle);
p3.y=p1.y;
p3.z=-p1.x*sin(angle)+p1.z*cos(angle);
return(p3);
}


///projectiion of 3d to 2d////
 point projection(float x_angle,float y_angle,float z_angle,point p1)
{
    float x1,y1;
    float horz_scale=0.4;
 float vert_scale=0.4;


 x_angle=M_PI*(x_angle)/180;
 y_angle=M_PI*(y_angle)/180;
 z_angle=M_PI*(z_angle)/180;

 x1=p1.x*cos(x_angle)+p1.y*cos(y_angle)+p1.z*cos(z_angle);
 y1=p1.x*sin(x_angle)+p1.y*sin(y_angle)+p1.z*sin(z_angle);

   p1.x=x1*horz_scale;
   p1.y=y1*vert_scale;
   return(p1);
   }



////// here you can form button of any name and include the following code inside it.Here i have formed  a button name drawClick ,You can give any name and include it/////

void __fastcall TForm1::drawClick(TObject *Sender)
{
point p1,p2,p3,p4,p5,p6,p7,p8,p;
float i1[700],i2[700],intensity;float color;
int deno;
p1.x=200;//{200;200;500};
p1.y=200;
p1.z=500;
p2.x=200;//{200,200,200};
p2.y=200;
p2.z=200;
p3.x=200;//{200,500+100,200};
p3.y=600;
p3.z=200;
p4.x=200;//{200,500+100,500};
p4.y=600;
p4.z=500;

p6.x=500+100;//{500+100,200,500};
p6.y=200;
p6.z=500;
p5.x=500+100;//{500+100,500+100,500};
p5.y=620;
p5.z=500;
p7.x=500+100;//{500+100,200,200};
p7.y=500;
p7.z=200;

p8.x=600;
p8.y= 200;
p8.z= 200;


//assigning intensity levels
i1[0]=1;i2[0]=.5;
i1[p4.y-p1.y]=.2;i2[p3.y-p2.y]=0.2;
for(int i=0;i<=p4.y-p1.y-1;i++)
{
i1[i+1]=i1[i]-(i1[0]-i1[p4.y-p1.y])/(p4.y-p1.y);
i2[i+1]=i2[i]-(i2[0]-i2[p3.y-p2.y])/(p3.y-p2.y);
//ListBox1->Items->Add(i2[i]);
}

for(int i=0;i<=p4.y-p1.y;i++)
{
for(int j=p1.z;j>=p2.z;j--)
{
deno=p2.z-p1.z;
intensity=(j-p2.z)*i1[i]/deno+((p1.z-j)*i2[i])/deno;
color=intensity*255;
//ListBox1->Items->Add(color);

color=abs(color);
if(color>=255)color=100;
if(color<=40)color=004;
p.x=p1.x;p.y=i+p1.y;p.z=j;
p=projection(0,90,45,p);
Canvas->Pixels[p.x][p.y]=RGB(200,color,color);
//Form1->Caption=i;
}
}

//front face

i1[0]=1;i2[0]=.5;
i1[p4.y-p1.y]=.2;i2[p5.y-p6.y]=0.2;
for(int i=0;i<=p4.y-p1.y-1;i++)
{
i1[i+1]=i1[i]-(i1[0]-i1[p4.y-p1.y])/(p4.y-p1.y);
i2[i+1]=i2[i]-(i2[0]-i2[p5.y-p6.y])/(p5.y-p6.y);
//ListBox1->Items->Add(i2[i]);
}

for(int i=0;i<=p4.y-p1.y;i++)
{
for(int j=p1.x;j<=p6.x;j++)
{
deno=p6.x-p1.x;
intensity=(j-p1.x)*i2[i]/deno+((p6.x-j)*i1[i])/deno;
color=intensity*255;
//ListBox1->Items->Add(color);

color=abs(color);
if(color>=255)color=100;
if(color<=40)color=004;
p.x=j;p.y=i+p1.y;p.z=p1.z;
p=projection(0,90,45,p);
Canvas->Pixels[p.x][p.y]=RGB(200,color,color);
//Form1->Caption=i;
}



}




//top face

i1[0]=1;i2[0]=.5;//i1[0] at p1 and i2[0] at p6
i1[p1.z-p2.z]=.2;i2[p6.z-p7.z]=0.2;
for(int i=0;i<=p1.z-p2.z-1;i++)
{
i1[i+1]=i1[i]-(i1[0]-i1[p1.z-p2.z])/(p1.z-p2.z);
i2[i+1]=i2[i]-(i2[0]-i2[p6.z-p7.z])/(p6.z-p7.z);
//ListBox1->Items->Add(i2[i]);
}

for(int i=0;i<=p1.z-p2.z;i++)
{
for(int j=p1.x;j<=p6.x;j++)
{
deno=p6.x-p1.x;
intensity=(j-p1.x)*i2[i]/deno+((p6.x-j)*i1[i])/deno;
color=intensity*255;
//ListBox1->Items->Add(color);

color=abs(color);
if(color>=255)color=100;
if(color<=40)color=004;
p.x=j;p.y=p1.y;p.z=-i+p1.z;
p=projection(0,90,45,p);
Canvas->Pixels[p.x][p.y]=RGB(200,color,color);
}
}
}

BACK FACE DETECTION CODE IN GRAPHICS IN C++ BUILDER IDE


#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include "math.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
 int ang;

struct point
{
int x;
int y;
int z;
};


point yrotate(point p1,int theta)
{
point p3; float angle;
angle=M_PI*theta/180;
p3.x=p1.x*cos(angle)+p1.z*sin(angle);
p3.y=p1.y;
p3.z=-p1.x*sin(angle)+p1.z*cos(angle);
return(p3);
}

 point projection(float x_angle,float y_angle,float z_angle,point p1)
{
    float x1,y1;
    float horz_scale=0.4;
 float vert_scale=0.4;


 x_angle=M_PI*(x_angle)/180;
 y_angle=M_PI*(y_angle)/180;
 z_angle=M_PI*(z_angle)/180;

 x1=p1.x*cos(x_angle)+p1.y*cos(y_angle)+p1.z*cos(z_angle);
 y1=p1.x*sin(x_angle)+p1.y*sin(y_angle)+p1.z*sin(z_angle);

   p1.x=x1*horz_scale;
   p1.y=y1*vert_scale;
   return(p1);
   }

 void bhm(int x1,int y1,int x2,int y2,int col)
{
int dx,dy,p,kx,ky;
dx=abs(x1-x2);
dy=abs(y1-y2);


    p=2*dy-dx;
    Form1->Canvas->Pixels[x1][y1]=col;

        //DRAWING VERTICAL LINES
        if(dx==0)
        {
        //TO DETERMINE THE +VE OR -VE SLOPE
         ky=dy/(y2-y1);
            for(int i=0;i<=dy;i++)
            {
              Form1->Canvas->Pixels[x1][y1]=col;
            y1=y1+ky;
            }
        return;
        }

        //DRAWING HORIZONTAL LINES
        if(dy==0)
         {
        //TO DETERMINE THE +VE OR -VE SLOPE
         kx=dx/(x2-x1);
            for(int i=0;i<=dx;i++)
            {
              Form1->Canvas->Pixels[x1][y1]=col;
            x1=x1+kx;
            }
         return;
        }

        //BRESENHAM ALGORITHM FOR LINE DRAWING FOR m<1
        if(dx>dy)
        {
        //TO DETERMINE THE +VE OR -VE SLOPE
        kx=dx/(x2-x1);
        ky=dy/(y2-y1);
        for(int i=0;i<=dx;i++)
        {
        x1=x1+kx;
            if(p<0)p=p+2*dy;
            else
            {
            y1=y1+ky;
            p=p+2*dy-2*dx;
            }
          Form1->Canvas->Pixels[x1][y1]=col;
        }
        return;
        }


         //BRESENHAM ALGORITHM FOR LINE DRAWING FOR m>1
        if(dx<dy)
       {
       p=2*dx-dy;

       //TO DETERMINE THE +VE OR -VE SLOPE
        kx=dx/(x2-x1);
        ky=dy/(y2-y1);
        for(int i=0;i<=dy;i++)
        {
        y1=y1+ky;
            if(p<0)p=p+2*dx;
            else
            {
            x1=x1+kx;
            p=p-2*dy+2*dx;
            }
          Form1->Canvas->Pixels[x1][y1]=col;
        }
        }

        if(dx==dy)
        {
            for(int i=0;i<=dy;i++)
            {
            //TO DETERMINE THE +VE OR -VE SLOPE
            kx=dx/(x2-x1);
            ky=dy/(y2-y1);
            y1=y1+ky;
            x1=x1+kx;
              Form1->Canvas->Pixels[x1][y1]=col;
            }
        return;
        }
    }
void __fastcall TForm1::zbufferClick(TObject *Sender)
{
Form1->Refresh();
ang+=10;
point p1,p2,p3,p4,p5,p6,p7,p8;
float ak1,ak2,ai1,ai2,aj1,aj2,bk1,bk2,bi1,bi2,bj1,bj2,ck1,ck2,ci1,ci2,cj1,cj2,dk1,dk2,di1,di2,dj1,dj2;
int diffx,diffy,x1,x2,x3,y1,y2,y3,z1,z2,z3;float checkx,checky,checkz;
p1.x=200;//{200;200;500};
p1.y=200;
p1.z=500;
p2.x=200;//{200,200,200};
p2.y=200;
p2.z=200;
p3.x=500;//{500,200,500};
p3.y=200;
p3.z=500;
p4.x=500;//{500,500,500};
p4.y=500;
p4.z=500;
p5.x=500;//{500,200,200};
p5.y=200;
p5.z=200;
p6.x=500;//{500,500,200};
p6.y=500;
p6.z=200;
p7.x=200;//{200,500,200};
p7.y=500;
p7.z=200;
p8.x=200;//{200,500,500};
p8.y=500;
p8.z=500;
p1=yrotate(p1,ang);
p2=yrotate(p2,ang);
p3=yrotate(p3,ang);
p4=yrotate(p4,ang);
p5=yrotate(p5,ang);
p6=yrotate(p6,ang);
p7=yrotate(p7,ang);
p8=yrotate(p8,ang);

p1=projection(0,90,20,p1);//oblique projection
p2=projection(0,90,20,p2);
p3=projection(0,90,20,p3);
p4=projection(0,90,20,p4);
p5=projection(0,90,20,p5);
p6=projection(0,90,20,p6);
p7=projection(0,90,20,p7);
p8=projection(0,90,20,p8);

diffx=p1.x-200;//translation for rotation about fixed point
diffy=p1.y-200;
p1.x=200;p1.y=200;
p2.x=p2.x-diffx;p2.y=p2.y-diffy;
p3.x=p3.x-diffx;p3.y=p3.y-diffy;
p4.x=p4.x-diffx;p4.y=p4.y-diffy;
p5.x=p5.x-diffx;p5.y=p5.y-diffy;
p6.x=p6.x-diffx;p6.y=p6.y-diffy;
p7.x=p7.x-diffx;p7.y=p7.y-diffy;
p8.x=p8.x-diffx;p8.y=p8.y-diffy;


x1=p1.x;y1=p1.y;z1=p1.z;
x2=p3.x;y2=p3.y;z2=p3.z;
x3=p4.x;y3=p4.y;z3=p4.z;

ak1=(float)y1*(z2-z3)+y2*(z3-z1)+y3*(z1-z2);
bk1=(float)z1*(x2-x3)+z2*(x3-x1)+z3*(x1-x2);
ck1=(float)x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);
dk1=(float)-x1*(y2*z3-y3*z2)-x2*(y3*z1-y1*z3)-x3*(y1*z2-y2*z1);

x1=p6.x;y1=p6.y;z1=p6.z;
x2=p7.x;y2=p7.y;z2=p7.z;
x3=p2.x;y3=p2.y;z3=p2.z;


ak2=(float)y1*(z2-z3)+y2*(z3-z1)+y3*(z1-z2);
bk2=(float)z1*(x2-x3)+z2*(x3-x1)+z3*(x1-x2);
ck2=(float)x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);
dk2=(float)-x1*(y2*z3-y3*z2)-x2*(y3*z1-y1*z3)-x3*(y1*z2-y2*z1);

x1=p1.x;y1=p1.y;z1=p1.z;
x2=p3.x;y2=p3.y;z2=p3.z;
x3=p5.x;y3=p5.y;z3=p5.z;


aj1=(float)y1*(z2-z3)+y2*(z3-z1)+y3*(z1-z2);
bj1=(float)z1*(x2-x3)+z2*(x3-x1)+z3*(x1-x2);
cj1=(float)x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);
dj1=(float)-x1*(y2*z3-y3*z2)-x2*(y3*z1-y1*z3)-x3*(y1*z2-y2*z1);

x1=p8.x;y1=p8.y;z1=p8.z;
x2=p4.x;y2=p4.y;z2=p4.z;
x3=p6.x;y3=p6.y;z3=p6.z;

aj2=(float)y1*(z2-z3)+y2*(z3-z1)+y3*(z1-z2);
bj2=(float)z1*(x2-x3)+z2*(x3-x1)+z3*(x1-x2);
cj2=(float)x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);
dj2=(float)-x1*(y2*z3-y3*z2)-x2*(y3*z1-y1*z3)-x3*(y1*z2-y2*z1);

x1=p3.x;y1=p3.y;z1=p3.z;
x2=p5.x;y2=p5.y;z2=p5.z;
x3=p6.x;y3=p6.y;z3=p6.z;

ai1=(float)y1*(z2-z3)+y2*(z3-z1)+y3*(z1-z2);
bi1=(float)z1*(x2-x3)+z2*(x3-x1)+z3*(x1-x2);
ci1=(float)x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);
di1=(float)-x1*(y2*z3-y3*z2)-x2*(y3*z1-y1*z3)-x3*(y1*z2-y2*z1);

x1=p7.x;y1=p7.y;z1=p7.z;
x2=p8.x;y2=p8.y;z2=p8.z;
x3=p1.x;y1=p1.y;z1=p1.z;

ai2=(float)y1*(z2-z3)+y2*(z3-z1)+y3*(z1-z2);
bi2=(float)z1*(x2-x3)+z2*(x3-x1)+z3*(x1-x2);
ci2=(float)x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2);
di2=(float)-x1*(y2*z3-y3*z2)-x2*(y3*z1-y1*z3)-x3*(y1*z2-y2*z1);

if(ai1==0)ai1=0.00000001;
if(ai2==0)ai2=0.00000001;
if(ck2==0)ck2=0.00000001;
if(ck1==0)ck1=0.00000001;

checkz=((ak2/ck2)-(ak1/ck1))*200+((bk2/ck2)-(bk1/ck1))*200-(dk1/ck1)+(dk2/ck2);
checky=((aj2/bj2)-(aj1/bj1))*200+((cj2/bj2)-(cj1/bj1))*200-(dj1/bj1)+(dj2/bj2);
checkx=((ci2/ai2)-(ci1/ai1))*200+((bi2/ai2)-(bi1/ai1))*200-(di1/ai1)+(di2/ai2);
//Form1->Caption=checkx;

if(checkz>0)
{

bhm(p1.x,p1.y,p3.x,p3.y,clBlue);
bhm(p3.x,p3.y,p4.x,p4.y,clBlue);
bhm(p4.x,p4.y,p8.x,p8.y,clBlue);
bhm(p8.x,p8.y,p1.x,p1.y,clBlue);

 int diffi=p8.y-p1.y;

for(int i=0;i<=diffi;i++)

{
bhm(p1.x,p1.y+i,p3.x,p3.y+i,clGreen);
}


}

if(checkx<0&&(int)checkx!=-1461&& (int)checkx!=-635&&(int)checkx!=-352&&(int)checkx!=-217)
{


bhm(p3.x,p3.y,p5.x,p5.y,clBlue);
bhm(p5.x,p5.y,p6.x,p6.y,clBlue);
bhm(p6.x,p6.y,p4.x,p4.y,clBlue);
bhm(p4.x,p4.y,p3.x,p3.y,clBlue);
 int diffi=p4.y-p3.y;
for(int i=0;i<=diffi;i++)
{
bhm(p3.x,p3.y+i,p5.x,p5.y+i,clBlue);
}


}
if(checky>0)
{
bhm(p8.x,p8.y,p4.x,p4.y,clBlue);
bhm(p4.x,p4.y,p6.x,p6.y,clBlue);
bhm(p6.x,p6.y,p7.x,p7.y,clBlue);
bhm(p7.x,p7.y,p8.x,p8.y,clBlue);




 int diffi=p8.x-p7.x;
for(int i=0;i<=20;i++)
{
bhm(p8.x-i,p8.y,p1.x-i,p1.y,clRed);
}
}

if(checkz<0)
{
bhm(p6.x,p6.y,p7.x,p7.y,clBlue);
bhm(p7.x,p7.y,p2.x,p2.y,clBlue);
bhm(p2.x,p2.y,p5.x,p5.y,clBlue);
bhm(p5.x,p5.y,p6.x,p6.y,clBlue);
  int diffi=p6.y-p5.y;

for(int i=0;i<=diffi;i++)

{
bhm(p5.x,p5.y+i,p2.x,p2.y+i,clGreen);
}

}

if(checkx>0&&checkx!=426971993473024&&checkx!=428400002990080&& (int)checkx!=764&&(int)checkx!=405&&(int)checkx!=273&&(int)checkx!=199)
{
bhm(p7.x,p7.y,p8.x,p8.y,clBlue);
bhm(p8.x,p8.y,p1.x,p1.y,clBlue);
bhm(p1.x,p1.y,p2.x,p2.y,clBlue);
bhm(p2.x,p2.y,p7.x,p7.y,clBlue);
int diffi=p7.y-p2.y;

for(int i=0;i<=diffi;i++)

{
bhm(p2.x,p2.y+i,p1.x,p1.y+i,clBlue);
}

}


if(checkx==426971993473024||checkx==428400002990080|| (int)checkx==764||(int)checkx==405||(int)checkx==273||(int)checkx==199)
 {
    bhm(p3.x,p3.y,p5.x,p5.y,clBlue);
bhm(p5.x,p5.y,p6.x,p6.y,clBlue);
bhm(p6.x,p6.y,p4.x,p4.y,clBlue);
bhm(p4.x,p4.y,p3.x,p3.y,clBlue);
 int diffi=p4.y-p3.y;
for(int i=0;i<=diffi;i++)
{
bhm(p3.x,p3.y+i,p5.x,p5.y+i,clBlue);
}

 }
 if((int)checkx==-1461|| (int)checkx==-635||(int)checkx==-352||(int)checkx==-217)

  {
    bhm(p7.x,p7.y,p8.x,p8.y,clBlue);
bhm(p8.x,p8.y,p1.x,p1.y,clBlue);
bhm(p1.x,p1.y,p2.x,p2.y,clBlue);
bhm(p2.x,p2.y,p7.x,p7.y,clBlue);
int diffi=p7.y-p2.y;

for(int i=0;i<=diffi;i++)

{
bhm(p2.x,p2.y+i,p1.x,p1.y+i,clBlue);
}

  }

if(checky<0)
{
Form1->Caption=p1.z;
;
bhm(p1.x,p1.y,p3.x,p3.y,clBlue);
bhm(p3.x,p3.y,p5.x,p5.y,clBlue);
bhm(p5.x,p5.y,p2.x,p2.y,clBlue);
bhm(p2.x,p2.y,p1.x,p1.y,clBlue);


Form1->Canvas->MoveTo(p1.x,p1.y);
Form1->Canvas->LineTo(p5.x,p5.y);
Form1->Canvas->MoveTo(p2.x,p2.y);
Form1->Canvas->LineTo(p3.x,p3.y);
Form1->Canvas->MoveTo((p1.x+p3.x)/2,(p1.y+p3.y)/2);
Form1->Canvas->LineTo((p2.x+p5.x)/2,(p2.y+p5.y)/2);
Form1->Canvas->MoveTo((p2.x+p1.x)/2,(p2.y+p1.y)/2);
Form1->Canvas->LineTo((p3.x+p5.x)/2,(p3.y+p5.y)/2);



}





}

ELIZA SOFTWARE FOR ARTIFICIAL INTILLIGENCE


ELIZA emulates a Rogerian psychotherapist.

ELIZA has almost no intelligence whatsoever, only tricks like string substitution and canned responses based on keywords. Yet when the original ELIZA first appeared in the 60's, some people actually mistook her for human. The illusion of intelligence works best, however, if you limit your conversation to talking about yourself and your life.

This javascript version of ELIZA was originally written by Michal Wallace and significantly enhanced by George Dunlop.

You can get the details and download the  eliza software here
CLICK HERE

Eliza AI software 2.0 here