>> script1 Your variables are: leaving m-file function testit1 output = 5 8 5 dummy = 5 8 5 leaving script1 - did you get the dimensions and shapes correct? Name Size Elements Bytes Density Complex dummy 3 by 1 3 24 Full No output 1 by 3 3 24 Full No x 1 by 5 5 40 Full No y 1 by 8 8 64 Full No z 1 by 5 5 40 Full No Grand total is 24 elements using 192 bytes >> type script1.m % m-file script [script1.m] for practice midterm 1/cs205/fall 98 % clear % empty the work space who % x = 0:0.5:2; y = -2:5; z = 1:2:10; % invoke the function, "testit1" [output,dummy] = testit1 (x,y,z); output dummy fprintf(' leaving script1 - did you get the dimensions and shapes correct?\n\n') whos >> type testit1 function [out1,out2] = testit1 (in1, in2, in3) % m-file function devised for practice midterm 2 in cs 205/fall 96 % the file is available from the class home page % http://www.stewart.cs.sdsu.edu/cs205/ % and from the individual student's rohan account for this course % so that you can practice with it to check your understanding of % communications between MATLAB m-file scripts and m-file functions % n1 = length(in1); n2 = length(in2); n3 = length (in3); % ; suppressed output % out1 = [n1, n2, n3]; % first output parameter is a matrix of size 1 by 3 out2 = [n1; n2; n3]; % second output parameter is a matrix of size 3 by 1 fprintf ('\n leaving m-file function testit1 \n') >> >> >> >> >> >> >> >> script2 finished with script 2 Your variables are: x y >> >> type script2 % m-file script [script2.m] for practice midterm 1/cs205/fall 98 % clear % empty the work space x = -3:0.1:3; y = rect(x); % a function to compute the "rectangle function" plot (x,y), title(' Rectangle Function'), ... xlabel ('x'), ylabel ('y'), grid fprintf('\n\n finished with script 2 \n\n') who >> >> >> type rect function r = rect (x) % RECT The rectangular function is defined to be 1 % on [-0.5,0.5] and 0 elsewhere % % m-file function [rect.m] devised for practice midterm 1 in cs 205/spring 98 % the file is available from the class home page % http://www.stewart.cs.sdsu.edu/cs205/ % and from the individual student's rohan account for this course % so that you can practice with it to check your understanding of % communications between MATLAB m-file scripts and m-file functions % % initialize output matrix to be all zeros, same size as input r = zeros(size(x)); % set1 = find(abs(x) <= 0.5); % identify component of input vector in [-0.5,0.5] r(set1) = ones(size(set1)); % for those component in [-0.5,0.5], set value 1 >> >> >> >> >> >> >> script3 Your variables are: leaving m-file function testit1 output = 1 1 4 dummy = 1 1 4 what were the dimensions of the constants? Your variables are: dummy output >> >> >> type script3 % m-file script [script3.m] for practice midterm 1/cs205/fall 98 % % start with an empty workspace clear who % invoke the function, "testit1" with constants as inputs [output,dummy] = testit1 (1,0,[1,2,3,4]); output dummy fprintf(' what were the dimensions of the constants? \n\n') who >> >> >> type testit1 function [out1,out2] = testit1 (in1, in2, in3) % m-file function devised for practice midterm 2 in cs 205/fall 96 % the file is available from the class home page % http://www.stewart.cs.sdsu.edu/cs205/ % and from the individual student's rohan account for this course % so that you can practice with it to check your understanding of % communications between MATLAB m-file scripts and m-file functions % n1 = length(in1); n2 = length(in2); n3 = length (in3); % ; suppressed output % out1 = [n1, n2, n3]; % first output parameter is a matrix of size 1 by 3 out2 = [n1; n2; n3]; % second output parameter is a matrix of size 3 by 1 fprintf ('\n leaving m-file function testit1 \n') >> >> >> script4 leaving m-file function testit1 output = 16 19 1 dummy = 16 19 1 s = this is a string this is a string finished script 4 Name Size Elements Bytes Density Complex dummy 3 by 1 3 24 Full No output 1 by 3 3 24 Full No s 1 by 16 16 128 Full No Grand total is 22 elements using 176 bytes >> >> type script4 % m-file script [script4.m] for practice midterm 1/cs205/fall 98 % clear % empty the workspace s = 'this is a string'; % invoke the function, "testit1" [output,dummy] = testit1 (s,' what is the length',0); output dummy s disp(s) fprintf(' \n\nfinished script 4 \n') whos >> >> >> type testit1 function [out1,out2] = testit1 (in1, in2, in3) % m-file function devised for practice midterm 2 in cs 205/fall 96 % the file is available from the class home page % http://www.stewart.cs.sdsu.edu/cs205/ % and from the individual student's rohan account for this course % so that you can practice with it to check your understanding of % communications between MATLAB m-file scripts and m-file functions % n1 = length(in1); n2 = length(in2); n3 = length (in3); % ; suppressed output % out1 = [n1, n2, n3]; % first output parameter is a matrix of size 1 by 3 out2 = [n1; n2; n3]; % second output parameter is a matrix of size 3 by 1 fprintf ('\n leaving m-file function testit1 \n') >> exit 3083 flops.