HW1 - Matlab - 2016
HW1 - Matlab - 2016
(Second Semester-2016)
Assignment-1: Introduction to Matlab
Due: Wednesday, February 17, 2016 (10AM)
……………………………………………………………………………………………………..
This homework is designed to teach you to think in terms of matrices and vectors because this is how
Matlab organizes data. You will find that complicated operations can often be done with one or two lines
of code if you use appropriate functions and have the data stored in an appropriate structure. The other
purpose of this homework is to make you comfortable with using help to learn about new functions. The
names of the functions you’ll need to look up are provided in bold where needed
What to turn in: Copy the text from your both scripts and output and paste it into a document. If a
question asks you to plot or display something to the screen, also include the plot and screen output your
code generates. Submit either a *.doc or *.pdf file.
Submit all your codes in a “Zipfile” using “winrar” together with the pdf/word file. On top of your codes
comment ( % student name, Index Number, Assignment 1, Date )
For problems 1-7, write a script called shortProblems.mand put all the commands in it. Separate and
label different problems using comments.
Isaac Otchere 1
Isaac Otchere 2
Isaac Otchere 3
Isaac Otchere 4
Isaac Otchere 5
9. Throwing a ball. Below are all the steps you need to follow, but you should also add your own
meaningful comments to the code as you write it.
a. Start a new file in the Matlab Editor and save it as throwBall.m
b. At the top of the file, define some constants (you can pick your own variable names)
i. Initial height of ball at release = 1.5 m
2
ii. Gravitational acceleration = 9.8 m/s
iii. Velocity of ball at release = 4 m/s
iv. Angle of the velocity vector at time of release = 45 degrees
c. Next, make a time vector that has 1000 linearly spaced values between 0 and 1, inclusive.
d. If x is distance and y is height, the equations below describe their dependence on time and all
the other parameters (initial height h , gravitational acceleration g , initial ball velocity v , angle
of velocity vector in degrees θ ). Solve for x and y
Isaac Otchere 6
Isaac Otchere 7
10. Write a simple shuffling ‘encryption’ algorithm.
Isaac Otchere 8
Isaac Otchere 9