Posts

Showing posts from January, 2015

A MATLAB Program To Generate A Unit Step Signal

Image
%unit step signal generation %n denote the range of input %y here is output n=[-10:10] y=ones(1,21) y=zeros(1,10) y=ones(1,11) y=[zeros(1,10) ones(1,11)] stem(n,y) IN the above created program in MATLAB editor ,to generate the unit step sequence i first specified the range of n.Then the output y is obtained by appending the 2 vectors which are zeros(1,10) and ones(1,11). By using the stem(n,y),the each of output value is plotted against each value of input range specified as a vector that is stored in n.

Solution for Practical Programs

Image
A = size(3x3) with range [7-11] B = identity matrix of same size as A. Perform operations i) Addition ii) Subtraction iii) Multiplication iv) Element Multiplication. Solution. Click Here. Divide screen as shown in fig given below.                 Plot in screen 3 => y = x3 + 5 Plot in screen 1 => y = cos(x) in range (0,4*pi) with 100 points in blue color with dotted line. Solution. Click Here. Create a semicircle of radius 8 centered at (3 4) with red lines. Solution. Click Here. P2(Given x=[1 2 3 4 5 ] y=[2 9 28 65 126] find equation of curve which fits best. compare graphically) Solution. Click Here.              

Solution:

Image
theta=linspace(0,pi,100);   //simple pi for semi circle r=8;                                    //radius = 8 x=r*cos(theta);                 x=x+3;                               //for center at x=3. y=r*sin(theta); y=y+4;                              //for center at y=4. plot(x,y,'r');                      //'r' is to change color into red. Run. Output :

Solution

Image
x=linspace(0,50,100); p=[1 0 0 5]; y=polyval(p,x); subplot(2,2,4); plot(x,y); x1=linspace(0,4*pi,100); z=cos(x1); subplot(1,2,1); plot(x1,z,'b.'); Run it. Output :

Solution

a=rand(3)            //to create random matrix of range 0 to 1 and of size 3x3 a=a*4                 //for range; a=a+7 a=round(a)         // to convert elements into int. b=eye(3)            // to create identity matrix addi=a+b           // addition sub=a-b             //subtraction mul1=a*b         //multiplication mul2=a.*b       //corresponding elements multiplication Output : //for a=rand(3) a =     0.7922    0.0357    0.6787     0.9595    0.8491    0.7577     0.6557    0.9340    0.7431 //for a=a*4; a =     3.1688    0.1428    2.7149     3.8380    3.3965    3.0310     2.6230    3.7360    2.9725 //for a=a+7; a =    10.1688    7.1428    9.7149    10.8380   10.3965   10.0310     9.6230   10.7360    9.9725 //for a=round(a); a =     10     7    10     11    10    10     10    11    10 // for b=eye(3); b =      1     0     0      0     1     0      0     0     1 // for addi=a+b; addi =     11     7    10     11    11    10     10    11

P2 : Plot Graph

Image
linspace Cmd : >> x=linspace(0,10,100); linspace(a,b,n); where a = start point            b = final point            n = number of point you want to divide range of a and b. Example : >> x=linspace(0,10,10)                        x =                               0    1.1111    2.2222    3.3333    4.4444    5.5556    6.6667    7.7778    8.8889                                         10.0000 Plot Circle Using MATLAB : >> theta=linspace(0,10,100); >>r=10; >> y=r*sin(theta); >> x=r*cos(theta); >> plot(x,y) Output will be :  Now in this 4 line code we have theta having value 0 to 10 with 100 points. Radius r = 10. As we know that equation of circle is x 2 + y 2 = r 2 or x = r*cos(theta) and y = r*sin(theta) . so we use x = r*cos(theta) and y = r*sin(theta) where r = 10. Now using plot cmd we draw x and y using plot(x,y) and hit enter.                                           We were done this wo

P1 : MATLAB Basics

To declare a variable. a=10 a =     10 Note : If you will put ; (semi colons) the you will not output of that variable  or command. As seen blow : >> a=10; >> b=30; Addition of two variable. >> c=a+b c =     40 Subtraction of two variable. >> c=a-b c =    -20 Multiplication of two numbers. >> c=-1*c c =     20 Similarly you can do divide operation using / symbol between two variables. Command for writing 1 to 10 >> a=1:10 a =      1     2     3     4     5     6     7     8     9    10 Note : By putting : colons you can  start from a number and count to another number. Here I have use 1 as starting and 10 as ending.  Command for writing or storing vector as counting and giving same gap between the number s. >> a=1:2:10 a =      1     3     5     7     9 Note : In this example I have start from 1 and storing after a gap of 2 till 10. Similarly you can write down table of any nubmer. >> a=3:3:30 a =      3     6     9   

Queue

Image
What is Queue? Queue is another kind of  abstract data type or collection of data like Stack. Similarly in Queue there are mainly two operation we can perform on Queue that is PUSH and POP. In Queue we push data elements from end of Queue but POP form the beginning of Queue. Example Queue in Govt. Office, Water passing through pipe etc. Queue (source wikimedia)        Basically Queue is Last In First Out. That means the oldest data will be pop from queue. PUSH means Enqueue and POP means Dequeue.          Queues are also can be implemented using Linked list and Array data structure. Click Here form Programs..

Stack

Image
What is Stack? Stack is a particular kind of abstract data type or collection of data. In Stack the principal operations are push and pop. In stack we push data from end and pop from end. Stack can be implements using linked list or array. Example of stack is books in library one over another, Plates in kitchen etc. Stack (source wikimedia)                            The relation between the push and pop operations is such that the stack is a Last in First Out, means the fresh element remove from stack first.                             Stack is also a kind of list on which we perform push and pop operation. Applications : - Backtracking. Run-time memory management. Stack Over Flow Problem : -                       Stack Over Flow problem exists when whole stack memory is full. Means there is no free place to push data in memory or stack. Stack Under Flow Problem : -                       Stack Under Flow problem exists when there is no data exist in stack. Means th

Sorting and Searching

 What is Sorting and Why we need Sorting? Sorting means arranging numbers or objects or things in specific order either in ascending or descending.              Now the question is why we need sorting? We need sorting because when we have hundreds of thousands of comparable values stored in array or linked list then for efficient searching we need to sort that linked list or array data. For example if some ask you to find smallest number form 100 numbers stored in data structure, then it will be difficult for you to find smallest number for 100 numbers. If you will sort that data structure in ascending order that means 1st number in that data structure will be Smallest one.   Types of Sorting Algorithms : -   Selection Sort Algorithm.   Insertion Sort Algorithm.   Bubble Sort Algorithm.   Quick Sort Algorithm.   Merge Sort Algorithm.   Shell Sort Algorithm.   Heap Sort Algorithm. What is Search? Search means to find some form many. Type of Searching Algorithms : -  

Double Linked List.

Image
What is Doubly linked list and what is difference between Single and Double linked list? Doubly Linked list, in doubly linked list each node contains three parts I) Data part and two pointers II) Next Pointer III) Previous Pointer.                                         Next Pointer is a pointer of node type which points to next node of Doubly linked list. If there is no next node then next pointer points toward null means that node is last in that Doubly Linked List.                                          Previous Pointer or Backward Pointer is a pointer of same node type which point to previous pointer of that linked list. If there is no previous node then previous node points towards null means that node is Start node of that linked list. Double Linked List (source wikipedia) Click here for programs.