0% found this document useful (0 votes)
4 views11 pages

MATLAB and SIMULINK Scheme of Valuation

The document outlines various commands and functions in MATLAB, including directory management, error handling, and polynomial operations. It covers topics such as accessing sub-matrices, using loops, and evaluating polynomials with matrix arguments. Additionally, it discusses controlled and uncontrolled switches in electronics, as well as the concept of transfer functions in system dynamics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views11 pages

MATLAB and SIMULINK Scheme of Valuation

The document outlines various commands and functions in MATLAB, including directory management, error handling, and polynomial operations. It covers topics such as accessing sub-matrices, using loops, and evaluating polynomials with matrix arguments. Additionally, it discusses controlled and uncontrolled switches in electronics, as well as the concept of transfer functions in system dynamics.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

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".

1. b) Explain the function of ver and quit commands. (4M)

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.

quit: The quit command terminates the current MATLAB session.

1.c) Construct the concept of 'Toolbox' as well as the reason behind its naming. (2M)

A Toolbox in MATLAB is a collection of functions designed for a specific purpose.

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)

You can recall previous commands by:

Using the up and down arrow keys in the Command Window.

Double-clicking on a command in the Command History window.

Unit II

3. a) What is a sub-matrix? Explain how to access it from a matrix using a simple example. (8M)

A sub-matrix is a portion of a larger matrix. It's a matrix formed by selecting


specific rows and columns from the original matrix.

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. b) Compare the trigonometric functions sin and sind. (4M)

sin(x): Calculates the sine of x, where x is in radians.

sind(x): Calculates the sine of x, where x is in degrees.

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)

The MATLAB function to convert Cartesian coordinates to polar coordinates is cart2pol.

(OR)

4. a) What is a structure? How is it different from an array? (8M)

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

< : Less than

: Greater than

Unit III

5. a) What is the syntax of the error command? Explain it with a suitable example. (8M)

The syntax of the error command is: error('Error message')

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

% Calling the function


calculate_average([1, 2, 3, 4, 5]); % Works fine
calculate_average([]); % Triggers the error

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)

The simplest ways are:

o disp(variable_name): Displays the value of the variable.


o Typing variable_name (without a semicolon) and pressing Enter: This also
displays the value.

(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.

6. b) Explain the function file with a simple example. (4M)

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:

Create a file named add_numbers.m:

Matlab
function sum = add_numbers(a, b)
% This function calculates the sum of two numbers.
sum = a + b;
end

In the Command Window:

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.

dbclear all: Removes all breakpoints in all functions.


Unit IV

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];

% Evaluate the polynomial


result = polyval(coefficients, x);

% result will be:


% 6 15
% 28 45

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;

% Solve the equation using ode45


[t, x] = ode45(odefun, [0 10], 1); % [0 10] is the time span, 1 is
the initial condition

% Plot the solution


plot(t, x);
xlabel('t');
ylabel('x');
title('Solution of dx/dt = -2x + 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');

% Add a box around the plot


box on;

(OR)

8. a) Show the arithmetic operations on polynomials with suitable examples. (8M)

Let's say we have two polynomials:

p1 = 2x^2 + x - 3 (represented as p1 = [2 1 -3])

p2 = x + 4 (represented as p2 = [1 4])

Addition/Subtraction: You can add or subtract polynomials represented as vectors


directly if they have the same degree. If not, you might need to pad with zeros.

Matlab
p1 = [2 1 -3];
p2 = [0 1 4]; % Pad with a zero to make it the same length as p1

sum_poly = p1 + p2; % sum_poly = [2 2 1] (2x^2 + 2x + 1)


diff_poly = p1 - p2; % diff_poly = [2 0 -7] (2x^2 - 7)

Multiplication: Use the conv function for polynomial multiplication.

Matlab
p1 = [2 1 -3];
p2 = [1 4];

prod_poly = conv(p1, p2); % prod_poly = [2 9 1 -12] (2x^3 + 9x^2 +


x - 12)

Division: Use the deconv function for polynomial division. It gives the quotient and
remainder.

Matlab
p1 = [2 1 -3];
p2 = [1 4];

[quotient, remainder] = deconv(p1, p2);


% quotient = [2 -7] (2x - 7)
% remainder = [0 0 25] (25)
8. b) Outline the MATLAB code to evaluate the value of the polynomial y = 2s^2 + 3s + 4 at s =
[1 -32; 5 18 643]. (4M)

Matlab
% Polynomial coefficients
coefficients = [2 3 4];

% Matrix s
s = [1 -32; 5 18 643];

% Evaluate the polynomial


y = polyval(coefficients, s);

% Note: polyval will give an error because the matrix dimensions


don't align correctly.
% polyval is designed for square matrices or scalar inputs.
% To evaluate for each element, you'd need to loop or use arrayfun
(more advanced).

% Corrected (element-wise evaluation using arrayfun):


y_elementwise = arrayfun(@(x) 2*x^2 + 3*x + 4, s);

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

% Find the derivative


dydx = polyder(y);

% dydx will be [4 12 16 0] (which represents 4s^3 + 12s^2 + 16s)

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;

% Maximum iterations (to prevent infinite loops)


max_iter = 100;
% Secant method iteration
for i = 1:max_iter
x2 = x1 - (f(x1) * (x1 - x0)) / (f(x1) - f(x0));

% Check for convergence


if abs(x2 - x1) < tolerance
fprintf('Root found at x = %.4f after %d iterations\n', x2, i);
return;
end

% Update for the next iteration


x0 = x1;
x1 = x2;
end

fprintf('Secant method did not converge within %d iterations\n',


max_iter);

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:

Transistors (BJT, MOSFET): Controlled by current (BJT) or voltage (MOSFET) at the


base or gate terminal.

Thyristors (SCR, Triac): Controlled by a current pulse at the gate terminal.

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.

9. c) Construct the concept of 'Transfer function'. (2M)


The transfer function of a linear time-invariant (LTI) system is defined as the ratio
of the Laplace transform of the output to the Laplace transform of the input,1 assuming all
initial conditions are zero.2

It is a mathematical representation of how a system responds to an input,


expressed in the frequency domain (s-domain).

(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);

% Check for convergence


if abs(x_new - x) < tolerance
fprintf('Root found at x = %.4f after %d iterations\n', x_new, i);
return;
end

% Update for the next iteration


x = x_new;
end

fprintf('Newton-Raphson method did not converge within %d


iterations\n', max_iter);
10. b) Explain the steps involved in the fixed-point iterative scheme in finding the root of any
continuous, non-linear equation. (4M)

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.

Choose an initial guess: Select an initial approximation x0 for the root.

Iterate: Apply the iterative formula x_n+1 = g(x_n) repeatedly. Start with n = 0, then n = 1,
2, and so on.

Check for convergence: Check if the sequence of approximations {x_n} converges to a


limit. Convergence is achieved if |x_n+1 - x_n| < tolerance (a predefined small value) or
|f(x_n)| < tolerance.

Solution: If the sequence converges, the limit is the approximate root of the equation.

10. c) Organize distinct ways to create a new Simulink model. (2M)

There are several ways to create a new Simulink model:

Simulink Library Browser: Open the Simulink Library Browser and click the "New Model"
button on the toolbar.

MATLAB Command Window: Use the new_system command in the MATLAB


Command Window. For example, new_system('model_name') creates a new model
named "model_name".

Simulink Start Page: In recent versions of MATLAB, the Simulink Start Page provides
options to create a blank model or use templates.

You might also like