class5a_matlab_activities_engr195(II)s10

# class5a_matlab_activities_engr195(II)s10 - ENGR 195(II –...

This preview shows pages 1–2. Sign up to view the full content.

ENGR 195(II) – Spring 2010 Activity 1 Class 5a Activity 1 – Writing a function to compute the volume of a box (Estimated Time: 10 minutes) In this exercise, you and a partner will practice writing a user-defined function starting from a working program. 1. Open function_header_template.m in the MATLAB editor and re-save as an appropriately named user-defined function for the task below. 2. Convert the program below to be a user-defined function: % Script to compute the volume of a box % Inputs box_l = 2 % box length (m) box_w = 0.6 % box width (m) box_d = 0.6 % box depth (m) % Calculation box_vol = box_l * box_w * box_d %box volume (m^3) % Output fprintf('Box volume (m^3) is %g',box_vol) 3. Make sure your function works as it should: The hard-coded numbers should be eliminated; all variables should be passed as arguments The output should not be displayed; the output should only be returned by the function Make sure your code works with vectors 4. Email your script to your partner so your partner can the save the file.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ENGR 195(II) – Spring 2010 Activity 2 Class 5a Activity 2 – Creating a function (Estimated Time: 15 minutes) Through this exercise, you and a partner will create a user-defined function from the beginning. 1. Open function_header_template.m in the MATLAB editor and re-save as an appropriately named user-defined function for the task below. 2. Write a MATLAB function that has as arguments the lengths of two sides (a and b) of an oblique triangle and the angle (γ) between them and returns the length of the third side (c) and the remaining two angles (α and β). The length of the third side is given by: γ cos 2 c 2 2 ab b a-+ = The angles α and β are given by: =-c a α sin sin 1 =-c b β sin sin 1 3. For the function: Angles need to be in degrees; Test with vectors 4. Email your script to your partner so your partner can the save the file. a b c β γ α...
View Full Document

## This note was uploaded on 02/20/2012 for the course ENGR 195 taught by Professor Staff during the Spring '08 term at Purdue.

### Page1 / 2

class5a_matlab_activities_engr195(II)s10 - ENGR 195(II –...

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

View Full Document
Ask a homework question - tutors are online