Social Icons

Sunday, 14 September 2014

Insertion Deletion In Linked List

#include<iostream>
#include<conio.h>
using namespace std;
struct link
{
int data;
struct link *next;

};

void display();
void initial();
void deletion();

struct link *newn,*loc,*start=NULL,*ptr;


int main()
{
int i,item;
for(i=1;i<5;i++)
    {
    cout<<"Enter element";
cin>>item;
newn =new struct link[1];
newn->data=item;
newn->next=NULL;


if(start==NULL)
    {
    start=newn;
    }
    else
    {
    ptr=start;
    while(ptr->next!=NULL)
    {
    ptr=ptr->next;
   
    }
   
    ptr->next=newn;
    }

 }
   
    display();
    //for(i=1;i<=2;i++)
    //{
   
initial();
//}
}





void display()
{
ptr=start;
while(ptr!=NULL)
{
cout<<ptr->data;
cout<<"-->";
ptr=ptr->next;
}


}



void initial()
{
int item;
    cout<<"Enter the item which u want to insert in begining";
    cin>>item;
   
    struct link *p;
    p=new struct link[1];
    p->data=item;
    p->next=NULL;
    if(start==NULL)
    {
    start=p;
   
    }
else
    {
      p->next=start;
 start=p;
    }

display();
deletion();
}


void deletion()
{
char c;
cout<<"do u want to delete from begining";
cin>>c;
if(c=='y')
{
start=start->next;
display();
}

}

Sunday, 4 May 2014

Gauss Elimination in Matlab

function [x] = g1(A, b)
%work out the number of equations
N = length(b)
%Gaussian elimination
for column=1:(N-1)
%work on all the rows below the diagonal element
for row = (column+1):N
%work out the value of d
d = A(row,column)/A(column,column);
%do the row operation
A(row,:) = A(row,:)-d*A(column,:)
b(row) = b(row)-d*b(column)
end%loop through rows
end %loop through columns
for row=N:-1:1
x(row) = b(row);
for i=(row+1):N
x(row) = x(row)-A(row,i)*x(i);
end
x(row) = x(row)/A(row,row);
end
return

Monte Carlo Simulation

N=input('enter no of dats');
r=4;
c=0;
for i=1:N
    x=r*rand(1);
    y=r*rand(1);
    if((x^2+y^2)<=r^2)
        c=c+1;
       
    end;
end;
n=c;
pi=(4*n)/N

Script For inverse of a matrix in Matlab

x=input('Enter a matrix 3*3')
y=input('Enter another 3*3 matrix')
s=x+y
 det=s(1,1)*(s(2,2)*s(3,3)-s(2,3)*s(3,2))-s(1,2)*(s(2,1)*s(3,3)-s(3,1)*s(2,3))+s(1,3)*(s(2,1)*s(3,2)-s(3,1)*s(2,2))
adj=[[(s(2,2)*s(3,3)-s(3,2)*s(2,3));-(s(2,1)*s(3,3)-s(3,1)*s(2,3));(s(2,1)*s(3,2)-s(3,1)*s(2,2))] [-(s(1,2)*s(3,3)-s(3,2)*s(1,3));(s(1,1)*s(3,3)-s(3,1)*s(1,3));-(s(1,1)*s(3,2)-s(3,1)*s(1,2))] [(s(2,2)*s(1,3)-s(1,2)*s(2,3));-(s(1,1)*s(2,3)-s(2,1)*s(1,3));(s(1,1)*s(2,2)-s(2,1)*s(1,2))]]
inverse=(1./det).*adj
 

Sample Text

Sample text

 
Just Programming Cse DriveReputation Management