CS 104 - Lab 6
Due in Blackboard Assignment (one file named lastnameLab6.zip) Week 9 before Lab (8:35am)
put all the m-files and diary file in one zip file

Objectives:

  1. (20 points) Create m-file scripts/functions to solve some basic vector problems in MATLAB

Tasks:

1. (20 points) Create m-file scripts/functions to solve some basic problems in MATLAB

A. (4 points) A. Write an m-file script called TimesTable.m that prompts the user for an integer multiplier (it is fine to assume the user enters a positive integer from 1-9). Then create the "times table" for that integer multiplied by the integers zero through ten. Format and display the times table as shown below.

B. (6 points) Write an m-file function called projectileMotion which should take three arguments, a scalar initial velocity in meters/sec, a scalar angle in degrees, and a vector of times "t" (in seconds) to calculate the x and y location of the projectile at those times. The function should return nothing and plot the x and y locations (showing the path of the projectile). See http://en.wikipedia.org/wiki/Projectile_motion Assume gravity is the only external force (no wind resistance, etc). Here are some sample calls to test your function:

>> projectileMotion(100, 30, linspace(0,10,20)); 
>> projectileMotion(100, 20, linspace(0,10,20)); 
>> projectileMotion(100, 50, linspace(0,10,20)); 

Why do some of the graphs "y value" go below zero?

C. (4 points) A few students got together to form an investment group. They wanted to pool their savings and decide which investments would maximize their return. Each student was to find an investment, determine the interest (compounded annually, constant interest rate) then calculate the value (future value) of the initial investment over time. Each student was to report about the investment to the group; the group could then decide which investment(s) were most promising. You are one of the investors and decided that you would like to write a program that would calculate the future value of the investment given the interest and the principal.

The formula for calculating the future value knowing interest and principal is: FV = P(1 + r)^n where:

Your m-file function "futureValue" should take three arguments, a scalar interest rate, a scalar principal and a vector of years (n) to calculate the the future value at. Your m-file should not return any values, just a discrete plot using the "scatter" function of the years n vs. the future value. Use Help scatter if necessary.

Complete the test table including adding three more of your own test cases, then write the function and test it.

D. (6 points) Write a matlab function to calculate the inverse tangent for -1 < x < 1 using the taylor series expansion given an argument "n" for the number of terms to calculate.

Copyright CS, Illinois Institute of Technology