BENG 449 Problem 2 1

BENG 449 Problem 2 1 - if (current_length >...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
2/5/08 5:20 PM MATLAB Command Window 1 of 1 >> % BENG 449 -- Problem Set 2, Question 1 % Written by Alex Lemon % Put the expressions to be evaluated into a cell array PS21expressions{1} = '2/2*3'; PS21expressions{2} = '6-2/5+7^2-1'; PS21expressions{3} = '10/2\5-3+2*4'; PS21expressions{4} = '3^2/4'; PS21expressions{5} = '3^2^2'; PS21expressions{6} = '2 + round(6/9+3*2)/2-3'; PS21expressions{7} = '2 + floor(6/9+3*2)/2-3'; PS21expressions{8} = '2 + ceil(6/9+3*2)/2-3'; disp([' ']) disp(['Results for BENG 449 Problem Set 2, Question 1:']) % Find the width of the longest expression so that we % can align the equals signs when we display the results PS21spacer_length = length(PS21expressions{1}); for i = 2:length(PS21expressions) current_length = length(PS21expressions{i});
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (current_length > PS21spacer_length) PS21spacer_length = current_length; end end % Evaluate the expressions and display the results for i = 1:length(PS21expressions) PS21spacer = ['']; % Generate the spacer string to align the equals signs for j = length(PS21expressions{i}):PS21spacer_length PS21spacer = [PS21spacer ' ']; end disp([(i + 'a' - 1), '. ', PS21expressions{i}, . .. PS21spacer, ' = ', num2str(eval(PS21expressions{i}))]) end Results for BENG 449 Problem Set 2, Question 1: a. 2/2*3 = 3 b. 6-2/5+7^2-1 = 53.6 c. 10/2\5-3+2*4 = 6 d. 3^2/4 = 2.25 e. 3^2^2 = 81 f. 2 + round(6/9+3*2)/2-3 = 2.5 g. 2 + floor(6/9+3*2)/2-3 = 2 h. 2 + ceil(6/9+3*2)/2-3 = 2.5 >>...
View Full Document

Ask a homework question - tutors are online