Answers
MATLAB SCRIPT :
Code to Copy:
% time interval
t = 0:250;
% initial oil temperature
to = 40;
% initial ball temperature
ti = 800;
% Get the time constant from user
T1 =input('Enter the value of T1: ');
% verify that it is a value between 20 and 100
while ((T1<20)||(T1>100))
T1 =input('Entered value does not lie between 20 and 100. Reenter the value: ');
end
% Get the time constant from user
T2 =input('Enter the value of T2: ');
% verify that it is a value between 20 and 100
while ((T2<20)||T2>100)
T2 =input('Entered value does not lie between 20 and 100. Reenter the value: ');
end
% Get the time constant from user
T3=input('Enter the value of T3: ');
% verify that it is a value between 20 and 100
while (T3<20||T3>100)
T3 =input('Entered value does not lie between 20 and 100. Reenter the value: ');
end
% Initialize the variables
Temp1=0; Temp2=0; Temp3=0;
% verify the stopping the condition that the value of temperature for all 3 arrays to be plotted is less than 80 degrees Celsius
while(((max(Temp1) < 80)&&(max(Temp2) < 80)&&(max(Temp3) < 80)))
% calculating the ball temperatures
Temp1 = (ti-to).*exp(-t./T1)+to;
Temp2 = (ti-to).*exp(-t./T2)+to;
Temp3 = (ti-to).*exp(-t./T3)+to;
end
% Display the graph
plot(t, Temp1,'r', t, Temp2, 'g', t, Temp3, 'b'), xlabel('time, s'), ylabel ('temperature');
legend('Time constant 1','Time constant 2','Time constant 3');