Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Introduction to MATLAB Quiz

Total questions: 20

Worksheet time: 3600secs

Name
Class
Date
1.

Create two variables, X as a 5-by-5 identity matrix and Y as a 2-by-3 matrix of random values. Use the whos command to display information about the variables in the workspace.

4 lines
2.

Using the variables X and Y from Question 1, save them to a file named workspaceData.mat, then clear all variables from the workspace.

4 lines
3.

Reload the variables X and Y into the workspace from the workspaceData.mat file created in Question 2.

4 lines
4.

Define variables p = 10 and q = 4, then compute their product, product_pq, without displaying the result in the Command Window. Use the arrow key to recall the command for defining q, change its value to 6, and compute the new product.

4 lines
5.

Create a 3-by-3 matrix A with the following values: Then, add 5 to each element of A and display the result.

4 lines
6.

Transpose the matrix A from Question 1. Then, calculate the element-wise square of each element in the transposed matrix.

4 lines
7.

Concatenate the matrix A horizontally with itself to create a new matrix B that has double the columns of A. Then, concatenate A vertically with itself to create a matrix C that has double the rows of A.

4 lines
8.

Create a string variable greeting with the text "Hello, MATLAB". Then, add the phrase " - Welcome to text handling!" to the end of greeting using the + operator, and display the result.

4 lines
9.

Create a 2x2 string array B with the following values: Use the strlength function to determine the length of each string in B, and display the result.

4 lines
10.

Define a character array dna_seq1 with the value 'AGCTTAGC'. Concatenate dna_seq1 with another character sequence 'CGTACG' to create a new sequence dna_seq2, and display the combined sequence.

4 lines
11.

Create a structure named car with the following fields and data: • make: A string representing the car brand (e.g., "Toyota"). • model: A string representing the car model (e.g., "Corolla"). • year: A numeric value representing the year of manufacture (e.g., 2020). • mileage: A numeric value representing the mileage of the car in kilometers (e.g., 15000). Write a MATLAB script to: 1. Display all the details of the car. 2. Update the mileage to 20000 and display the updated structure.

4 lines
12.

You are provided with energy consumption data for three households. Each household has the following attributes: • household_id: A unique identifier for the household (e.g., 101, 102, 103). • location: A string representing the city where the household is located (e.g., "Kuala Lumpur", "Penang"). • monthly_usage: An array containing energy consumption (in kWh) for the last six months. Write a MATLAB script that: 1. Creates a structure array for the three households with the following data: o Household 1: household_id = 101, location = "Kuala Lumpur", monthly_usage = [320, 310, 330, 340, 325, 315] o Household 2: household_id = 102, location = "Penang", monthly_usage = [200, 210, 205, 220, 215, 210] o Household 3: household_id = 103, location = "Kuala Lumpur", monthly_usage = [400, 420, 410, 430, 415, 405] 2. Calculates and displays the average monthly energy consumption for each household. 3. Identifies and displays the household ID with the highest average energy consumption. 4. Calculates and displays the total energy consumption for households in "Kuala Lumpur".

4 lines
13.

Solve the system of equations: 2x+y=8 x+3y=18

4 lines
14.

Plot y=e^-0.1x for x values between 0 and 10

4 lines
15.

Plot the function y=cos(x) + sin(2x) for x values between 0 and 2π

4 lines
16.

Plot the function y=1/(1+x^2) for values x between -5 and 5.

4 lines
17.

Solve the second order differential equation d^2y/dt^2 + 2 dy/dt + 5y=0 for the initial conditions y(0)=1 and dy/dt(0)=0 and plot the solution y(t) for t between 0 and 10.

4 lines
18.

Calculate the area under the curve f(x)=x^2 from x=0 to x=2.

4 lines
19.

Find the area under f(x)=sin(x) from x=0 to x=π.

4 lines
20.

What is the total energy consumed over 1 second?

4 lines