Computer Lab #1 - Introduction To MATLAB Due: Friday, September 24 at 11:30pm
Computer Lab #1 - Introduction To MATLAB Due: Friday, September 24 at 11:30pm
Piecewise functions are sometimes useful when the relationship between a dependent and
independent variable cannot be adequately represented by a single equation. For example, the
velocity of a rocket might be described by:
10𝑡 − 5𝑡 0≤𝑡<8
624 − 3𝑡 8 ≤ 𝑡 < 16
𝑣(𝑡) = 36𝑡 + 12(𝑡 − 16) 16 ≤ 𝑡 < 26
2136𝑒 . ( )
𝑡 > 26
0 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Develop a function m-file called Rocketv.m that computes 𝑣 as a function of 𝑡 using the above
equations and conditions. The function should accept 𝑡 as an input variable and return 𝑣 as an
output variable. Then develop a script file called Lab1Q1.m that calls this function to compute 𝑣
for a range of 𝑡 values from 𝑡 = -5 to 50 and plots the results on a 𝑣 vs. 𝑡 graph as a solid red line.
Include a title and axes labels on your plot.
Note: Please include the clear and clc commands as the first two lines of all your script files in
this course. This will ensure all old variables are cleared and the command window is cleared
before running your code. Do not include these commands in function files since this will cause
errors when running your code.
2.
Create a script m-file called Lab1Q2.m that uses nesting for loops (a for loop inside another for
loop) to fill a 6 x 5 coefficient matrix as follows:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
26 27 28 29 30
Page 1 of 2
MECH 2150 Mechanical Engineering Modelling and Numerical Methods Fall 2021
3.
The data shown in the table below can be modeled using the following equation:
4.8375 + √𝑥
𝑦=
2.4303√𝑥
𝑥 0.5 1 2 3 4
Develop a MATLAB script file called Lab1Q3.m that does the following:
Submission Requirements: Submit your four m-files (Rocketv.m, Lab1Q1.m, Lab1Q2.m and
Lab1Q3.m) electronically into the correct Assignment folder. Please combine all the files
mentioned above into a folder and compress the folder into a zip file. Then upload the zip file to
the Assignment folder. Each student will then only have one zip file they are submitting. Please
name the zip file as Lab1_LastName_StudentNumber (ex. Lab1_Guyot_1234567).
Page 2 of 2