1.0K views

Uploaded by Amit Walia

It is a file which includes all programs of matlab which are basis of matlab.I made it during my matlab course in B.tech.

- Speaker Recognition Using MATLAB
- L01_MATLAB1
- An Introduction to Ant Colony Optimization
- matlab
- speaker_recognition
- Coping With Threats Towards Speaker Recognition Systems, Spoofing Risk Minimization
- 61664272 Ant Colony Optimization
- MATLAB
- Matlab - Development of Neural Network Theory for Artificial Life-Thesis_ MATLAB and Java Code
- Lab Exp 1
- Experiment 01
- fingerprintRecognition
- Spatial Filtering Image Processing
- matlab ga
- skripsi
- Engg100 Project 08 h
- report
- Proces Wp007 en p
- Introduction Matlab
- Digital Image Processing MATLAB Notes

You are on page 1of 19

COLLEGE SUNDERNAGAR

PRACTICAL FILE

ON MATLAB

BRANCH -ECE

4TH SEM

B.TECH

2012

LIST OF EXPERIMENTS: i) Roots of a quadratic equation. ii) Guessing a number. iii) Units conversion. iv) Factorial Program v) Simulation of an RC circuit. vi) I-V characteristic of a MOSFET. vii) Finding average with a dynamic array. viii) Writing a binary file. ix) Reading a binary file. x) Plotting one and two-dimensional graphs using various MATLAB 2-D Plot types. xi) Using functions in MATLAB environment.

MATLAB Environment

The MATLAB high-performance language for technical computing integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include

Math and computation Algorithm development Data acquisition Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including graphical user interface building

MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. It 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. The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the state of the art in software for matrix computation. MATLAB has evolved over a period of years with input from many users. In university environments, it is the standard

instructional tool for introductory and advanced courses in mathematics, engineering, and science MATLAB features a family of add-on application-specific solutions called toolboxes. Very important to most users of MATLAB, toolboxes allow you to learn and apply specialized technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. You can add on toolboxes for signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many other areas. Relational Operators < > <= >= == ~=

Relational operators compare operands quantitatively, using operators like "less than" and "not equal to"

Relational operations Syntax < <= > >= == ~= Less than Less than or equal to Greater than Greater than or equal to Equal to Not equal to

Arithmetic operators perform numeric computations.

Syntax

+ .* ./ .\ + : .^ .' ' * / \ ^

Addition Subtraction Multiplication Right division Left division Unary plus Unary minus Colon operator Power Transpose Complex conjugate transpose Matrix multiplication Matrix right division Matrix left division Matrix power

MATLAB offers three types of logical operators and functions:

Element-wise operate on corresponding elements of logical arrays. Bit-wise operate on corresponding bits of integer values or arrays. Short-circuit operate on scalar, logical expressions.

Syntax

Aim 1: Program for generation of sin, cos, impulse, ramp, exponential wave.{2-D plots}

A.

%program for generation of sin wave clear all; close all; t=0:.04:pi; y=sin(2*pi*t); subplot(2,2,1); stem(t,y); xlabel('time'); ylabel('amplitude');

clear all; close all; t=0:.04:pi; y=cos(2*pi*t); subplot(2,2,1); stem(t,y); xlabel('time'); ylabel('amplitude');

C. %program for generation of impulse signal clear all; close all; t=-2:1:2; y=[zeros(1,2),ones(1,1),zeros(1,2)]; subplot(2,2,1); stem(t,y); xlabel('time'); ylabel('amplitude');

D. %program for generation of exponential signal n=input('enter the length of exponential sequence') t=0:0.1:n; y=exp(t); subplot(2,2,1); stem(t,y); ylabel('amplitude'); xlabel('time');

close all; n1=input('enter the length of ramp sequence'); t=0:.1:n1; a=input('enter value of slope'); y=a*t; subplot(2,2,1); stem(t,y); ylabel('amplitude'); xlabel('time');

Aim 2: Program to find roots of quadratic equation. a=input('enter the value of a='); b=input('enter the value of b='); c=input('enter the value of c='); x=b^2-4*a*c; x1=sqrt(x); r1=(-b+x1)/(2*a) r2=(-b-x1)/(2*a)

Aim 3: Program to find factorial of a given number . function factn=factorial(n) a=input('Enter the number whose factorial you want ') ; if a>=0 factn=1; for k=a:-1:1 factn=factn*k; end else if a<0 fprintf('Number you entered is not positive \n'); end end Aim 4: Program for unit conversion . c=[2;3]; f=(9/5)*c+32; k=c+273; tempcon=[c f k] Aim 5: Program for guessing a number. a=rand(1)*10; n=round(a); b=input('enter number between 1&10'); while (n~=b) %do while loop if (b<n) disp('number is less than computer has genrated'); end if (b>n) disp('number is greater than computer has genrated'); end b=input('enter number between 1&10'); end

disp('number is right'); Aim 6: Program for simulation of R-C circuit. vcf=5;r=1000;c=1e-6;to=0.0015;tf=0.008;vci=0; t=linspace(0,tf,1000); vc=zeros(1,1000) for i=1:1000; if t(i)<to vc(i)=vci; else vc(i)=vcf+(vci-vcf)*exp(-(t(i)-to)/(r*c)); end end plot(t*1000,vc); title('rc step response.'); ylabel('capacitor voltage(volts)'); xlabel('time(milliseconds)'); grid

Aim 7: Program using functions in MATLAB environment. FUNCTIONS: These take inputs and return outputs .These are saved by extension .m. We shall start with a very simple example:

1.

The first line of xsq.m tells us this is a function called xsq which takes an input called input and returns a value called output.

The second line of this function actually performs the calculation, in this case squaring the value of the input, and storing this result in the variable output. Having written our function we can now access it from within MATLAB

x = 1:10; y = xsq(x)

2.

Suppose we now want to construct the squares and cubes of the elements of a vector. function [sq,cub] = xpowers(input) sq = input.2; cub = input.3; This function file must be saved as xpowers.m and it can be called as follows:

Aim 8: Plotting two-dimensional graphs using various MATLAB 2-D Plot types. plot(x,y): Plots the values in vector y versus x. Plot produces a piecewise linear graph between its data values.

Stem(x,y): Plots the data sequence y at the values specified in x. Xlabel('string'): Labels the x-axis with string. Ylabel('string'): Labels the y-axis with string. Title('string'): Gives the plot the title string. x = -2:0.2:2; y = x.^2; xlabel('x'); figure(1); ylabel('y=x^2'); plot(x,y); title('Simple stem plot'); xlabel('x'); ylabel('y=x^2'); title('Simple plot'); stem(x,y);

legend('plot1','plot2',...,'plot N'): The legend command provides an easy way to identify individual plots when there are more than one per figure. subplot(m,n,p): Divides the figure window into m rows, n columns and selects the pth subplot as the current plot. grid on/off: This command adds or removes a rectangular grid to your plot.

1.A.sin wave:

1.B.cos wave:

1.C.impulse signal:

1.E.Ramp signal: enter the length of ramp sequence6 enter value of slope1

OUTPUT: 2.

enter the value of a=2 enter the value of b=3 enter the value of c=4 r1 = -0.7500 + 1.1990i r2 = -0.7500 - 1.1990i

3.

Enter the number whose factorial 5 ans = 120 Enter the number whose factorial you want -9 Number you entered is not positive

4.

OUTPUT: 5.

enter number between 1 & 10 =5 number is less than computer has genrated enter number between 1 & 10 =8 number is less than computer has genrated enter number between 1 & 10 =9 number is right

6.

OUTPUT: 7.

7.1.

y= 1 4 9 16 25 36 49 64 81 100

7.2.

xsq = 1 4 9 16 25 36 49 64 81 100 xcub = Columns 1 through 7 1 8 27 64 125 216 343

- Speaker Recognition Using MATLABUploaded byMuhammad Saeed
- L01_MATLAB1Uploaded byuddanikku
- An Introduction to Ant Colony OptimizationUploaded byapi-3694045
- matlabUploaded byAshkan Abbasi
- speaker_recognitionUploaded byHussain Shareef
- Coping With Threats Towards Speaker Recognition Systems, Spoofing Risk MinimizationUploaded byNarek Petrosyan
- 61664272 Ant Colony OptimizationUploaded bySwayamsiddha Mohapatra
- MATLABUploaded byПараг Тамбе
- Matlab - Development of Neural Network Theory for Artificial Life-Thesis_ MATLAB and Java CodeUploaded byHotland Sitorus
- Lab Exp 1Uploaded byNumanAbdullah
- Experiment 01Uploaded byZeynal Abidin Şabaş
- fingerprintRecognitionUploaded byRupendra Bakoliya
- Spatial Filtering Image ProcessingUploaded bySankalp_Kallakur_402
- matlab gaUploaded bygreenday3
- skripsiUploaded byyosys
- Engg100 Project 08 hUploaded bySean Kurian George
- reportUploaded byNishil Vijayan
- Proces Wp007 en pUploaded byIkhtiander Ikhtiander
- Introduction MatlabUploaded byAditya Khedikar
- Digital Image Processing MATLAB NotesUploaded bySeun -nuga Daniel
- matlab primer introUploaded byVishalChikkerur
- Matlab Training in JalandharUploaded bye2matrix
- GENN004_Spring2012_Midterm2Uploaded byBishoy Emile
- 20121Uploaded byXfoxy Mau
- MATLAB MATLAB lab manual numerical methods and matlabUploaded byJavaria Chiragh
- Signal & sytem lab-manval (Autosaved) (Autosaved).pdfUploaded byAnonymous FEjtNQn
- Gui BuildingUploaded bynguyen1192
- Remote Process Control and Monitoring Using MatlabUploaded bysankyyy
- Introduction to MatlabUploaded byHassaan Shah

- Eigenvalues and EigenvectorsUploaded byanon_351812634
- lphc codeUploaded bySimadri Badatya
- Scipy TutorialUploaded bySyed Faisal
- Intorductory Composite Lab ReportUploaded byTory Johansen
- Mme Syllabus 2010Uploaded byDhirendraRavi
- An improved partial Haar dual adaptive filter for rapid identification of a sparse echo channelUploaded byMia Amalia
- Weighted Linear RankingUploaded byJoao bilbo
- Special MatricesUploaded byRushi Desai
- Nonlinear Aerostatic Stability Analysis of New Suspension Bridges With Multiple Spans_zhang2013Uploaded byjaswant
- Simulink IntroductionUploaded byGreen Heart
- update-on-state-estimation-based-object-oriented-dse-based-protection.pdfUploaded byKléberVásquez
- MATHS SyllabusUploaded byAndrew Nelson
- Random ConvolutionUploaded byazn
- JUJ 2008Uploaded byFatimah Abdul Khalid
- The Structure of the Color Space in Naming and Memory for Two LanguagesUploaded byhector3nu3ez
- ECE-R07Uploaded byVinay Kothapally
- Browne 1987Uploaded byKanthavel Thillai
- chap1Uploaded byAbhiKhan
- SolutionEigenUploaded byUsman Ghafoor Chaudhary
- Classification accuracy analyses using Shannon’s EntropyUploaded byAnonymous 7VPPkWS8O
- Matlab AssignmentUploaded byManish Yadav
- 200 Operator OverloadingUploaded bySuman Kumar
- 4_WSEAS_NN08Uploaded byBogdan Popa
- Generator StabilityUploaded bysanjeevchhabra1
- statisticsUploaded byShomri Bellerin Tamotsu Kazembe
- Kbest MIMO DecodersUploaded byJuan Castillo
- Matlab Data TypesUploaded bykrishnagdeshpande
- Applied Linear AlgebraUploaded bySelvam Pds
- BAB02- The Commonly Used Blocks LibUploaded bycakMAD69
- Composite by AnsysUploaded bying_tahar