Activity: MATLAB Exercises
Objectives
• Create well-documented MATLAB script
• Practice MATLAB commands for mathematical computations
• Practice MATLAB commands for working with variables, vectors, and
matrices
• Practice MATLAB commands for conditions
• Practice MATLAB commands for simple loops
• Practice MATLAB commands for 2D plots
Procedure
Start by creating a MATLAB script (m-file) for ALL the MATLAB work for this activity.
Make sure to document your script using comments.
1. In the script, enter the commands to perform the following three calculations:
2. In the script, complete the following steps
A. ) Use 3 different methods to define the row vector:
j = [ XXXXXXXXXX12]
B. ) Solve the polynomial and display the resulting k vector when
plugging in the vector j defined in part 2A:
k = 2j2 -6j +13
3. In the script, define the variable "BD" as the number of the month you were
orn
For example if my birthday is in October, BD would equal 10
With this variables defined, write an else-if-elseif statement based on the
following conditions:
You are born in a Spring month (March, April, May) so "spring" is equal to 1
You are born in a Summer month (June, July, August) so "summer" is equal
to 1
You are born in a Fall month (September, October, November) so "fall" is
equal to 1
You are born in a Spring month (December, January, Fe
uary) so "winter" is
equal to 1
Verify that the code works for a birthday month in each season.
4. Write a for loop to compute factorial of 100, i.e. compute the product of first
100 natural numbers. Do not use the pre-existing "prod" or "factorial"
functions in MATLAB, you must use the for loop along with simple operations
like multiplication.
At the end of the for loop, write a statement to print the final output in the
command window.
5. At the end of the script define a MATLAB function whose name is of your
choice. The function must take as input a vector of length 5 with numbers in
it, and produce as output the sum of squares of those numbers.
In the script write a command to call this function and print the sum of
squares of 2, 4, 6, 8, 10.
6. In the script, define appropriate vectors and plot the following two functions in
a single plot. Make sure to use different line attributes to differentiate the two
curves, add a title to the plot, label the axes, and add a legend.
Submission Criteria
Publish your script as a pdf file by clicking the 'PUBLISH' tab on the top menu, clicking
the 'Publish' button for the drop-down menu, choosing 'Editing Publish Options',
changing the Output File Format from html to pdf, and clicking 'Publish'. See
screenshots below.
Submit a single pdf file for this activity.