Starting from:

$30

ASSIGNMENT #1 Solution

This is a really large class and the logistics of grading assignments are challenging. Me and the markers require your help in making this process go smoothly. Please ensure that your assignments conform to the following requirements - any violation will result in getting a zero for the particular assignment.




All assignments should be submitted electronically through the ConneX course website and shoud be SINGLE PDF FILES. No other formats will be accepted.. Handwrit-ten answers are ok but they will need to be scanned and merged into a single pdf le together with any code examples and associated plots.




The assignment number, student name and student number should be clearly visible on the top of every page of your assignment submission.




PLEASE DO NOT COPY THE ASSIGNMENT DESCRIPTION IN YOUR SUBMISSION




The asnwers to the questions should be in the same order as in the assignment speci-cation.




Some of the questions of the assignments are recycled from previous years but typically with small changes in either the description or the numbers. Any submission that contains numbers from previous years in any questions will be immediately graded with zero.




Any assignment related email questions should have a subject line of the form CSC349A Assignment X, where X is the number of the corresponding assignment.




The total number of points for this assignment is 20.




Question #1 - 10 marks.




A MATLAB function M- le for Euler's method (as described in class and on pages 17-19 of the textbook) for solving the di erential equation




dvdt = g mcv







(this is (1.9) on page 14) is given below. As discussed in class, this numerical method

is obtained by approximating dv at time ti by v(ti+1) v(ti) , which results in the computed




dt ti+1 ti

approximation

h c i

v(tt+1) = v(ti) + g mv(ti) (ti+1 ti):







To create a MATLAB function M- le, either type edit in the Command Window or select HOME ! New ! Script or select HOME ! New ! Function (the latter gives you a template for creating a function).




1



Each of these options will open a new window (an Editor window) in which to type in the MATLAB statements for Euler's method. Enter the following. Statements starting with % are comments, documenting the MATLAB code.




function Euler(m,c,g,t0,v0,tn,n)




print headings and initial conditions



fprintf('values of t approximations v(t)\n')




fprintf('%8.3f',t0),fprintf('%19.4f\n',v0)




compute step size h h=(tn-t0)/n;



set t,v to the initial values t=t0;



v=v0;




compute v(t) over n time steps using Euler's method for i=1:n



v=v+(g-c/m*v)*h; t=t+h; fprintf('%8.3f',t),fprintf('%19.4f\n',v)




end




To save your M- le, select




EDITOR ! Save ! Save As...

At the top of this window, it should say




File name: Euler.m




Save as type: MATLAB les (*.m)




Select




Save




to save your le, and close the Editor window.




In order to use the above function, you must specify values for the 7 local parameters in the function Euler:




m is the mass of the falling object




c is the drag coe cient




g is the gravity constant




t0 is the initial time, v0 is the initial velocity




tn is the nal time at which the velocity is to be computed n is the number of time steps into which [t0; tn] is divided







Thus, in the function Euler, the step size h = (tn t0)=n is computed, and Euler's method is used to compute an approximation to the solution v(t) of the di erential equation at the n points (values of time)




t0 + h; t0 + 2h; t0 + 3h; t0 + 4h; : : : ; t0 + nh = tn:










2



For example, in order to use Euler to solve the problem given in Example 1.2 on page 17 and to save your results in a le for printing, you could enter the following (in the MATLAB Command Window):




diary lename




Euler ( 68.1 , 12.5 , 9.81, 0 , 0 , 12 , 6 )







fthe desired results should appear hereg




diary o







Create a copy of the MATLAB function Euler in your installation of MATLAB. Modify the function so that it creates and returns two matrices, one containing the times used in the calculations and one for the resulting velocities.



Note, we index matrices in MATLAB with round brackets and we start indexing at 1




NOT 0. That is, if t is a vector representing the times, then t(1) should contain time t0 and t(2) should contain time t1 = t0 + h, etc. The nal matrices should be




t = [t0 t1 : : : tn] and v = [v(t0) v(t1) : : : v(tn)].




DELIVERABLES: A copy of the M-FILE in your pdf.




Use Euler to solve the di erential equation using m = 70 kg, c = 12 kg/s and initial conditions v(0) = 0 on the time interval [0; 12] using 15 time steps and g = 9:81. DELIVERABLES: The function call to Euler and the resulting output.



Using the same parameters from Q1(b) solve the di erential equation analytically in MATLAB. That is, create a function for the formula,





gm
(1 e
ct


v(t) =


m
)
(1)
c



and run it for t = [t0 : h : tn].




DELIVERABLES: The function, the call and the results.




Plot the results from Q1(b) and Q1(c) together to compare. DELIVERABLES: The commands and resulting plot.



What is the terminal velocity of this free-falling body of mass 70 kg? (You may approximate this roughly with experimental results from your function or solve it analytically.)



DELIVERABLES: MATLAB output if using MATLAB or your analytic solution.



















3
sm se e1 e2 t1 t2 t3 t4










Question #2 - 5 Marks.




Consider a ternary, normalized oating-point number system that is base 3. Analogous to a bit, a ternary digit is a trit. Assume that a hypothetical ternary computer uses the following oating-point representation:




where sm is the sign of the mantissa and se is the sign of the exponent (0 for positive, 1 for negative), t1; t2; t3 and t4 are the trits of the mantissa, and e1; e2 are the trits of the exponent where each trit is 0,1 or 2. Write the following numbers (parts (a) to (d)) using this representation where X10 is used to indicate that the number provided is in decimal. Show all your work.

(a) 3 + 2

9 10




(b) 5510




(c) The largest number that can be represented in this system.




(d) The smallest positive non-zero number that can be represented in this system.




(e) What is the spacing for numbers between 310 and 910 in this ternary oating-point representation system? Your answer should be in decimal. Don't just provide the answer but also show your reasoning.







Question #3 - 5 Marks




The function e x can be approximated by its McLaurin series expansion as follows (note the alternating + and ):




e x








x2
x3




xn
1 x +


















+ : : :










2!
3!
n!
Alternatively, note that e x =


1
. Thus,


e x




can also be apporximated by 1 over the


x




e




























McLaurin series expansion of ex. That is,




























e x












1
































1 + x +
x2
+
x3


+ : : : +
xn






n!












2!


3!







Approximate e 2 using both approaches above for n = 1; 2; :::; 6 and compare each ap-proximation to the true value of e 2 = 0:135335:::, using the true relative error. What conclusions can you make about the two approaches?






















4

More products