MATLAB and SIMULINK Scheme of Valuation
MATLAB and SIMULINK Scheme of Valuation
Unit I
1. a) What are the commands used to retrieve the directory information and explain them? (8M)
dir: The dir command lists all the files and folders in the current directory.
ls: This command is similar to dir and is often used in Unix-based systems. In MATLAB,
it also lists the contents of the current directory.
pwd: This stands for "present working directory". It displays the current directory path.
cd: This command is used to change the current directory. For example, cd
'folder_name' will change the directory to "folder_name".
ver: The ver command displays information about the MATLAB version, the installed
toolboxes, and their versions. This is useful for checking which toolboxes are available for
use.
1.c) Construct the concept of 'Toolbox' as well as the reason behind its naming. (2M)
The naming of a toolbox reflects its functionality. For example, the "Signal Processing
Toolbox" contains functions for signal processing, and the "Image Processing Toolbox"
provides tools for image manipulation and analysis.
(OR)
2. a) List out and explain the major components of the MATLAB environment. (8M)
Command Window: This is the main area where you enter commands and see results.
Workspace: The Workspace displays the variables you have created during your MATLAB
session. You can see their names, values, sizes, and data types.
Current Folder: This shows the current directory where MATLAB is looking for files and
saving them.
Command History: The Command History window keeps a record of the commands you
have entered. You can easily recall and re-execute previous commands from here.
Editor: This is where you can write and edit MATLAB code, including scripts and
functions.
2. b) Explain the Current Directory. Summarize the way to change the Current Directory. (4M)
The Current Directory is the folder that MATLAB uses as a reference point for loading and
saving files. When you type a filename, MATLAB first looks for it in the Current Directory.
To change the Current Directory, you can use the cd command followed by the path to the
desired directory. For example: cd 'C:\Users\Documents\MATLAB'
2. c) Organize the necessary steps to recall the previous executed commands by using the
command history window. (2M)
Unit II
3. a) What is a sub-matrix? Explain how to access it from a matrix using a simple example. (8M)
You can access a sub-matrix using the colon operator (:). The syntax is
A(row_start:row_end, col_start:col_end), where A is the matrix, and you
specify the range of rows and columns you want to extract.
Example:
Matlab
A = [1 2 3; 4 5 6; 7 8 9];
sub_matrix = A(1:2, 2:3); % Extracts the top-right 2x2 sub-
matrix
% sub_matrix will be:
% 2 3
% 5 6
3. c) Identify the appropriate MATLAB function to convert the coordinates of a point from the
Cartesian coordinate system to the polar coordinate system. (2M)
(OR)
A structure is a data type that can hold multiple values of different data types. It's like a
container for related information. Each piece of data within a structure is called a field.
An array, on the other hand, stores a collection of elements of the same data type.
4. b) With an example, explain how to obtain the data from a structure array. (4M)
You access data in a structure array using dot notation. First, you specify the structure array
element, and then the field name.
Example:
Matlab
% Create a structure array
students(1).name = 'Alice';
students(1).id = 123;
students(2).name = 'Bob';
students(2).id = 456;
% Access data
student_name = students(1).name; % student_name will be 'Alice'
student_id = students(2).id; % student_id will be 456
4. c) Organize and summarize the symbols for any four relational operators in MATLAB. (2M)
Relational operators compare values. Here are four common ones:
== : Equal to
~= : Not equal to
: Greater than
Unit III
5. a) What is the syntax of the error command? Explain it with a suitable example. (8M)
It displays the specified 'Error message' in the Command Window and terminates the
execution of the current function or script.
Example:
Matlab
function calculate_average(numbers)
if isempty(numbers)
error('Input array cannot be empty.');
end
average = sum(numbers) / length(numbers);
disp(['The average is: ', num2str(average)]);
end
5. b) Illustrate the for loop to obtain the sum of all even numbers from 20 to 0. (4M)
Matlab
sum_even = 0;
for i = 20:-2:0 % Loop from 20 down to 0, decrementing by 2
sum_even = sum_even + i;
end
disp(['The sum of even numbers is: ', num2str(sum_even)]);
5. c) Construct the simplest way to print the value of a variable in the command window. (2M)
(OR)
6. a) List out and explain the basic tools available for error-handling in MATLAB. (8M)
try-catch blocks: These blocks allow you to handle errors gracefully. The code within
the try block is executed, and if an error occurs, the code within the catch block is
executed.
error function: As explained in 5(a), this function displays an error message and stops
execution.
warning function: Displays a warning message but does not stop execution.
Debugging tools: MATLAB provides a debugger that allows you to step through code, set
breakpoints, and inspect variables to find and fix errors.
A function file is a separate file (with a .m extension) that defines a function. Functions
encapsulate a specific task and can be reused. They take input arguments and can return
output values.
Example:
Matlab
function sum = add_numbers(a, b)
% This function calculates the sum of two numbers.
sum = a + b;
end
Matlab
result = add_numbers(5, 3); % result will be 8
6. c) Build up the difference between dbclear and dbclear all functions. (2M)
dbclear: Removes a specific breakpoint. You can specify the function name or the line
number where the breakpoint is set.
7. a) Show how a polynomial can be evaluated with matrix arguments. Illustrate with a suitable
example. (8M)
The polyval function is used to evaluate a polynomial. When you use a matrix as the
argument to polyval, it evaluates the polynomial for each element of the matrix.
Example:
Matlab
% Polynomial: 2x^2 + 3x + 1
coefficients = [2 3 1]; % Coefficients in descending order of power
% Matrix argument
x = [1 2; 3 4];
7. b) Outline the MATLAB code to evaluate and plot the numerical solution of the following
first-order linear differential equation: dx/dt = -2x + t with initial condition as x(0) = 1 for 0 < t <
10 using simple syntax of ode45 solver. (4M)
Matlab
% Define the differential equation
odefun = @(t, x) -2*x + t;
7. c) Develop the MATLAB code to plot the function b = 4a^2 for 0 < a < 20 and illustrate the
box command. (2M)
Matlab
% Create the vector 'a'
a = 0:0.1:20; % From 0 to 20 with a step of 0.1
% Calculate 'b'
b = 4 * a.^2; % Use element-wise squaring (.^)
% Plot the function
plot(a, b);
xlabel('a');
ylabel('b');
title('Plot of b = 4a^2');
(OR)
p2 = x + 4 (represented as p2 = [1 4])
Matlab
p1 = [2 1 -3];
p2 = [0 1 4]; % Pad with a zero to make it the same length as p1
Matlab
p1 = [2 1 -3];
p2 = [1 4];
Division: Use the deconv function for polynomial division. It gives the quotient and
remainder.
Matlab
p1 = [2 1 -3];
p2 = [1 4];
Matlab
% Polynomial coefficients
coefficients = [2 3 4];
% Matrix s
s = [1 -32; 5 18 643];
8. c) Build up the MATLAB code to evaluate the derivative of the polynomial y = s^4 + 4s^3 +
8s^2 + 0s + 16. (2M)
Matlab
% Polynomial coefficients
y = [1 4 8 0 16]; % Include the 0 for the missing 's' term
Unit V
9. a) Given a non-linear equation 2^x - 5x + 2 = 0. Using the Secant method, find the root of this
equation up to four decimal places. Use x0 = 0 and x1 = 1 as initial guesses. Tolerance = 10^-4
(8M)
Matlab
% Define the function
f = @(x) 2.^x - 5*x + 2;
% Initial guesses
x0 = 0;
x1 = 1;
% Tolerance
tolerance = 1e-4;
9. b) Explain the controlled and uncontrolled switches with suitable examples. (4M)
Controlled Switches:
Controlled switches are semiconductor devices that can be turned ON (closed) or OFF
(open) by an external control signal.
The control signal can be electrical (voltage or current), optical, or other means.
Examples:
Uncontrolled Switches:
Uncontrolled switches change their state (ON or OFF) based on the circuit conditions
(voltage polarity or current direction) and do not require an external control signal.
Examples:
Diodes: Conduct current in only one direction when forward-biased and block current
when reverse-biased.
Circuit breakers: Open the circuit when they detect over current.
(OR)
10. a) Define a non-linear function. Given a non-linear equation 2^x - 5x + 2 = 0. Using the
Newton-Raphson method, find the root of this equation up to four decimal places. Use x0 =
0 as initial guess. Tolerance = 10^-4 (8M)
Non-linear function: A non-linear function is a function whose graph is not a straight line.
In other words, it does not satisfy the property of superposition (f(a + b) != f(a) + f(b)) or
homogeneity (f(kx) != kf(x)).
Newton-Raphson Method:
Matlab
% Define the function and its derivative
f = @(x) 2.^x - 5*x + 2;
df = @(x) log(2) .* 2.^x - 5; % Derivative of f(x)
% Initial guess
x0 = 0;
% Tolerance
tolerance = 1e-4;
% Maximum iterations
max_iter = 100;
% Newton-Raphson iteration
x = x0;
for i = 1:max_iter
x_new = x - f(x) / df(x);
The fixed-point iteration method is used to find the root of an equation by rewriting it in the
form x = g(x). The steps are:
Rearrange the equation: Rewrite the given equation f(x) = 0 into an equivalent form x =
g(x). There can be multiple ways to rearrange, and the choice of g(x) affects convergence.
Iterate: Apply the iterative formula x_n+1 = g(x_n) repeatedly. Start with n = 0, then n = 1,
2, and so on.
Solution: If the sequence converges, the limit is the approximate root of the equation.
Simulink Library Browser: Open the Simulink Library Browser and click the "New Model"
button on the toolbar.
Simulink Start Page: In recent versions of MATLAB, the Simulink Start Page provides
options to create a blank model or use templates.