10
INDEX S.No Name of the practical Page no. Signature 1. Programming inMATLAB:Introduction ,Branchin g statements, loops, functions, additional data types, plots, arrays. 2-19 a WAP for multiplication of 2 matrices 20 b. WAP to find the area of circle if r=π 1/3 -1 21 c. WAP for addition of 2 matrices 21 d. Evaluate sin(π/6)+cos(π/3). 22 e. Evaluate e 3 and e π . 22 f WAP to plot a circle 23 g WAP to plot a cycloid 23 h Plot a simple sine cusine y=sin(x),0≤x≤2π taking 100 linearly spaced points. 24 i Use the relational operators in MATLAB 25 j Plot a 3D circular Helix 26 k Write a script file or function file for Y={15√(4x) +10, for x≥9 10x+10 ,for 0≤x<9, 10 ,for x<0} 27

SM File Final

Embed Size (px)

Citation preview

Page 1: SM File Final

INDEXS.No Name of the practical Page no. Signature

1. Programming inMATLAB:Introduction ,Branching statements, loops, functions, additional data types, plots, arrays.

2-19

a WAP for multiplication of 2 matrices 20

b. WAP to find the area of circle if r=π1/3-1 21

c. WAP for addition of 2 matrices 21

d. Evaluate sin(π/6)+cos(π/3). 22

e. Evaluate e3 and eπ. 22

f WAP to plot a circle 23

g WAP to plot a cycloid 23

h Plot a simple sine cusine y=sin(x),0≤x≤2π taking 100 linearly spaced points.

24

i Use the relational operators in MATLAB 25

j Plot a 3D circular Helix 26

k Write a script file or function file for Y={15√(4x) +10, for x≥9 10x+10 ,for 0≤x<9, 10 ,for x<0}

27

2 Practical implementation of single server queue simulation in C++.

3. Introduction to Network Simulators

Page 2: SM File Final

2.Single Server Queue Simulation in C++

#include "stdafx.h"#include<iostream>using namespace std;int main(){//////////// initilization variables //////////////////int n=0,n1=0; // no. of jobsint maxLength=0; // max length queue.float t=0 ; //clock or timefloat eventTime=0,totalTime=0,totalBusytime=0,totalArea=0;char eventType; //event type : Arraival or Departurefloat X=0,U=0,R=0,N=0; // Performence mesuresint nCompletion=0; // how many jobs are completed or departure .int nRejection=0 ; // how many jobs or custemers are rejected .int nArrival=0;float PreEventTime=0;float ratioRtoA=0; // Ratio between rejected job & arrival jobs.int Eventlist=0;int i=0; // counter////////////Input & Processing Stage ////////////////////cout<<"Enter the Total Time or Stop Simulation Time : \n";cin>>totalTime;cout<<"Enter the No. of Event list : \n";cin>>Eventlist;cout<<"Enter the No. of jobs or custemers : \n";cin>>n1;cout<<"Enter the maximume no. of custemers : \n";cin>>maxLength;while(i<Eventlist) // while the event list is not empty{cout<<"Enter the event type A for 'Arraival' or D 'for 'Departure' \n";cin>>eventType;cout<<"Enter the event time \n";cin>>eventTime;PreEventTime=t; // time advanced algorithmt=eventTime;if(n>0) // server status is busy{totalBusytime=totalBusytime+(t-PreEventTime);totalArea=totalArea+(t-PreEventTime)*n ;cout<<"busy time "<<totalBusytime<<" Area="<<totalArea<<endl;}else { cout<< " the server is Idle \n"; }if(eventType=='A' || eventType=='a'){if(n<maxLength){ n++;nArrival++; }

Page 3: SM File Final

else {cout<<"Alert ! the job is rejected \n";nRejection++ ; }}else if(eventType=='D' || eventType=='d'){n--;nCompletion++;cout<<"No. of completion=" <<nCompletion<<endl;}else { cout<<"Please Re Enter Event Time (A or D ) \n " ;}i++; //loop end}///////////////////// RESULTS //////////////////////////////X=nCompletion/totalTime; // throughputN=totalArea/totalTime; // average length queueR=N/X; // response timeU=totalBusytime/totalTime; // utilizationratioRtoA=(nRejection/nArrival)*100 ;cout<<"TotalBusytime = " <<totalBusytime<<endl;cout<<"Throughput = " <<X<<endl;cout<<"Average length queue = "<<N<<endl;cout<<"Response Time = " <<R<<endl;cout<<"Utilization = " <<U<<endl;cout<<"Ratio between Rejection jobs and Arrival % = " <<ratioRtoA<<endl;cout<<"Total time = "<<totalTime<<endl;cout<<"t="<<t<<endl;cout<<"Total Area="<<totalArea<<endl;system("PAUSE");return 0;

}

Page 4: SM File Final
Page 5: SM File Final

3. Introduction to Network Simulators

The network simulator is discrete event packet level simulator. The network simulator covers a very large number of applications of different kind of protocols of different network types consisting of different network elements and traffic models. Network simulator is a package of tools that simulates behaviour of networks such as creating network topologies, log events that happen under any load, analyze the events and understand the network.

Platform required running network simulator

Unix and Unix like systems Linux (Use Fedora or Ubuntu versions) Windows 95/98/NT/2000/XP

Backend Environment of Network Simulator

Network Simulator is mainly based on two languages .They are C++ and OTcl. OTcl is the object oriented version of Tool Command language .The network simulator is a bank of of different network and protocol objects. C++ helps in the following way:

It helps to increase the efficiency of simulation. It is used to provide details of the protocols and their operation. It is used to reduce packet and event processing time.

Otcl helps in the following way:

With the help of OTcl we can describe different network topologies. It helps us to specify the protocols and their applications. It allows fast development. Tcl is compatible with many platforms and it is flexible for integration. Tcl is very easy to use and it is available in free.

Basics of Tcl Programming with respect to ns2

Before we get into the program we should consider the following things:

Page 6: SM File Final

Initialization and termination aspects of network simulator. Defining the network nodes , links ,queues and topology as well. Defining the agents and their applications. Network Animator (NAM). Tracing

Initialization

To start a new simulator we write

Set ns [new Simulator]

From the above command we get that a variable ns is being initialized by using the set command. Here the code [new Simulator] is a instantiation of the class Simulator which uses the reserved word 'new'. So we can call all the methods present inside the class simulator by using the variable ns.

Creating the output files

#To create the trace files we write set tracefile1 [open out.tr w] $ns trace-all $tracefile1

#To create the nam files we write set namfile1 [open out.nam w] $ns namtrace-all $namfile

In the above we create a output trace file out.tr and a nam visualization file out.nam. But in the Tcl script they are not called by their names declared ,while they are called by the pointers initialized for them such as tracefile1 and namfile1 respectively .The line which starts with '#' are commented .The next line opens the file 'out.tr' which is used for writing is declared 'w'. The next line uses a simulator method trace-all by which we will trace all the events in a particular format.

The termination program is done by using a 'finish' procedure

# Defining the 'finish' procedure' proc finish {} { global ns tracefile1 namfile1 $ns flush-trace close $tracefile close $namfile exec namout.nam& exit 0 }

In the above the word 'proc' is used to declare a procedure called 'finish'. The word 'global' is used to tell what variables are being used outside the procedure.

Page 7: SM File Final

flush-trace' is a simulator method that dumps the traces on the respective files. The command 'close' is used to close the trace files and the command 'exec' is used to execute the name

visualization. The command 'exit' closes the application and returns 0 as zero(0) is default for clean exit.

In ns we end the program by calling the 'finish' procedure

#end the program $ns at 125.0 "finish" Thus the entire operation ends at 125 seconds. To begin the simulation we will use the command

#start the the simulation process $ns run

Defining nodes

Way to create a node: view source print? 1 set n0 [ns node]

In the above we created a node that is pointed by a variable n0.While referring the node in the script we use $n0.

NETWORK ANIMATOR (NAM)

Nam is a Tcl/TK based animation tool for viewing network simulation traces and real world packet traces. It supports topology layout, packet level animation, and various data inspection tools.

Simulation results

Two main types of simulation results

NAM files

A text file for the “nam” software The visual output of simulation Is useful for demonstration Trace files

A text file with specific format The raw data of simulation and event record

Nam: Network animator Packet level animation NS records all needed info for nam $ns namtrace-all $namFilenam reads the file and visualizes it namnamfile.nam

Page 8: SM File Final

Trace objects – For each single packet writes to trace file: – Time of arrival, sending, dropping – For links or queues Tracing of all links to one file is easy: – $ns trace-all $tf – Not for bigger simulations! Different trace objects – Trace/Enque: packet arrival (at a queue) – Trace/Deque packet departure (at a queue) – Trace/Drop packet drop (packet delivered to drop-target) – Trace/Recv packet receive event at the destination node of a link $ns create-trace {type file srcdst} Example trace file - 0.84824 2 3 tcp 1040 ------- 0 0.0 3.0 29 46 r 0.85408 2 3 tcp 1040 ------- 0 0.0 3.0 28 44 + 0.85656 2 3 tcp 1040 ------- 0 0.0 3.0 30 47 - 0.85656 2 3 tcp 1040 ------- 0 0.0 3.0 30 47 r 0.8624 2 3 tcp 1040 ------- 0 0.0 3.0 29 46 + 0.86488 2 3 tcp 1040 ------- 0 0.0 3.0 31 49 - 0.86488 2 3 tcp 1040 ------- 0 0.0 3.0 31 49 r 0.87072 2 3 tcp 1040 ------- 0 0.0 3.0 30 47 + 0.8732 2 3 tcp 1040 ------- 0 0.0 3.0 32 50 - 0.8732 2 3 tcp 1040 ------- 0 0.0 3.0 32 50 r 0.87904 2 3 tcp 1040 ------- 0 0.0 3.0 31 49 + 0.88152 2 3 tcp 1040 ------- 0 0.0 3.0 33 52 - 0.88152 2 3 tcp 1040 ------- 0 0.0 3.0 33 52 r 0.88736 2 3 tcp 1040 ------- 0 0.0 3.0 32 50 + 0.88984 2 3 tcp 1040 ------- 0 0.0 3.0 34 53