A matrix named mach contains 3 columns of data concerning th
A matrix named mach contains 3 columns of data concerning the energy output of several machines. The first column contains an ID code for a specific machine, the second column contains the total amount of energy produced by that machine in calories, and the third column contains the amount of time required by that machine to produce the energy listed in column 2 in hours.
Write a MATLAB program that will:
a) Request the user for the matrix mach.
b) Return a new matrix named P containing 2 columns and the same number of rows as mach.The first column should contain the machine ID codes, and the second column should contain the average power generated by each machine in units of watts.
Solution
n=input(\'Enter number of entries\');
disp(\'Now enter values one by one\');
x=zeros(n,1);
y=zeros(n,1);
z=zeros(n,1);
for i=1:n
x(i)=input(\'Enter ID\');
y(i)= input(\'Enter energy\');
z(i)=input(\'Enter time required\');
end
mach=[x y z];
%1 Joule=4.184 Cal
%Power in Watt=energy in J/Time in Sec=y*(1/4.184)/Z
%1 Watt hour=Power in watt/time in hours
%simplifying we get, Watt hour=y/(4.184*3600)
P=[x y./(4.184*z*3600)];
%P_watthour=[x y/(4.184*3600)];
disp(P);
