Professional Documents
Culture Documents
Fall 2020
Lab Session-6 Solutions
Note that the limits for ∆T are given in terms of ⁰C. Our function ‘heat’ calculates the
energy (E) required to for a change of ∆T (in K) in water at constant pressure. However,
as ⁰C+273.15=K , ∆T(⁰C) = ∆T(K). So, we can directly use the given ∆T limits to plot the
function without any need for unit conversion.
2. Solution:
%a)
>> f=@(z) (1/sqrt(2*pi))*exp(-z.^2/2);
>> fplot(f,[-4,4])
>> xlabel('z'),ylabel('f(z)')
>>%b)
>> x=@(t) sin(t).*(exp(cos(t))-2*cos(4*t)-sin(t/12).^5);
>> y=@(t) cos(t).*(exp(cos(t))-2*cos(4*t)-sin(t/12).^5);
>> fplot(x,[0,100])
>> hold on
>> fplot(y,[0,100],':c')
>> xlabel('t'),ylabel('x ot y')
>> legend('x','y')
3. a)An example function M-file can be as follows:
function Ta=avgtempi(Tm,Tp)
w=2*pi/365;
ts=input('Starting day: ');
te=input('Ending day: ');
t=ts:te; % ts: starting day, te: ending day
T=Tm+(Tp-Tm)*cos(w*(t-205)); % temperature of a specific day,t.
Ta=mean(T) % mean temperature averaged for all the days
% calculated in the range from ts to te.
endfunction
>> avgtempi(17,30);
Starting day: 0
Ending day: 90
Ta = 6.1564
>> avgtempi(23.4,42);
Starting day: 181
Ending day: 243
Ta = 40.974
function currency_converter2(a,b)
%This function converts between dollars to euros,liras and yens
%On Monday, 28 December, 2020 :
%1 US Dollar=103.87 Japanese Yen
%1 US Dollar=7.43 Turkish Liras
%1 US Dollar=0.82 Euros
>> currency_converter2(1,10)