Problem 2 A matrix named much contains 3 columns of data con

Problem 2

A matrix named much 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: Request the user for the matrix mach. 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. Please use the text book for any unit conversion needed.

Solution

% matlab code determine power generated by each machine

function P = power(mach)
[row,column] = size(mach);

for i=1:row
% determine power for each id
P(i,1) = mach(i,1);
P(i,2) = mach(i,2)/mach(i,3);
end
end

mach = input(\"Enter matrix mach: \");
P = power(mach);
disp(\"\ ID\\tPower\");
[row,column] = size(P);
for i=1:row
fprintf(\"%d\\t%0.2f\ \",P(i,1),P(i,2));
end

%{
output:

Enter matrix mach: [1 23 4; 2 42 8; 3 34 5]

ID Power
1 5.75
2 5.25
3 6.80

%}

Problem 2 A matrix named much contains 3 columns of data concerning the energy output of several machines. The first column contains an ID code for a specific m

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site