Assignment 04 - University of California, Berkeley Fall...

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

View Full Document Right Arrow Icon
University of California, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M. Frenklach, R. Horowitz E7, Assignment 4 Assigned: Thursday, September 25, 2008 Due: 12:00pm, Friday, October 3, 2008. This assignment is an introduction to creating your own functions in MATLAB . As before, turn in the hard copy of your published file to the drop boxes in Etcheverry 1109 and upload the soft copy of your script (the M-file) to bspace. Do not forget to name your M- file as lastname_firstname_SID_lab04.m MATLAB commands * introduced in this assignment: fminbnd, fzero 1. In this problem, you will create several functions. Remember that most functions that you create must be saved in an M-file that has the same name as the function name (except for anonymous, subfunctions and nested functions). Don’t forget to suppress all command lines inside the functions unless you want them to appear in your command window / HTML. Also, try not to name your functions using the same name as a MATLAB built-in function. IMPORTANT : Since your function will be written inside another M-file rather than your main script, you need to use type to display the contents of your function in the published HTML (The syntax for using type is provided in the following sections). a) Write a function called my_adder that takes two input arguments, in1 , in2 and returns one output argument, out , which equals the sum of the two input arguments. The declaration line of your function should look like the following. function out = my_adder(in1,in2) After you have written your function, run the following commands in the command window (not in your script) and comment on what you observe. >> a = 5; >> b = 16; >> my_adder(3,4) * Please refer to MATLAB help to learn how to use the functions introduced in this assignment. Assignment 4 E7 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
University of California, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M. Frenklach, R. Horowitz >> c = my_adder(a,b) >> my_adder([5 6],[1 2]) >> in1 + in2 >> c – out NOTE: Don’t forget to include the line type my_adder to your main script file to display its contents in the HTML.
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.

Page1 / 7

Assignment 04 - University of California, Berkeley Fall...

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