Assignments - NOC - MATLAB Programming For Numerical Computation
Assignments - NOC - MATLAB Programming For Numerical Computation
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.