Lab Assignment #1.
Lab Assignment #1.
Introduction to Matlab
Spring 2015
Objective:
1.
2.
3.
4.
5.
Obtain Matlab
Familiarize yourself with the Matlab environment
Matlab Basics and Scripts
Solving simple word problems
Vectors and Arrays
Task 1:
If you have not already done so, download a version of Matlab to
your own personal laptop from:
https://software.berkeley.edu/mathematicsstatistics#Matlab
Task 2
Familiarize yourself with the Matlab environment as discussed in
Lab. As well as completing tutorials 1-4 on the following site:
http://www.mathworks.com/academia/student_center/tutorials/play
er/player/content/CoursePlayer.html
Task 3
Solve the following problems with Matlab:
1. You are given two sides of a triangle, a=4.5 and b=6. The
angle between them is 35 degrees. Write a script to find the
length of the third side and the area of the triangle
2. Write a script that validates the relationship between sin ,
cos , and tan by evaluating functions at suitably chosen
values of .
3. It takes an average of 45 horsepower to run an electric car at
an average speed of 35 mph. Write a script to compute the
electrical storage capacity of the battery system that would
make this car practical for a 25-mile commute, recharging the
batteries only at home at night when the electricity is cheap.
How many D cell alkaline batteries would be needed for this?
4. The distance between my house to UC Berkeley is 1.5 miles.
Every morning, I have to take the bus that averages (once it
arrives) 25 mph, or to walk. I can walk at 4 mph. Write a
script to determine how frequently the buses should run to
give them a 50% chance of getting me to the office faster
than walking.
5. You are given a circle with radius 5 centered at x=1, y=2.
You want to calculate the intersection of some lines with that
circle. Write a script t find the x and y of both points of
intersection. You should test this code at least with these
lines:
y = 2x -1
y = -2x -10
y = x + 5.9054
all identical, but the values of the rows range from 200
to 1,000 in equal increments.
b. Next, generate the matrix doublejeopardy, which has
the same dimensions as jeopardy, but whose values
range from 400 to 2,000.
c. You decided to go even one step further and practice
for a round that doesnt even exist yet. Generate a
matrix squaredjeopardy that contains each entry of the
original jeopardy matrix squared.
10.
Write a script named arraycollide that will combine
two arrays, sort them, and then return a new array of a
specified size. Your script should process the following data:
A: a 2-D array of any size
B: another 2-D array that may be a different size from
A
N: a number specifying the number of rows for the new
array
M: a number specifying the number of columns for the
new array
Your script should produce an array, res, of size N x M that
contains the first N x M elements of A and B and is sorted
columnwise. If N x M is larger than the total number of
elements in A and B, you should fill the empty spaces with 0.
Test this script by writing another script that repeatedly sets
the values of A, B, M, and N and then invokes your
arraycollide script.