Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB Engineers use both English and SI (Systeme International d’Unites) units

ID: 3828915 • Letter: M

Question

MATLAB

Engineers use both English and SI (Systeme International d’Unites) units on a regular basis. Some fields use primarily one or the other, but many combine the two systems. For example, the rate of energy input to a steam power plant from burning fossil fuels is usually measured in Btu/hour. However, the electricity produced by the same plant is usually measured in joules/s (watts). Automobile engines, by contrast, are often rated in horsepower or in ft lbf/s. Here are some conversion factors relating these different power measurements:

1 kW = 342.14 Btu/h = 737.56 ft lbf/s
1 hp = 550 ft lbf/s = 2544.5 Btu/h

1-Ask user to enter the minimum and maximum kilowatt values.
In nested for loops, get one random number at a time between the minimum and maximum kilowatt values and save it into the 4x3 matrix using indexing. p.334
Convert kw to btu/h, hp, and ft lbf/s. You now have four 4x3 matrices.
Print a conversion table as shown below for kw to btu/h, hp, and ft lbf/s without using a loop.

2-Find the kilowatt values in the matrix that are within a standard deviation on either side of the overall kilowatt average in the 4x3 matrix. Use find not a loop or if.
Print a conversion table as shown below for kw to btu/h, hp, and ft lbf/s for kilowatt values from the between kilowatt average ± standard deviation using the result of the find without using a loop.

Explanation / Answer

prompt = 'Enter a minimum KW val ';

min_val = input(prompt)

prompt = 'Enter a maximum KW val ';

max_val = input(prompt)

KW_matrix = zeros(4,3);

kW_to_Btu_h = 342.14; %conversion from KW to Btu/h

KW_to_lbf_s = 737.56; %conversion from KW to lbf/s

hp_to_ft_lbf_s = 550; % conversion ratio hp to ft lbf/s

hp_to_Btu_h = 2544.5; %conversion ratio from hp to Btu/h

% loop to initialize KW matrix

for i= 1:4

for j = 1:3

random_val = min_val+(max_val-min_val)*rand();

KW_matrix(i,j) = random_val;

end

end

Btu_h_matrix = kW_to_Btu_h.*KW_matrix; % converting values from KW matrix into BTu/h

hp_matrix = (1/hp_to_Btu_h).*Btu_h_matrix; % converting values from Btu/h matrix into hp

ft_lbf_s_matrix = hp_to_ft_lbf_s.*hp_matrix;% converting values from hp matrix into ft lbf/s

mean_KW_matrix = mean(mean(KW_matrix));% mean of KW matrix

std_KW_matrix = std(std(KW_matrix)); %standard deviation of KW matrix

% finding index of all value in KW matrix that are in range mean-std to mean+std

KW_in_range_index = find(KW_matrix<=mean_KW_matrix + std_KW_matrix & KW_matrix>=mean_KW_matrix-std_KW_matrix);

%finding values of all values of KW matrix corresponding to the indeices in KW_in_range_index and storing them into a vector

KW_in_range = KW_matrix(KW_in_range_index);

%finding required BTu/h values and storing them into a vector

Btu_h_in_range = Btu_h_matrix(KW_in_range_index);

%finding required hp values and storing them into a vector

hp_in_range = hp_matrix(KW_in_range_index);

%finding required ft lbs/s values and storing them into a vector

ft_lbf_s_in_range = ft_lbf_s_matrix(KW_in_range_index);

result1 = zeros(12,4);

for i = 1:12

result1(i,1) = KW_matrix(i);

result1(i,2) = Btu_h_matrix(i);

result1(i,3) = hp_matrix(i);

result1(i,4) = ft_lbf_s_matrix(i);

end

[m,n] = size(KW_in_range);

result2 = zeros(m,n);

for i = 1:m*n

result2(i,1) = KW_in_range(i);

result2(i,2) = Btu_h_in_range(i);

result2(i,3) = hp_in_range(i);

result2(i,4) = ft_lbf_s_in_range(i);

end

disp('Power Conversion Table:');

fprintf([repmat('%f ', 1, size(result1, 2)) ' '], result1');

%printing the final data

% as you didn't mention the format I used this format

disp('Power conversion of KW values in range mean +/- standard deviation:');

fprintf([repmat('%f ', 1, size(result2, 2)) ' '], result2');