LIST OF EXPERIMENTS
S.No. Name of Experiment Page No
Write a Python Program to find the square root of a
1 number by Newton’s Method.
2 Write a Python program to find first n prime numbers
3 Linux programming Tool – Ubuntu
4 Programming in Freeware software- Linux Ubuntu
Programming and Simulation in GUI Simulators-
5
MATLAB
6 Programming & simulation in python simulator
7 Study on MATLAB simulation tools
8 Correlation of sequences on MATLAB simulation tools
9 Led blinking program using embedded c
10 Study on proteus simulation tools
11 Study on OrCAD simulation tools
EX:1 TO FIND THE SQUARE ROOT OF A NUMBER DATE:
AIM:
To write a Python Program to find the square root of a number by Newton’s
Method.
ALGORITHM:
1. Define a function named newtonSqrt().
2. Initialize approx as 0.5*n and better as 0.5*(approx.+n/approx.)
3. Use a while loop with a condition better!=approx to perform the following,
i. Set approx.=better
ii. Better=0.5*(approx.+n/approx.)
4. Print the value of approx.
PROGRAM:
Def newtonsqrt(n):
approx.=0.5*n
better=0.5*(approx.+n/approx)
While better!=approx:
approx=better
better=0.5*(approx.+n/approx.)
Return approx
Print(newtonsqrt(100))
OUTPUT:
RESULT: Thus, the Python program for finding the square root of a given number
by Newton’s Method is executed successfully and the output is verified.
EX:2 TO FIND THE FIRST N PRIME NUMBERS DATE:
AIM:
To write a Python program to find first n prime numbers.
ALGORITHM:
1. First, take the number N as input.
2. Then use a for loop to iterate the numbers from 1 to N
3. Then check for each number to be a prime number. If it is a prime number,
print it.
PROGRAM:
# Python3 program to display Prime numbers till N
#function to check if a given number is prime
def isPrime(n):
#since 0 and 1 is not prime return false.
if(n==1 or n==0): return False
#Run a loop from 2 to n-1
for i in range(2,n):
#if the number is divisible by i, then n is not a prime number.
if(n%i==0):
return False
#otherwise, n is prime number.
return True
# Driver code
N = 100;
#check for every number from 1 to N
for i in range(1,N+1):
#check if current number is prime
if(isPrime(i)):
print(i,end=" ")
OUTPUT:
RESULT: Thus the Python Program to find the first n prime numbers is executed
successfully and the output is verified.
EX :3 LINUX PROGRAMMING TOOL – UBUNTU DATE:
AIM:
Write an Ubuntu C program to print the strings.
SOFTWAREREQUIRED:
PC with Linux UBUNTU 4.10 OS.
THEORY:
Ubuntu uses Linux desktop environments for its interface. Ubuntu is an open-
source operating system (OS) based on the Debian GNU/Linux distribution.
Ubuntu incorporates all the features of a Unix OS with an added customizable
GUI, which makes it popular in universities and research organizations. Ubuntu is
primarily designed to be used on personal computers, although a server edition
does also exist.
Ubuntu consists of many software packages, which are licensed under GNU
General Public License. This allows users to copy, change, develop and
redistribute their own version of the program. Ubuntu comes with a wide range of
software programs, including Firefox and LibreOffice. There is also proprietary
software that can be run on Ubuntu. Ubuntu consists of many software packages,
which are licensed under GNU General Public License. This allows users to copy,
change, develop and redistribute their own version of the program. Ubuntu comes
with a wide range of software programs, including Firefox and LibreOffice. There
is also proprietary software that can be run on Ubuntu.
PROCEDURE:
• Open the Linux- Ubuntu OS.
• Open the command terminal.
• Create a .c extension file in the directory path.
• C file is created in the path and double click on the program editor.
• Program editors open and write the program and save.
• Compile the output by using command gcc. -o and give name to output
file.
• Get the output by using command./
PROGRAM:
#include <stdio.h>
int main()
printf(“Hello world\n”);
return 0;
}
OUTPUT:
Hello World
RESULT: Thus, a C program to print the strings was executed successfully.
DATE:
EX:4 PROGRAMMING IN FREEWARE SOFTWARE- LINUX UBUNTU
AIM:
Write an Ubuntu C program to find the sum of numbers.
SOFTWAREREQUIRED:
PC with Linux UBUNTU 4.10 OS.
THEORY:
Freeware is software most often proprietary that is distributed at no
monetary cost to the end user. There is no agreed upon set of rights, license
or EULA that defines freeware. Every publisher defines its own rules for the
freeware it offers. For instance, modification, redistribution by third parties
and reverse engineering are permitted by some publishers but prohibited by
others.
Ubuntu uses Linux desktop environments for its interface. Ubuntu is an
open-source operating system (OS) based on the Debian GNU/Linux
distribution. Ubuntu incorporates all the features of a Unix OS with an added
customizable GUI, which makes it popular in universities and research
organizations. Ubuntu is primarily designed to be used on personal
computers, although a server edition does also exist.
Ubuntu consists of many software packages, which are licensed under GNU
General Public License. This allows users to copy, change, develop and
redistribute their own version of the program. Ubuntu comes with a wide
range of software programs, including Firefox and LibreOffice. There is also
proprietary software that can be run on Ubuntu. Ubuntu consists of many
software packages, which are licensed under GNU General Public License.
This allows users to copy, change, develop and redistribute their own
version of the program.
Ubuntu comes with a wide range of software programs, including Firefox
and LibreOffice. There is also proprietary software that can be run on
Ubuntu.
PROCEDURE:
• Open the Linux- Ubuntu OS .
• Open the command terminal.
• Create a .c extension file in the directory path.
• C file is created in the path and double click on the program editor.
• Program editors open and write the program and save.
• Compile the output by using command gcc. -o and give name to output
file.
• Get the output by using command ./
PROGRAM:
#include<stdio.h>
int main()
printf(“Enter two integer numbers:”);
scanf(“%d%d”,&n1,&n2);
sum=n1+n2;
printf(“The sum of %d and %d”,n1,n2,sum);
return 0;
}
OUTPUT:
RESULT: Thus, a C program to print the sum of numbers was executed
successfully.
DATE:
EX:5 PROGRAMMING AND SIMULATION IN GUI SIMULATORS-
MATLAB
AIM:
Write a program for GUI Simulation using MATLAB.
SOFTWARE REQUIRED:
MATLAB R2007b
THEORY:
MATLAB (Matrix Laboratory) is a software package that is widely used in
control systems design. MATLAB is a high-performance language for
technical computing. It integrates computation, visualization, and
programming environment. Furthermore, MATLAB is a modern programming
language environment: it has sophisticated data structures, contains built-in
editing and debugging tools, and supports object-oriented programming. These
factors make MATLAB an excellent tool for teaching and research.
Starting MATLAB:
Enter MATLAB by double-clicking on the MATLAB shortcut icon on your
Windows desktop. When you start MATLAB, a special window called the
MATLAB desktop appears. The desktop is a window that contains other
windows.
• The major tools within or accessible from the desktop
are:
• The Command Window
• The Command History
• The Workspace
• The Current Directory
• The Help Browser
• The Start button
GUI:
Graphical user interface, is a form of user interface that allows users to interact
with electronic devices through graphical icons and audio indicator such as
primary notation, instead of text-based UIs, typed command labels or text
navigation. GUIs were introduced in reaction to the perceived steep learning
curve of CLIs (command-line interfaces) which require commands to be typed
on a computer keyboard.
PROCEDURE:
• Open MATLAB R2007b
• Choose File ->New-> GUI for Creating a new GUI
Project
• A new window opens, Click on default GUI Project->OK
• Select appropriate tools and assign string and tag.
• Save the Project and Click Run
• Program Editor opens write the program and Run the
program
• Enter the Output and display the stimulation output.
PROGRAM:
function varargout = ink(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ink_OpeningFcn, ...
'gui_OutputFcn', @ink_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function ink_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = ink_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function textbox1_Callback(hObject, eventdata, handles)
function textbox1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function textbox3_Callback(hObject, eventdata, handles)
function textbox3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pushbutton1_Callback(hObject, eventdata, handles)
a1=str2num(get(handles.textbox1,'string'))+str2num(get(handles.textbox2,'string'))
set(handles.textbox3,'string',a1)
OUTPUT:
RESULT: Thus a program for GUI Simulation using MATLAB was executed
successfully.
DATE:
EX:6 PROGRAMMING & SIMULATION IN PYTHON SIMULATOR
AIM:
To write a python program to find sum of arrays using PyCharm IDE.
SOFTWARE REQUIRED:
PyCharm, Python 2.7.0
THEORY:
PyCharm is a dedicated Python Integrated Development Environment (IDE)
providing a wide range of essential tools for Python developers, tightly integrated
to create a convenient environment for productive Python, web, and data science
development. Python is an interpreted, interactive, object-oriented programming
language. It incorporates modules, exceptions, dynamic typing, very high level
dynamic data types, and classes. Python has packages that encapsulates different
categories of functionality in libraries.
PROCEDURE:
• Import array module
• Define a function to calculate the sum of elements in an array
• Declare a variable to store the sum and Calculate the length of the array
using Len() function
• Run a loop for all the elements in the array
• Add each element to the variable for sum one by one and Return sum
• Declare the array and Call function and execute the result
PROGRAM:
import array as ar
def SumofArray(arr):
sum=0
n=len(arr)
for i in range(n):
sum=sum+arr[i]
return sum
#input value to list
a=ar.array(‘i’,[10,21,12,13])
#displaysum
print(‘Sum of the array is’,SumofArray(a))
OUTPUT:
RESULT: Thus, a python program to find sum of arrays was executed
successfully.
EX:7 STUDY ON MATLAB SIMULATION TOOLS DATE:
AIM:
To study about the simulation in MATLAB tool.
INTRODUCTION TO MATLAB:
MATLAB is high-performance language for technical computing. It
integrates computation, visualization, and programming in an easy-to-user
environment where problems and solutions are expressed in familiar mathematical
notation. The name MATLAB stands for Matrix Laboratory. MATLAB was
written originally to provide easy access to matrix software developed by the
LINPACK (linear system package) and EISPACK (Eigen system package)
projects. MATLAB is a high-performance language for technical computing. It
integrates computation, visualization, and programming environment. MATLAB is
a modern programming language environment: it has sophisticated data structures,
contains built-in editing and debugging tools, and supports object-oriented
programming. These factors make MATLAB an excellent tool for teaching and
research. MATLAB has many advantages compared to conventional computer
languages (e.g., C, FORTRAN) for solving technical problems. MATLAB is an
interactive system whose basic data element is an array that does not require
dimensioning. It has powerful built-in routines that enable a very wide variety of
computations. It also has easy to use graphics commands that make the
visualization of results immediately available. Specific applications are collected in
packages referred to as toolbox. There are toolboxes for signal processing,
symbolic computation, control theory, simulation, optimization, and several other
fields of applied science and engineering.
OBJECTIVES:
This lab provides introduction to MATLAB and helps students developing
following skills: • Arithmetic Operations in MATLAB
Use of Complex Numbers
Array Indexing and addressing
Matrices
Control Flow in MATLAB
Plotting
Programming in MATLAB
THEORY:
MATLAB is an interactive system whose basic data element is an array that does
not require dimensioning. This allows you to solve many technical computing
problems, especially those with matrix and vector formulations, in a fraction of the
time it would take to write a program in a scalar non-interactive language such as
C or FORTRAN.
Typical uses include:
• Math and computation
• Algorithm development
• Modeling, simulation, and prototyping
• Data analysis, exploration, and visualization
• Scientific and engineering graphics
• Application development, including graphical user interface building
MATLAB BASICS
MATLAB is started by clicking the mouse on the appropriate icon and is ended by
typing exit or by using the menu option. After each MATLAB command, the
"return" or "enter" key must be depressed.
Starting MATLAB:
Enter MATLAB by double-clicking on the MATLAB shortcut icon on your
Windows desktop. When you start MATLAB, a special window called the
MATLAB desktop appears. The desktop is a window that contains other windows.
The major tools within or accessible from the desktop are:
The Command Window
The Command History
The Workspace
The Current Directory
The Help Browser
The Start button
You can customize the arrangement of tools and documents to suit your needs.
Now, we are interested in doing some simple calculations. We will assume that
you have sufficient understanding of your computer under which MATLAB is
being run. You are now faced with the MATLAB desktop on your computer,
which contains the prompt (>>) in the Command Window. Usually, there are 2
types of prompts: >> for full version EDU> for educational version.
Quitting MATLAB:
To end your MATLAB session, type quit in the Command Window, or select File
Exit MATLAB in the desktop main menu.
The graphical interface to the MATLAB workspace
Creating MATLAB variables:
MATLAB variables are created with an assignment statement. The syntax of
variable assignment is
variable name = a value (or an expression)
For example,
>> x = expression
Where expression is a combination of numerical values, mathematical operators,
variables, and function calls. On other words, expression can involve:
1. manual entry
2. built-in functions
3. user-defined functions
MATLAB features a family of application-specific solutions called toolboxes.
Toolboxes are comprehensive collections of MATLAB functions (M-files) that
extend the MATLAB environment to solve particular classes of problems. Areas in
which toolboxes are available include signal processing, control systems, neural
networks, fuzzy logic, wavelets, simulation, and many others.
RESULT: Thus, the simulation of MATLAB Tool was studied.
EX:8 CORRELATION OF SEQUENCES USING MATLAB DATE:
AIM:
To write MATLAB programs for auto correlation and cross correlation.
APPARATUS REQUIRED:
HARDWARE: COMPUTER
SOFTWARE: MATLAB
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
PROGRAM: (Cross-Correlation of the Sequences)
clc; clear
all;close
all;
x=input('Enter the sequence 1: ');
h=input('Enter the sequence 2: ');
y=xcorr(x,h);
figure;
subplot(3,1,1);
stem(x);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 1');
subplot(3,1,2);
stem(fliplr(y));
stem(h); xlabel('n-
>');
ylabel('Amplitude->');
title('Input sequence 2');
subplot(3,1,3);
stem(fliplr(y));
xlabel('n->');
ylabel('Amplitude->');
title('Output sequence');
disp('The resultant is');
fliplr(y);
OUTPUT: (Cross-Correlation of the Sequences)
Enter the sequence 1: [1 3 5 7]
Enter the sequence 2: [2 4 6 8]
PROGRAM: (Auto correlation function)
clc;
close all;
clear all;
x=input('Enter the sequence 1: ');
y=xcorr(x,x);
figure;
subplot(2,1,1)
stem(x);
ylabel('Ampli
tude->');
xlabel('n->');
subplot(2,1,2)
stem(fliplr(y));
ylabel('amplitude');
xlabel('n->');
title('Outputsequence')
disp('the resultant is ');
fliplr(y);
OUTPUT: (Auto Correlation Function)
Enter the sequence [1 2 3 4]
RESULT: Thus, the MATLAB programs for auto correlation and cross correlation
written and the results were plotted.
EX:9 LED BLINKING PROGRAM USING EMBEDDED C DATE:
AIM:
To write program for 8051 micro controller for blinking an LED using
keil software and implement it using MCBx51.
SOFTWARE REQUIRED:
Keil micro vision version3 IDE.
HARDWARE REQUIRED:
8051programmer
MCBx51developmentboard
Serial cable (RS232C)
PROCEDURE:
Open Keil Micro vision software.
Project New Project AT89C51ED2 OK.
File New.
Right click “sourcegroup1” “add files to group source group1”
select the saved file. program and save it with.c extension.
Project options for target target tab configuration dialog (set
oscillator frequency, baud rate.,).
Go to debug tab (set simulation or hardware)
Click Rebuilt and save options.
Debug start/stop debug session.
Debug Run.
Check the output at Peripherals I/O ports.
Click on stop debugging button
PROGRAM:
#include<reg51.h>
Void Delay();
void main()
{
P1=0x55;
delay ();
P1=0xAA;
Delay();
}
Void Delay()
{
TMOD=0X01;
TL0=0X00;
TH0=0X35;
TR0=1;
while(TF0== 0); TR0=0; TF0=0;
}
RESULT: Thus, embedded C program for blinking an LED using 8051
microcontroller is written and the output was successfully executed.
EX:10 STUDY ON PROTEUS SIMULATION TOOLS DATE:
AIM:
To study about the simulation in Proteus tool.
Introduction to Proteus software:
Proteus is used to simulate, design and drawing of electronic circuits. It was
invented by the LaCenter electronic.
By using proteus you can make two-dimensional circuits designs as well.
With the use of this engineering software, you can construct and simulate
different electrical and electronic circuits on your personal computers or
laptops.
There are numerous benefits to simulate circuits on proteus before make
them practically.
Designing of circuits on the proteus takes less time than practical
construction of the circuit.
The possibility of error is less in software simulation such as loose
connection that takes a lot of time to find out connections’ problems in a
practical circuit.
Circuit simulations provide the main feature that some components of
circuits are not practical then you can construct your circuit on proteus.
There is zero possibility of burning and damaging of any electronic
component in proteus.
The electronic tools that are very expensive can easily get in proteus such as
an oscilloscope.
Using proteus you can find different parents of circuits such as current, a
voltage value of any component and resistance at any instant which is very
difficult in a practical circuit.
How to Make Circuit in Proteus
Perform some steps to make a circuit.
Step 1:
First of all, click on proteus Icon in your computer and click on a new file option
Step 2:
After that, you will see the drawing sheet. Save it according to your project
Step 3:
After a move to the component option and select the elements for your
projects.
Step 4:
After clicking on components mode, you will see two buttons P and L. If
you move to P button you will see Pic from Libraries
Step 5:
When you will click on the P button you will see box. Type your component
for a circuit.
As I type button and you can see a button in right figure that different
buttons are shown you can select according to your use.
Step 6:
When you will select components for your project you will see them in a
box.
I have also selected some components for designing of a simple circuit.
Step 7:
When you connect all components in the circuit like run button in left bottom
Step 8:
When you will observe the simulation of your circuit than click on stop button
on the left bottom to stop the working of the circuit.
RESULT: Thus, the simulation of Proteus Tool was studied
EX:11 STUDY ON OrCAD SIMULATION TOOLS DATE:
AIM:
To study about the simulation in OrCAD tool.
Introduction to OrCAD
This option of OrCAD Capture is available in the START -> ALL
PROGRAM
After opening the pspice capture, click on the file menu and create a new
project by selecting File -> New -> Project
After selecting the new project option, dialog box obtained on the screen,
We can give the name of our project like here in the picture name of the
project is given as “test”.
Then we have to select any one option from the given four options according
to the need.
“Analog or Mixed A/D” is selected.
Then select the location for the project where it is to be stored. We can select
any location as per our requirement.
This is the screen where we can create our circuit & can run our circuit.
On just above the blank screen of the software, we have different options
like different types of markers, voltage and current probes, run pspice, edit
simulation settings, save the file, print option, etc.
Likewise, on the right side of the screen also we have different options.
We can select the different types of components by selecting: Place -> Part.
All these components are stored in different Libraries according to their
feature.
So in order to view all the components, first select all library function.
We can also select the components from the icons given on the right side of
the screen.
After selecting the component, we can rotate the component by -- Right
click (on the component) ->Rotate. So we can create our circuit asper our
requirement.
After selecting the components, we can connect all the components by wire
& we can complete our circuit.
The option of wire can be available by: Place -> Wire. Or it is also available
on the right side of the blank screen.
Here, we can select the simulation and analysis type is selected as ‘DC
Sweep’.
Also we can select the sweep variable, sweep type, start value, end value &
increment as per the requirement.
When we run our circuit, we can see the graph This phenomenon of running
the circuit after making it in software is known as SIMULATION.
RESULT: Thus, the simulation of OrCAD Tool was studied.