Sep 3, 2015

Lecture 4

Today is the second day of the second week. I hope to learn how to create functions in MATLAB. I find myself constantly comparing MATLAB to normal C++.

Using trig functions: sin(x), cos(x), tan(x). Inverse trig: asin(x), acos(x), atan(x).
Also tested is the sind(x) function which, calculates sin(x) where x is in degrees. MATLAB calculates trig functions in radians by default. Not pictured, but we were also shown how to search for a function using "help" and "doc".
Practical exercises for trig functions.

Then we did a context example using trig functions to find the net force acting on a hot air balloon. The forces acting on the balloon were the weight, the force of buoyancy, and the force of the wind acting at an angle.








Here are screenshots of the code and results.



Then we went over data analysis functions: mean(x), median(x), and mode(x). MATLAB executes the functions by column. To execute functions by row, use the apostrophe (') after the vector name.
Practical exercises for data analysis functions.
There are some more functions for data analysis: sum(x), prod(x), cumsum(x), cumprod(x). The sum(x) and prod(x) functions are self-explanatory. The cumsum(x) and cumprod(x) functions print each sum as it goes through the vector.
There are also sort functions in MATLAB: sort(x) sorts the elements into ascending order, sort(x, 'descend')  sorts the elements by descending order. Use sortrows(x) and sortrows(x, 'descend') to sort the rows.
We did a context example with calculating precipitation per month and for the entire year.


Then we went over statistics functions: std(x) for standard deviation and var(x) for variance.
Practical exercises for statistics functions.
We went over various functions for complex and imaginary numbers: abs(x) for the magnitude of a complex number, angle(x) for the angle of the complex number represented in polar coordinates, complex(x,y) creates a complex number with x as the real component and y as the imaginary component, real(x) and imag(x) extracts the respective real and imaginary components from a complex number , conj(x) creates a conjugate of a real number.
Practical exercises for complex number functions.