0% found this document useful (0 votes)
36 views

Computer Lab #1 - Introduction To MATLAB Due: Friday, September 24 at 11:30pm

This document provides instructions for a MATLAB assignment with 3 questions. Students are asked to: 1) Create a function to calculate rocket velocity as a piecewise function and plot the results. 2) Create a script using nested for loops to fill a 6x5 matrix with numbers 1 to 30. 3) Create a script to plot an anonymous function modeling given data points against the data on the same graph.

Uploaded by

nathan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Computer Lab #1 - Introduction To MATLAB Due: Friday, September 24 at 11:30pm

This document provides instructions for a MATLAB assignment with 3 questions. Students are asked to: 1) Create a function to calculate rocket velocity as a piecewise function and plot the results. 2) Create a script using nested for loops to fill a 6x5 matrix with numbers 1 to 30. 3) Create a script to plot an anonymous function modeling given data points against the data on the same graph.

Uploaded by

nathan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

MECH 2150 Mechanical Engineering Modelling and Numerical Methods Fall 2021

Computer Lab #1 – Introduction to MATLAB


Due: Friday, September 24th at 11:30pm

1. Problem 3.14 in Chapra [1]

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

Follow the steps below when creating your code:

Page 1 of 2
MECH 2150 Mechanical Engineering Modelling and Numerical Methods Fall 2021

 Create a variable for the number of rows and set it equal to 6


 Create a variable for the number of columns and set it equal to 5
 Create a zeros matrix (using the zeros function) with the number of rows and columns
defined above
 Create a nesting for loop that fills the matrix with numbers 1 to 30 as shown above.
Try using breakpoints within the loop to ensure the code is working correctly.

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

𝑦 10.4 5.8 3.3 2.4 2

Develop a MATLAB script file called Lab1Q3.m that does the following:

 Creates two vectors for the data provided in the table.


 Creates an anonymous function for the equation provided above. Use different variable
names for the 𝑥 and 𝑦 in the anonymous function compared to those used for the data.
 Plots the anonymous function (using the fplot command) as a solid black line on a 𝑦 vs. 𝑥
graph from 𝑥 =0.5 to 𝑥 =4.
 Plots the data points from the table on the same 𝑦 vs. 𝑥 plot using blue squares (with no
line connecting the points) for the symbols.
 Include axis labels and a title for the graph.

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

You might also like