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

Lab Activity 1.2 Matlab Fundamentals

Uploaded by

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

Lab Activity 1.2 Matlab Fundamentals

Uploaded by

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

De La Salle University- Manila

Gokongwei College of Engineering

Lab Activity Number : 1.2


Lab Activity Title : Matlab Fundamentals

Date Performed : September 13, 2024


Date Submitted : September 19, 2024

Instructor : Jay Robert B. del Rosario, PhD

Name of Student : Liandro Kent F. Villaganas


Student ID : 12021806
Subject / Section : LBYEC3C/ ER1
Part I. Calculating the Area and Circumference of a Circle Using Functions
Objective: Create MATLAB functions to calculate the area and circumference of a circle, given its radius,
using the following formulas:
• Area of a circle: A=πr2
• Circumference of a circle: C=2πr

• Create the Function for Area:


• Write a MATLAB function called calculateArea that takes the radius of a circle as input
and returns the area.

function area = calculateArea(r)


area = pi * r^2;
end

• Create the Function for Circumference:


• Write another MATLAB function called calculateCircumference that takes the radius as
input and returns the circumference.

function circumference = calculateCircumference(r)


circumference = 2 * pi * r;
end

• Write a Main Script:


• In the main script, prompt the user to input the radius of the circle. Then, call both
functions to calculate the area and circumference, and display the results.

radius = input('Enter the radius: ');

area = calculateArea(radius);

circumference = calculateCircumference(radius);

fprintf('The area is: %.2f\n', area);


fprintf('The circumference is: %.2f\n', circumference);

Part II. Working with Arrays and Plotting in MATLAB


Objective: Learn how to create, manipulate, and visualize arrays in MATLAB.
• Create a 1D Array:
• Create a 1D array x containing values from 0 to 10, with a step of 0.5:
x = 0:0.5:10;

• Array Operations:
• Compute the sine and cosine values for each element in x:

sine_values = sin(x);
cosine_values = cos(x);

• Plot the Results:


• Plot the sine and cosine functions on the same graph:

Part III. Basic Matrix Operations in MATLAB


Objective: Learn how to create matrices, perform basic operations, and visualize the results.
• Create a Matrix:
• In MATLAB, create a 3x3 matrix A with random integers between 1 and 10.

A = randi([1, 10], 3, 3);

• Matrix Operations:
• Compute the transpose of A:

A_transpose = A'

• Calculate the determinant of A:

A_determinant = det(A)

• Find the inverse of A (if the determinant is non-zero):

if A_determinant ~= 0
A_inverse = inv(A)
else
disp('No inverse, determinant is 0')
end

• Matrix Multiplication:
• Multiply matrix A by its transpose:

A_transpose = A';
result = A * A_transpose

• Plotting a 3D Matrix:
• Plot a 3D bar graph of the matrix A:

You might also like