write a matlab code to perform the given instructions Ball b
write a matlab code to perform the given instructions
Ball bearings are hardened by a process called quenching-rapid cooling of a heated ball bearing in a bath of oil or water. The temperature of the ball bearing is estimated by the following equation: T(t) = (T_t - T_infinity)e^-t/tau + T_infinity Where t is the time, in seconds, T_t is the initial ball temperature (C), T_infinityis the temperature of the oil bath (C), and t (sec) is the time constant, which is a parameter that depends upon the material of the ball, its geometry, and also the oil bath properties. Write a MATLAB function M-file named BallBearingQuench to generate time and temperature estimates of the quenching process. The input arguments are T T_infinity and r. The output argument is a matrix containing an array of 100 time values in the first row, and the corresponding 100 temperatures in the second row. The time array begins at zero, and ends when the temperature is within 1% of its steady-state temperature, i.e., the temperature of the oil bath. Input Restrictions & special cases: The function should return a red error message for the following conditions. Any input is nonscalar Any input is negative T_infinity is greater than T_iSolution
The matlab code is as follows:
function [out] = ballbearingquench(Ti,Tinf,tao)
%checks
c=0;
if (Ti>Tinf)
c=1;
end
if(Ti<0)||(Tinf<0)
c=1;
end
assert(c==0,\'invalid input conditions\')
% T is the temperature array, tm is the time array
tm(1)=0;
T(1)=Ti;
% determination of T(100) and tm(100)
T(100)=99.1/100*Tinf;
tm(100)=-tao*log((T(100)-Tinf)/(Ti-Tinf));
h=(tm(100)-tm(1))/99;
for n=2:99
tm(n)=tm(n-1)+h;
T(n)=(Ti-Tinf)*exp(-tm(n)/tao)+Tinf;
end
out(:,1)=tm(:);
out(:,2)=T(:);
end
