0% found this document useful (0 votes)
324 views

Assignments - NOC - MATLAB Programming For Numerical Computation

This document provides three practice problems related to MATLAB programming for numerical computations. The first problem asks the user to use a vector to calculate the exponential of a value using its Maclaurin series expansion up to the 6th term, using both a for loop and without loops. The second problem asks the user to convert a script that calculates steam saturation pressure given temperature into a function, and then call that function at two different temperatures. The third problem asks the user to plot data from a vector defining the vertical location of a ball over time, showing the line through all points but symbols only at 0.5 second intervals.

Uploaded by

Praghashraja
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
324 views

Assignments - NOC - MATLAB Programming For Numerical Computation

This document provides three practice problems related to MATLAB programming for numerical computations. The first problem asks the user to use a vector to calculate the exponential of a value using its Maclaurin series expansion up to the 6th term, using both a for loop and without loops. The second problem asks the user to convert a script that calculates steam saturation pressure given temperature into a function, and then call that function at two different temperatures. The third problem asks the user to plot data from a vector defining the vertical location of a ball over time, showing the line through all points but symbols only at 0.5 second intervals.

Uploaded by

Praghashraja
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

MATLAB Programming for Numerical Computations Jan–March 2016

Module–1: Practice Problems


Week-1: 18th to 24th January

1. PRACTICE PROBLEM ON ARRAY OPERATIONS

We want to compute : &E.)G using MacLaurin series expansion. We have obtained a vector
terms = 0.25.^[1:n]./cumprod(1:n);
Explain what this vector contains. Use value of n = 6.
Use this vector to calculate the exponential. Note that the exponential is calculated as:
expVal = 1–terms(1)+terms(2)–terms(3)... so on until nth term.
Perform this in two ways: (i) using for loop; and (ii) without using any loops.

2. SCRIPT à FUNCTION

A simple but approximate formula for calculating pressure of saturated steam at any
temperature is given by: HI;J = K/100 L , where T is in degree C. Consider the script given
below that calculates saturation pressure given steam temperature (in K):
% Calculate pSat for steam
T = 400;
Tr = (400 – 273)/100;
pSat = Tr^4;
Convert the above script into a function that takes temperature in Kelvins as an input and
returns saturation pressure as output. From the command prompt, call this function as:
steamPressure(398) and steampressure(473).
The results should be 2.44 bar and 16 bar, respectively.

3. PLOTTING

Define vector t = [0:0.1:4];. Define vertical location of the ball using equation
, - = ./ - − 0.5 4- ) . This was done in Solved Problem #14 above. We now have a twist!
The command plot(t,y,'-bo') gives blue line with data-points shown as open
circles. Since the data is closely spaced, this does not look good.
Instead, plot the same graph such that the blue line is as before, but the circles are shown
only at 0.5 seconds interval (i.e., line goes through all 41 points, but symbols for 9 points only).
Hint: You will have to plot the same data twice: using '-b' to plot the line, and using 'bo'
to plot the symbols only.

You might also like