0% found this document useful (0 votes)
8 views1 page

CE122 Lab2

The document outlines a MATLAB lab exercise focusing on arrays, matrix operations, plotting, input/output formatting, functions, and solving systems of linear equations. It includes tasks such as creating matrices, performing mathematical operations, plotting functions, formatting user input, and implementing functions for calculations. The lab aims to enhance programming skills relevant to engineering applications.

Uploaded by

mosesdayes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

CE122 Lab2

The document outlines a MATLAB lab exercise focusing on arrays, matrix operations, plotting, input/output formatting, functions, and solving systems of linear equations. It includes tasks such as creating matrices, performing mathematical operations, plotting functions, formatting user input, and implementing functions for calculations. The lab aims to enhance programming skills relevant to engineering applications.

Uploaded by

mosesdayes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

CE122: Applied Programming for Engineers

Lab 2: Basics in MATLAB

1) Arrays and Matrix Operations

• Create a 3x3 matrix A with random integers from 1 to 5.


• Calculate the determinant, rank, and inverse of A.
• Perform element-wise addition, multiplication and division for A and AT and store in
variables B, C, and D respectively.
• Create a 3x3 matrix F whose rows are from B, C, D.
o Row 1 in F is row 1 of B,
o Row 2 in F is column 1 of C, and
o Row 3 in F is 3 times row 2 of D,

2) Plotting and Visualization

• Write a MATLAB script to plot the function y = x2, {x: -10 ≤ x ≤ 10}.
• Add labels and a title to the plot.
• Create a new figure
• Use the hold on keyword to create a 2 on 1 plot of 2graphs: one for y = sin(x) and
another for y = cos(x).
• Add labels, title, and a legend to the plot
• Use the subplot function to create a 2x1 grid of plots: one for y = sin(x) and another for
y = cos(x) on another figure.
• Add labels and titles to the plot.

3) Formatting output and Input

• Write a script to prompt the user separately for a character and a number.
• Print the character in a field width of 3 and the number left justified in a field width of 8
with 3 decimal places.
• What is the disp?

4) Functions

• Write an anonymous function in MATLAB that takes a number as input and returns its
square.
• Create a function file to calculate the area of a circle given the radius.

5) Systems of linear equation

• Using linsolve or the “\”,


• Solve these systems of linear equation using Cramer’s rule.
2x + 3y = 7, and
x – 3y = 2

You might also like