CSE1541 Lab 01
Learning to use MATLAB

Tue Jan 14, 2014
Due: Questions 1–3 at the end of the lab, Questions 4-6 on Thu Jan 16 before 11:59PM

Introduction

This first lab has the following components:

Using the MATLAB desktop in EECS

This is an in-lab demonstration.

Creating a script and publishing a report

This is an in-lab demonstration.

The script we created is shown below:

%% Lab 1 Creating a script and publishing a report
% This is the script created during the lab demonstration.
% The demonstration showed you how to create script,
% add comments to the script, use cell mode in a script,
% and publish a script to an HTML report.


%% Question 1
% The radius of the earth is approximately 6.37 * 10^6 meters.
% (a) What is the circumference of the earth in kilometers?
% (b) What is the surface area of the earth in square kilometers?
% (C) What is the volume of the earth in cubic meters?


%% Question 1a

% radius of the earth in meters
radius = 6.37e6;

% circumference in kilometers
circum = 2 * pi * radius / 1000


%% Question 1b

% surface area in square kilometers
surfaceArea = 4 * pi * (radius / 1000)^2


%% Question 1c

% volume in cubic meters
volume = 4 / 3 * pi * radius^3


%% Question 2
% Plot the function y = x^2 for values
% x = -5:0.1:5
% Label the x and y axes.

x = -5:0.1:5;
y = x.^2;
plot(x, y)
xlabel('x');
ylabel('y');

The report produced by publishing the script can be viewed here.

Submitting your script using the EECS submit service

This is an in-lab demonstration.

You can submit a file stored on your computer using the web-based submit service https://webapp.eecs.yorku.ca/submit/. You will need to provide your EECS login credentials to submit your file(s). Once you have logged in, choose the Course (1541) and the Assignment (lab1), Browse for your file or files, and press the Submit Files button.

You may submit files as many times as you like. The most recent submission overwrites all previous submissions.

Lab questions

Create a new script in which to answer the following questions. Publish your script as a web page. When you are finished, submit both your script and published report using the EECS submit service.

In your scripts, please show how you calculated your answers using MATLAB. Please use appropriate variables rather than repeatedly typing in the same numbers. Feel free to use the internet to double check the numeric values of your answers and conversion factors.

Question 1

Firewood is still sold in units known as cords. A cord is equal to a volume of cut wood of dimensions 4 feet high, 8 feet long, and 4 feet deep. What is the volume of a cord in cubic meters?

Question 2

Distances in astrophysics are so large that they have their own units of measurements. A light-year (units ly) is the distance that light travels through a vacuum in one year. 1 ly is approximately 9.5 × 1015 m. An astronomical unit (units AU) is approximately the average Earth-sun distance. 1 AU is defined to be exactly 149597870700 m. A parsec (units pc) can be computed from the following picture:


The angle θ is equal to 1 arcsecond = 1 / 3600 degrees. Using the small angle approximation tan(θ) ≈ θ for θ in radians, and the distances given above, compute the following:

(a) the number of astronomical units in 1 parsec

(b) the number of light-years in 1 parsec

(c) the number of light-years in 1 astronomical unit

Question 3

The equations for motion in a straight line with constant acceleration are given by:

v = v0 + at
x - x0 = v0t + (1 / 2)at2
v2 = v02 + 2a(x - x0)
x - x0 = (1 / 2)(v0 + v)t
x - x0 = vt - (1 / 2)at2

where x0 is the position at time t=0, x is the position at time t, v0 is the velocity at time t=0, v is the velocity at time t, and a is the acceleration.

Suppose that you brake your car from 100 km/h to 60 km/h over a distance of 100 m.

(a) What is the acceleration (assumed constant) in meters per second squared?

(b) How much time elapsed in seconds?

(c) Using the acceleration calculated in (a), what is the total amount of time in seconds needed to bring the car to a complete stop?

(d) In (c), what is the total distance covered in meters?

(e) Using the acceleration calculated in (a) and a different initial velocity, suppose you brought the car to a complete stop in 250 m. What was the total braking time?

Question 4

Textbook Chapter 1, Exercise 15. Use resistance values R1 = 100 Ω, R2 = 200 Ω, and R3 = 400 Ω.

Question 5

Textbook Chapter 1, Exercise 17. You do not need to provide any MATLAB code for your answer. Instead, write your answer in a comment in your script. For example:

%% Question 6
% round is equivalent to floor for values ...
% 
% floor is equivalent to round for values ...

Question 6

Textbook Chapter 1, Exercise 30. Try help elfun to find a function to compute the square root.