You are on page 1of 2

FE211

Fall 2020
Lab Session-6

1. The energy (E) required to heat water at constant pressure is approximately equal to

E=mC p DT

where m: mass of the water, in grams


Cp: heat capacity of water, 1 cal/g K
T: change in temperature, K.

a) Create an anonymous function called heat to find the energy required to heat 1 g of
water if the change in temperature is provided as the input. Then, create another
anonymous function cal_to_J to convert your answer into joules. Note that 1 cal = 4.2
J. Test your anonymous functions in a single command line for deltaT=20 K.
b) Finally, use fplot to plot E (in cal) vs. T for temperature changes within the range 0
C to 100 C. Include a title and labels to your graph.

2. Create function handlers for the following functions and plot them using fplot.

1 −z /2 2

a) f ( z )= e within z=-4 to 4. Add axes labels.


√2 π

(
cos (t )
b) x=sin ⁡(t) e −2 cos ( 4 t )−sin( 12t ))
5

t
y=cos(t )( e −2 cos ( 4 t )−sin ( ))
cos(t) 5
12

on the same graph from t=0 to 100. Plot the function (y) with cyan dotted lines. Add axes
labels and a legend.
3. The average daily temperature for an area can be approximated by the following
function:

T =T mean+ ( T peak −T mean ) cos ( w ( t−t peak ) )

Where Tmean = the average annual temperature, Tpeak = the peak temperature, w= the
frequency of the annual variation (=2π/365), and tpeak= day of the peak temperature (≅
205 d). Parameters for some cities are listed here:

City Tmean (°C) Tpeak (°C)


Ankara 19.1 38
İstanbul 21.2 36
İzmir 23.4 42
Artvin 17 30
Iğdır 5.5 22

a) Develop an interactive function M-file that computes the average temperature


between two days of the year for a particular city. Your function should accept 2
input arguments; i.e., Tmean and Tpeak of the city. The program should ask the user to
input by hand (via the command line interface) the starting and ending days for the
calculation! It should return a single output argument (the average temperature).

b) Test it for January-March in Artvin (t = 0 to 90), and for July-August temperature in


İzmir (t = 181 to 243).

4. Use your favorite Internet search engine and World Wide Web browser to identify recent
currency conversions for Turkish lira, Japanese yen, and the European euro to US dollars.
Write a function M-file to create the conversion table described below. Use the disp and
fprintf commands in your solution, which should include a title, column labels, and
formatted output.

The table must be composed of four columns. The first should contain dollars, the second
the equivalent number of euros, the third the equivalent number of liras, and the fourth the
equivalent number of yens.

Your function M-file should be composed of a primary function (named as


currency_converter2), and three subfunctions (named as dollar_to_euro, dollar_to_lira, and
dollar_to_yen). The primary function should accept two input arguments (the starting and
ending values for the column of dollars to be converted to other currencies) and should
generate the wanted table. The subfunctions must only be responsible for performing the
corresponding currency conversions. Test your program for dollars ranging from 1 to 10.

You might also like