Saturday, 11 February 2012

MATLAB - Q. BANK (unit 2&3)


                                       UNIT 2
                                       PART A
1) What are classes or data types?
                Ans: There are 14 fundamental data types. Each of these is in the form of array. char data type, Numeric data type, cell array, structure, function handle. javaclass are some of them.

2) Define char data type.
                Ans: In char data type, each character is stored in a unicode representation and is 16 bits long. The character string is 1xn array of characters .Array of strings can be used to   store number of strings ,provided all of them have the same length.

3) What are numeric data types?
                Ans: Numeric data types int8,uint8,int16,uint16, int32 ,int64,uint64 include signed and unsigned integer arrays that are 8,16,32 and 64 bits in length
4) What is a cell array?
                Ans: A cell array is used for storing dissimilar kinds of data.One can store arrays of different types and sizes in the cells of the cell array.Cell arrays are created by enclosing the matrix variable in curly braces
                eg A=[1 2 3 4];B=[2 3 6;6 3 8;2 8 4];C=zeros(3);D_cell={A B C}
5) What is a Structure?
                Ans: The structure data type is similar to cell array as it also stores a variety of types of data. But here the data is stored in named fields rather than cells. The data is accessed using their field names
eg abc.name='Bhanu singh';abc.age=18;abc.sex='Male'

6) What is a function handle?
                Ans: The function handle is a handle to a MATLAB function, which is a numerical value that identifies the function. This function handle can be passed as an argument and the function can then be easily evaluated using feval function in MATLAB

7) What are rules for naming the variable?
                Ans: Variable name should start with alphabet character, followed by numerics, characters or underscore. The variable name can be maximum of 31 characters. If it exceeds the extra characters will beignored. The variable names that contain more than one word separated by blank space are not valid. In such cases underscore has to be used. Lower and upper case letters represent two different  variables names. Words that are reserved for the key constructs should not be used as variable names.

8) What is the final value of A in the following MATLAB program
                Ans: A=2.5;A=(A+2.5)*2.5;I=A*4;k=I^2;A=k/20

9) Mention the three ways to input data in MATLAB.
                Ans: 1. Assign data to different variables through an assignment statement
                                2. Input data from keyboard as per commands displayed on the monitor
                                3. Read data from a file which is already stored in the computer's memory

10) What are the different types of M files? And how do they differ each other?
                Ans; script files and function files are the two types of m files.
                SCRIPT FILES                                                         FUNCTION FILES
                They do not accept input arguments   These files accept input arguments and 
                Or return output arguments                       return output arguments
                Script files operate on data                                  Function files treat the internal variables 
                in the work space                                            as local to that function and have their own
                                                                                                Work space
No specific definition line                             Function files starts with keyword function
                                                                                And function definition line


11) What are the parts of function M file?
Ans; The basic parts of function M file are function definition line, h1 line, help text , function body and comments.

12) What do you mean by  feval function?
                Ans: These are functions used to manipulate the value of expression

13) What are the different types of function
                Ans:       1.  Subfunctions
2.            private functions
3.            nested functions
4.            inline functions

14) What is function handle?
                Ans: A function handle is a pointer to a function and stores all the information about the function which is needed for its execution later. It can be created using @operator and str2func function.
15) What is an anonymous function?
                Ans: A function handle created using @operator can also be used to create functions called anonymous functions.
Function Name =@(list of variables/arguments in function) function expression

16) What are the two main types of errors in MATLAB?
Syntax errors and  runtime errors.
17) What are syntax errors?
                Ans; Syntax errors are caused by grammatical mistakes in the statements included in the program. For example, not using comma, semi-colon, bracket.etc
18) What are runtime errors?
                Ans: These are errors that are caused mainly due to wrong logic used by the programmer.

19) What is the role of a MATLAB debugger?
                Ans: MATLAB debugger helps in identifying program errors in a MATLAB  M file . It allows the user to view the contents of workspace at any time during function execution and change their values.

20) What are break points?
                Ans: User can define points where the program execution stops temporarily to allow the user examine the status of the program , its variables and to ensure the program segment till that point is without any runtime error. The programmer can then continue execution from that point onwards. Such points where the execution of the program stops for a while are known as break points.

21) What are the functions used for error handling?
                Ans: The two function eval and lasterr are the basic tools for error handling.
                                If an error occurs in a function , error handling routines are defined in another function which can be invoked using eval tool. The lasterr tool can be used to return a message which indicates the last error generated by the MATLAB.

22) What are private functions? 
                Ans: These are functions that are stored in sub-folders with a  special name private. These functions are visible only to the functions in their parent folder. Hence they can have same names as functions in other folders.
23) What is the difference between global variable, local variable and persistent variables?
Ans: Global variables – the variables that are available in the base work space are called global variables. They can be accessed both from script files as well as command window. 
                Local variables – these are variables available in function workspace as each MATLAB function has its own local variables which are separate from those of other functions and from those of base workspace.            Persistent variable – are variables required to retain their value between calls to the function. It is possible in MATLAB by declaring them as persistent variables.
24) Write the syntax for function definition line.
                Ans: function[ output arguments  ] = function_name(input arguments)    
                                       
                                                            PART B
 1) What are the different data types available in MATLAB? Explain each in detail?
2) What are the different constants available in  MATLAB?
3) What are the different  operators available in  MATLAB? Mention the hierarchy of operations?
4) Explain  script files with an example?
5) Explain function files with an example?
6) What are the different types of functions ? Explain each with an example?
7) What are the different types of errors in MATLAB?
8) Explain in detail about MATLAB debugger?
9) Explain in detail how Data import and export can be done in MATLAB?
10) What are different parts of a function file?
11) Explain memory usage?
12) Explain in detail about program scheduling?
13) What are function handles ?What are the two ways in which a function handle can be created?



                                     




UNIT:3
Part-A                                                         
1.Define   Graphics?
Matlab has a powerful tool for presenting and visualizing data called Graphics.

2)write the command for getting a 2-D plot?
 To draw a 2-D plot in matlab the plot command is used. The syntax is given as follows
plot(x,y)   where
 x is a vector containing the x- coordinates of the plot and
y is a vector containing the y coordinates of the plot

3) write the command for getting a 3-D plot?
To draw a 3-D plot in matlab the plot command is used. The syntax is given as follows
Plot3(x,y,z)   where
 x is a vector containing the x- coordinates of the plot and
y is a vector containing the y coordinates of the plot
z is a vector containing the  z coordinates of the plot

4)what are commands used for labeling the graphs?
 To make the plot more understandable ,the two axes are labeled and the title is provided .
The commands are as follows
Xlabel(‘string1’);
Ylabel(‘string2’);
Title(‘string3’);

5) what is the use of grid command?
To give better illustration of the coordinates on the plot a grid is used. The command grid is used to show the grid lines on the plot. The grid on the plot can be added or removed by using the on or off with the grid command. By default Mat lab starts with grid off.
  
6)What are the three different methods of drawing multiple plots in matlab?
        The three different methods of drawing multiple plots in Matlab are
    plot command ,hold command ,line command .

7) what is the use of hold command in graphics ?
 The hold command command is used to freeze the current plot in the graphics window.the syntax is hold on;
The hold command holds the cursor on the current plot in the graphics window and subsequent plots generated in the program are added to the same graph.The hold off command is used to clear the hold on command.

8) what is the use of plot  command in graphics ?
The plot command is used to generate  the plots  depending upon the number of arguments given ,in the same graphic window.Let there be three data sets (x1,y1), (x2,y2), (x3,y3) then the plot command will be plot(x1,y1,x2,y2,x3,y3)will generate three graphs in the same command window.

9) what is the use of line command in graphics?
 The line command is used along with the plot command to generate multiple plots. Once a plot is generated in the graphics window ,more plots  can be  added using the line command directly .the syntax for the line command is line(xdata,ydata,parameter_name,parameter_value)where xdata and ydata are vectors containing x-and y-coordinates of points on the graphs and parametername/parameter_values are used to give line style options .

10)Mention the different style options and write the syntax for style options
The different style options are
Colour style options ,marker style options,line style options
The syntax for style options are  plot(xvalues ,yvalus,’style options’);



11)what are the specialized plot functions in 2-D in graphics ?
The specialized plot functions in 2-D in graphics are
 Semilogx,semilogy,loglog,polar,area,bar,barh,hist,rose,pie,stairs,stem,compass.

12) what are the plot functions in 3-D in graphics?
The  plot functions in 3-D in graphics are
Plot3,bar3,bar3h,pie3,stem3,meshgrid,mesh,surf,contour,contour3.

13)what is the use of compass function  in graphics ?
The complex data can be plotted by using function compass .the syntax is given as
Compass(z)
Compass(x,y)
The function compass(z) draws a plot that displays the angel and magnitude of the complex data of vector z.

14)what is the use for polar function in Matlab?
The polar command draws the plot in polar coordinates.The syntax is given as
polar(theta,r)
where theta is angle  vector and
r is the corresponding distance

15) what is the use for rose  function in Matlab?
  The rose function draws the angle histogram. The different forms of the function are as follows
rose(a)
rose(a,v)
rose(a,v)
where a is the vector containing in radians.n is the scalar which specifies the number of bins and v is the vector which specifies the number of bins
16)What is meant by GUI?
  Graphical user interface is a  way of interacting with program by means of windows containing menus ,buttons,dropdownlist etc
  17)what is yhe importances of guide command in           GUI?
                The guide command is used for creating and implementing GUI.it opens a untitled figure which contains all the GUI tools needed to create and layout the GUI components. These components are called uicontrols in matlab.
18) what are the two files the GUIDE generates?
GUIDE generates two files that save and launches the GUI-a FIG file  and application Mfile.The FIG contains the  complete description of GUI figure and application Mfile contains the function required to launch and control GUI.
19)what are callback functions ?
Callback functions are subfunctions of application M file ,written by the user and it determines what action is taken when the user interacts with the GUI components .eg)click a button
20) what are the  different style options available in graphics ?
The  different style options available in graphics are
1. Color style options
2. marker style options
3. line style options
The syntax for style options is plot(xvalues,yvalues,’style options ‘)

21)what is the use of subplot command in graphics?
A graphic window can be subdivided into many sub graphs using subplot command .The command subplot (i,j,k)_splits the figure  window into( i xj) parts  of plotting areas with each treated as a subplot and selects the kth areas for the current plots
22)write down the commands for stem plot for the given sets of datas?
X=[0 2 3 4 5 6],y=[3 -1 6 -4 5 3 ].
Solution:
 X=[0 2 3 4 5 6];
Y=[3 -1 6 -4 5 3 ];
stem(X,Y);
title(‘graph for stem function’);
xlabel(“x-axis’);
ylabel(‘y-axis’);

23)write down the commands for contour 3-D plot for  for the given  function Z=sqrt(Y.^2-X.^2) over the interval  -3<=X<=3 and -3<=Y<=3 ?
[X,Y]=meshgrid(-3:0.5:3,-3:0.5:3);
Z=sqrt(Y.^2-X.^2);
contour3(X,Y,Z);
grid on;
title(‘contour 3-D plot’);
xlabel(‘x-axis’);
ylabel(‘y-axis’);
zlabel(‘Z=sqrt(Y.^2-X.^2)’);



24) write down the commands for stairs plot for   the given  function y=x.*x,where -2<=x<=2.
The  commands are
                x=-2:0.1:2;
   y=x.*x;
stairs(x,y,’r’);
grid on;
xlabel(‘x-axis’);
ylabel(‘y-axis’);title(‘stairs plot’);

25)define  a polar function?
         The polar command draws the plot in polar coordinates. The syntax is given by
polar(theta,r)
Where
theta is angle vector and
r is corresponding distance

PART-B
1. Explain with examples the three different methods of drawing multiple plots?
2) Explain the specialized functions for 2-D plots with syntax?
3) Explain the functions for 3-D plots with syntax?
4) Explain  the basic structure  of GUI?
5) ) Explain  in detail how a plot can be formatted ?

No comments:

Post a Comment

This site under replacement . Please visit later.