Ctufekci
Ctufekci
Ctufekci
Exercise Set 3
Spring 2012
Dr. C. Tufekci
Page 1 of 2
YTU Mechatronics
Lab II Mechanics
Exercise Set 3
Spring 2012
Writing Your Own Functions with MATLAB 2) The sine of an angle can be approximately calculated from the following series expansion: [ ]
a. Write a MATLAB function in a functional form that uses first 3 terms of the series. return_value = mySinFunc (theta) Find the error of your function with respect to built-in MATLAB function. b. Convert your MATLAB function in the following form: return_value = mySinFunc (theta, err) where theta is angle in degrees and err is a specified error value and return_value is the resulting sine value. Note that the error value is calculated as: | | where sin is the built-in function, whereas Sin is the series expansion. c. Add a flag to plot your sine function against built-in sine function in the range of return_value = mySinFunc (theta, err, plot_flag) If plot_flag is set to 1, the plot is sketched otherwise your function must behave like in part b.
Dr. C. Tufekci
Page 2 of 2
YTU Mechatronics