Solution Mid Term MFE 1006

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Solution Mid Term MFE 1006 (There might be multiple solutions, faculty member checking the

scripts must consider the alternate solution also.)

Sol1)

2)

or

If student has explained with the help of an example, please consider.

3) Explain the steps involved in plotting a simple 2-D graph using MATLAB.

Sol

Basic 2-D Plots

The basic command for producing a simple 2-D plot is plot(x values, y values, ‘style option’) where x
values and y values are vectors containing the x- and y-coordinates of points on the graph. Style
option is an optional argument that specifies the color, line-style and the point-marker style.

Or

If is plot(x values, y values) is mentioned by student. This is also correct.

SECTION B

Q4)

How can anonymous functions be used in MATLAB, and what are their advantages over named
functions?

Solution

An anonymous function is a function of one or more variables that you create on the command line
for subsequent evaluation
The key to anonymous functions is the syntax of its creation: fn_name = @(list of input variables)
function_expression Here, the key clement is the symbol @ that assigns a function handle to the
defined function.

A function handle is a name given to a function by which you can call it wherever you need it. In the
anonymous function definition line, fn_name is the name of the function or the handle of the function.

A function handle is a name given to a function by which you can call it wherever you need it. In the
anonymous function definition line, fn_name is the name of the function or the handle of the function.

Q4b) Write syntax for creating function in MATLAB. Write a program to create a function with your
name for determining the following expression:

Solution (Function name will be different in all scripts)

Q5a)
Q5b)

Solution

i) t =0:10*pi

f(t)=t.*cos(t)

plot(t,f(t))

ii)
Q6)
Solution
OR

Another solution could be analytical calculation of alpha and conventional method of writing the code.
In that case, code will be of 3-4 lines. Please note that is also correct.

Q7)

Solution (PLEASE NOTE THAT IN THE PROBLEM 110t has been printed twice. Consider whether student
has considered it twice or once both will be deemed correct)
PLEASE NOTE THERE ARE MULTIPLE SOLUTIONS

Smaller code with which can produce the same result shall also be considered.

There may be alternate solutions as symbolic computation. That can also be considered correct if end
result is same and logical.

Q8)a)

Q8b)

You might also like