Lab 02 - Problems - UNIVERSITY OF CALIFORNIA, BERKELEY...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
UNIVERSITY OF CALIFORNIA, BERKELEY Engineering 7 – Spring 2009 Department of Civil and Environmental Engineering Instructor: Professor Rector 1 Lab 02 Topics : Functions, Switches, Conditionals Assigned : Friday, 02/06/2009 Due : Friday, 02/06/2009 at 12:00 pm Type : Take Home Remember to use the help command if you are not familiar with a command. It will be much faster than waiting for a GSI to answer your question. Moreover, a list of useful commands is provided at the end of this document. For this lab, you may submit your report as one Word document or one PDF file. Remember to submit both a hard copy of your report and an electronic copy on Bspace. Thanks! 1. Link Between colon Notation and Array Manipulation (revisited) The start:increment:end notation and the colon notation for arrays are similar. Create the 5x5 identity matrix, store it in Z and use the start:increment:end notation to extract the rows 1, 3 and 5 of Z, but only the elements in the 2 nd and 4 th column of those rows. Copy the commands you typed into your report, as well as the output. You should only need 1 line of code to create the identity matrix, and 1 line of code to retrieve the values from Z . 2. Inputs and Outputs of Functions: An Exercise in Output Prediction The purpose of this exercise is to make you more flexible with how you treat MatLab functions. In this exercise, make sure you identify the important parts of a function and recognize different ways of calling the function. Also please note that commenting for all exercises in the future is strongly encouraged; it is both helpful for us to grade your work and good programming practice. (a) Read the function below. Rewrite the function’s code in MatLab, but with complete comments as indicated. function [distance, X, Y] = dist_plot(x1,y1,x2,y2) % The name of the function is < put function’s name here > % This function’s 4 inputs are the variables: % < define each of the 4 input variables here! > % The function’s 3 outputs are the variables: % < define each of the 3 output variables here! > % < briefly describe the purpose of the following 2 lines here > distance = ((x1-x2).^2 + (y1-y2).^2) ^.5; ['The distance between the two points is ' num2str(distance)] % < briefly describe the purpose of the following 3 lines here > X = [x1,x2]; Y = [y1,y2]; plot(X,Y,'ro-'); % < briefly describe the purpose of the following 4 lines here > grid on;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lab 02 2 UNIVERSITY OF CALIFORNIA, BERKELEY Engineering 7 – Spring 2008 Department of Civil and Environmental Engineering Instructor: Professor Rector title('Distance between 2 points'); xlabel('X'); ylabel('Y'); (b) Let x1 = 11, y1 = 9, x2 = 15, and y2 = 12. Predict what the following lines of code will output. Note that you should be able to predict the answer WITHOUT executing your MatLab script! You do not have to execute the commands; all that is required are comments. (i)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/12/2011 for the course E 7 taught by Professor Patzek during the Spring '08 term at University of California, Berkeley.

Page1 / 6

Lab 02 - Problems - UNIVERSITY OF CALIFORNIA, BERKELEY...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online