disp('hello'); hello a = 3; a a = 3 B = [1,2,5; 3,6,8] B = 1 2 5 3 6 8 B(2,3) ans = 8 a - 6 ans = -3 c - 6 {Undefined function or variable 'c'. } c = 4 c = 4 c - 6 ans = -2 % conditionals d = 17; % set d to a value edit program1.m ls program* program1.m program1.m~ program1 For this pay period, your pay is 493.6000 type program1.m % program1.m % % This is an example program in MATLAB. % % -Michael Weeks % % Usage: % program1 % % Give the rate of hourly pay in dollars. pay_rate = 12.34; % hours worked this pay period hours_worked = 40.0; pay = hours_worked * pay_rate; disp('For this pay period, your pay is '); disp(pay); clc help program1 program1.m This is an example program in MATLAB. -Michael Weeks Usage: program1 whos Name Size Bytes Class Attributes B 2x3 48 double a 1x1 8 double ans 1x1 8 double c 1x1 8 double d 1x1 8 double hours_worked 1x1 8 double pay 1x1 8 double pay_rate 1x1 8 double clear a c d whos Name Size Bytes Class Attributes B 2x3 48 double ans 1x1 8 double hours_worked 1x1 8 double pay 1x1 8 double pay_rate 1x1 8 double program1 For this pay period, your pay is 493.6000 You deserve overtime pay. have a nice day program1 For this pay period, your pay is 493.6000 have a nice day program1 For this pay period, your pay is 505.9400 You deserve overtime pay. have a nice day program1 For this pay period, your pay is 505.9400 You deserve overtime pay. have a nice day program1 For this pay period, your pay is 481.2600 If you work more hours you can get overtime pay. have a nice day type program1.m % program1.m % % This is an example program in MATLAB. % % -Michael Weeks % % Usage: % program1 % % Give the rate of hourly pay in dollars. pay_rate = 12.34; % hours worked this pay period hours_worked = 39.0; pay = hours_worked * pay_rate; disp('For this pay period, your pay is '); disp(pay); if (hours_worked > 40) disp('You deserve overtime pay.'); else if (hours_worked < 40) disp('If you work more hours you can get overtime pay.'); end end disp('have a nice day'); program1 For this pay period, your pay is 481.2600 If you work more hours you can get overtime pay. have a nice day program1 hours_worked = 41 For this pay period, your pay is 505.9400 You deserve overtime pay. have a nice day % conditions < > <= >= == ~= program1 hours_worked = 40 For this pay period, your pay is 493.6000 have a nice day type program1.m % program1.m % % This is an example program in MATLAB. % % -Michael Weeks % % Usage: % program1 % % Give the rate of hourly pay in dollars. pay_rate = 12.34; % hours worked this pay period hours_worked = 40.0 pay = hours_worked * pay_rate; disp('For this pay period, your pay is '); disp(pay); if (hours_worked > 40) disp('You deserve overtime pay.'); else if (hours_worked < 40) disp('If you work more hours you can get overtime pay.'); else disp('You worked exactly 40 hours.'); end end disp('have a nice day'); program1 hours_worked = 40 For this pay period, your pay is 493.6000 You worked exactly 40 hours. have a nice day type program1.m % program1.m % % This is an example program in MATLAB. % % -Michael Weeks % % Usage: % program1 % % Give the rate of hourly pay in dollars. pay_rate = 12.34; % hours worked this pay period hours_worked = 40.0 pay = hours_worked * pay_rate; disp('For this pay period, your pay is '); disp(pay); if (hours_worked > 40) disp('You deserve overtime pay.'); else % nested if statement if (hours_worked < 40) disp('If you work more hours you can get overtime pay.'); else disp('You worked exactly 40 hours.'); end end disp('have a nice day'); program1 hours_worked = 40 For this pay period, your pay is 493.6000 You worked exactly 40 hours. have a nice day type program1.m % program1.m % % This is an example program in MATLAB. % % -Michael Weeks % % Usage: % program1 % % Give the rate of hourly pay in dollars. pay_rate = 12.34; % hours worked this pay period hours_worked = 40.0 pay = hours_worked * pay_rate; disp('For this pay period, your pay is '); disp(pay); %{ multiline comments this is also a comment %} % htiewrhgerh lkehrlghelrkghel hvqkdvleqhgwqehg lkerh lkeqhrglk qklheql % hhjj eghewkjhjewhehoiufhefheo oeoruheor huehovi ewovjqev qeohvouqehvo % jfdd % if (hours_worked > 40) % disp('You deserve overtime pay.'); % else % % nested if statement % if (hours_worked < 40) % disp('If you work more hours you can get overtime pay.'); % else % disp('You worked exactly 40 hours.'); % end % end if (hours_worked > 40) disp('You deserve overtime pay.'); elseif (hours_worked < 40) disp('If you work more hours you can get overtime pay.'); else disp('You worked exactly 40 hours.'); end disp('have a nice day'); program1 hours_worked = 40 For this pay period, your pay is 493.6000 You worked exactly 40 hours. have a nice day whos Name Size Bytes Class Attributes B 2x3 48 double ans 1x1 8 double hours_worked 1x1 8 double pay 1x1 8 double pay_rate 1x1 8 double pay pay = 493.6000 disp(pay) 493.6000 sprintf('%6.2f', pay) ans = 493.60 disp(sprintf('%6.2f', pay)) 493.60 disp(sprintf('Your pay is %6.2f', pay)) Your pay is 493.60 disp(sprintf('Your pay is $%6.2f', pay)) Your pay is $493.60 disp(sprintf('Your pay is $%7.2f', pay)) Your pay is $ 493.60 hours_worked hours_worked = 40 disp(sprintf('You worked %7.2f hours', hours_worked)) You worked 40.00 hours disp(sprintf('You worked %4d hours', hours_worked)) You worked 40 hours disp(sprintf('You worked %d hours', hours_worked)) You worked 40 hours disp(sprintf('You worked %d hours', 123)) You worked 123 hours disp(sprintf('You worked %5.1f hours', 123.45)) You worked 123.5 hours disp(sprintf('You worked %5.2f hours', 123.45)) You worked 123.45 hours disp(sprintf('You worked %6.2f hours', 123.45)) You worked 123.45 hours disp(sprintf('You worked %s hours', 'hello')) You worked hello hours type program1.m % program1.m % % This is an example program in MATLAB. % % -Michael Weeks % % Usage: % program1 % % Give the rate of hourly pay in dollars. pay_rate = 12.34; % hours worked this pay period hours_worked = 40.0 pay = hours_worked * pay_rate; disp('For this pay period, your pay is '); disp(pay); %{ multiline comments this is also a comment %} % htiewrhgerh lkehrlghelrkghel hvqkdvleqhgwqehg lkerh lkeqhrglk qklheql % hhjj eghewkjhjewhehoiufhefheo oeoruheor huehovi ewovjqev qeohvouqehvo % jfdd % if (hours_worked > 40) % disp('You deserve overtime pay.'); % else % % nested if statement % if (hours_worked < 40) % disp('If you work more hours you can get overtime pay.'); % else % disp('You worked exactly 40 hours.'); % end % end if (hours_worked > 40) disp('You deserve overtime pay.'); elseif (hours_worked < 40) disp('If you work more hours you can get overtime pay.'); elseif (pay > 100) disp('We pay you a lot'); else disp('You worked exactly 40 hours.'); end disp('have a nice day'); program1 hours_worked = 40 For this pay period, your pay is 493.6000 We pay you a lot have a nice day program1 hours_worked = 41 For this pay period, your pay is 505.9400 You deserve overtime pay. have a nice day program1 hours_worked = 39 For this pay period, your pay is 481.2600 If you work more hours you can get overtime pay. have a nice day program1 hours_worked = 39 For this pay period, your pay is 481.2600 If you work more hours you can get overtime pay. have a nice day program1 hours_worked = 40 For this pay period, your pay is 493.6000 We pay you a lot have a nice day clc program1 change hours_worked = 40 For this pay period, your pay is 493.6000 We pay you a lot have a nice day program1 change2 hours_worked = 40 For this pay period, your pay is 493.6000 We pay you a lot have a nice day type program1.m % program1.m % % This is an example program in MATLAB. % % -Michael Weeks % % Usage: % program1 % % Give the rate of hourly pay in dollars. pay_rate = 12.34; disp('change2'); % hours worked this pay period hours_worked = 40.0 pay = hours_worked * pay_rate; disp('For this pay period, your pay is '); disp(pay); %{ multiline comments this is also a comment %} % htiewrhgerh lkehrlghelrkghel hvqkdvleqhgwqehg lkerh lkeqhrglk qklheql % hhjj eghewkjhjewhehoiufhefheo oeoruheor huehovi ewovjqev qeohvouqehvo % jfdd % if (hours_worked > 40) % disp('You deserve overtime pay.'); % else % % nested if statement % if (hours_worked < 40) % disp('If you work more hours you can get overtime pay.'); % else % disp('You worked exactly 40 hours.'); % end % end if (hours_worked > 40) disp('You deserve overtime pay.'); elseif (hours_worked < 40) disp('If you work more hours you can get overtime pay.'); elseif (pay > 100) disp('We pay you a lot'); else disp('You worked exactly 40 hours.'); end disp('have a nice day'); hours_worked = 40 For this pay period, your pay is 493.6000 clc hours_worked = 40 For this pay period, your pay is 493.6000 hours_worked = 41 For this pay period, your pay is 505.9400 ' fff ' + 12 ans = 44 114 114 114 44 disp(' fff ' + 12) 44 114 114 114 44 disp(' fff ' + 0) 32 102 102 102 32 disp(' fff ' + 1) 33 103 103 103 33 disp(' fff ') fff disp(sprintf('You worked %6.2f hours', 123.45)) You worked 123.45 hours disp(sprintf('For this pay period, your pay is $%6.2f', pay)); For this pay period, your pay is $505.94 disp(sprintf('For this pay period, your %%pay is $%6.2f', pay)); For this pay period, your %pay is $505.94 type program1.m % program1.m % % This is an example program in MATLAB. % % -Michael Weeks % % Usage: % program1 % % Give the rate of hourly pay in dollars. pay_rate = 12.34; %% % hours worked this pay period hours_worked = 41.0 pay = hours_worked * pay_rate; disp('For this pay period, your pay is '); disp(pay); %{ multiline comments this is also a comment %} %% % htiewrhgerh lkehrlghelrkghel hvqkdvleqhgwqehg lkerh lkeqhrglk qklheql % hhjj eghewkjhjewhehoiufhefheo oeoruheor huehovi ewovjqev qeohvouqehvo % jfdd % if (hours_worked > 40) % disp('You deserve overtime pay.'); % else % % nested if statement % if (hours_worked < 40) % disp('If you work more hours you can get overtime pay.'); % else % disp('You worked exactly 40 hours.'); % end % end if (hours_worked > 40) disp('You deserve overtime pay.'); elseif (hours_worked < 40) disp('If you work more hours you can get overtime pay.'); elseif (pay > 100) disp('We pay you a lot'); else disp('You worked exactly 40 hours.'); end disp('have a nice day'); % Currently, it says: % For this pay period, your pay is % 505.9400 % I would like to say % For this pay period, your pay is $505.94 disp(sprintf('For this pay period, your pay is $%6.2f', pay)); diary off