Poc Lab 1
Poc Lab 1
Submitted by-
Group Number: 03
Group Members-
SL NAME ID
13 AKTER,AIRIN 22-46334-1
Submission Date:28/10/2024
Explanation: This line of code creates a 3×3 matrix named A.The numbers within the brackets
represent the elements of the matrix.The semicolon ; separates the rows of the matrix &
space(<>) separates the columns of the matrix.
Command: >> A(1,3)+A(2,1)+A(3,2).
OUTPUT
Explanation: This line of code performs an operation on the elements of the matrix A that
was defined in the previous script.A(1,3) refers to the element in the first row and third
column of the matrix.A(2,1) refers to the element in the second row and first column of the
matrix.A(3,2) refers to the element in the third row and second column of the matrix.The
+ operator is used to add these elements together.
Command: >> A(2:3.1:2)
OUTPUT
Explanation: A(2:3, 1:2): This command extracts a submatrix from matrix A.2:3 specifies
that rows 2 to 3 of matrix A are selected.1:2 specifies that columns 1 to 2 of matrix A are
selected.
Command: >> A(1,1:2)
OUTPUT
Explanation: A(1, 1:2): This command extracts elements from the 1st row of matrix A.1
specifies that the 1st row of matrix A is selected.1:2 specifies that columns 1 to 2 of matrix
A are selected.
Command:>> A(:,2)
OUTPUT
Explanation: This line of code extracts the second column of the matrix A.The A(:,2)
syntax means "all rows of A, and the second column.". The output shows the contents of
the second column of the matrix A.
Command:>> linspace (0,pi,101)
OUTPUT
Explanation: This line of code creates a vector named x.The linspace function generates
evenly spaced numbers over a specified interval.In this case, it generates 101 numbers
between 0 and pi (approximately 3.14159).
Command:>> v= (10:-2:0)
OUTPUT
Explanation: This line of code creates a vector named v.The expression (10:-2:0)
generates a sequence of numbers starting from 10,decreasing by 2 in each step, and ending
at 0.
Command:>> B= zeros(3,4)
OUTPUT
Explanation: This line of code creates a 3×4 matrix named B.The zeros function creates
a matrix filled with zeros.The arguments (3,4) specify the dimensions of the matrix,3 rows
and 4 columns.
Command:>> C=ones(2,5)*6
OUTPUT
Explanation: This line of code creates a 2x5 matrix named C.The ones(2,5) function
creates a 2×5 matrix filled with ones.The *6 multiplies each element of the matrix by 6.
Command:>> D= rand(1,5)
OUTPUT
Explanation: This line of code creates a 3x3 matrix named E.The randn function generates
random numbers from a standard normal distribution (mean = 0, standard deviation =
1).The arguments (3,3) specify the dimensions of the matrix,3 rows and 3 columns.
Command:>> A(2,:)=[]
OUTPUT
Explanation: This line of code deletes the second row of the matrix A.The A(2,:) part
specifies the second row of the matrix.Assigning an empty array [] to this row effectively
removes it.
Command:>> x=0:pi/100:2*pi;
>> y=sin(x);
>> plot(x,y)
OUTPUT
Explanation: x = 0:pi/100:2*pi;: This line creates a vector x containing 101 evenly spaced
values between 0 and 2π.y = sin(x);: This line calculates the sine of each value in the x
vector and stores the results in the y vector.plot(x,y): This line plots the values in y against
the corresponding values in x, creating a sine wave graph.xlabel('x'): This line labels the x-
axis of the plot as "x".ylabel('y'): This line labels the y-axis of the plot as
"y".title('y=sin(x)'): This line adds a title to the plot, indicating that it represents the
function y = sin(x).
Command: >> x1 = 0:pi/100:2*pi;
y1 = sin(x1);
y2 = sin(x1 - 0.30);
y3 = sin(x1 - 0.60);
plot(x1,y1,’g:*’)
hold on
plot(x1,y2,’r:+’)
hold on
plot (x1,y3,’b:o’)
OUTPUT
Explanation: t = -pi:pi/100:pi;: This line creates a vector t containing 201 evenly spaced
values between -π and π.s = cos(t);: This line calculates the cosine of each value in the t
vector and stores the results in the s vector.plot(t,s): This line plots the values in s against
the corresponding values in t, creating a cosine wave graph.axis([-pi pi -1 1]): This line
sets the x-axis limits to -π and π, and the y-axis limits to -1 and 1.xlabel('\pi \leq t \leq \pi'):
This line labels the x-axis of the plot with the expression "π ≤ t ≤ π".ylabel('cos(t)'): This
line labels the y-axis of the plot as "cos(t)".title('the cosine function'): This line adds a title
to the plot, indicating that it represents the cosine function.text(-2,-0.5,'This is a note at
position (-2,-0.5)'): This line adds a text annotation to the plot at the specified coordinates,
displaying the text "This is a note at position (-2,-0.5)".
Discussion & Conclusion:
The objectives of the lab experiment were met, and all of the tasks were finished.
Although MATLAB has several advantages over other programs, its efficacy is up for debate. This
creates opportunities for more investigation into possibly useful research.To sum up, this lab
experiment gave a useful overview of the fundamental MATLAB's features and applications. We
obtained real-world experience through experiential learning. Our results show that MATLAB
may be used for this course in an efficient manner. But it's crucial to recognise our limitations .
All things considered, this experience provided a strong basis for further research into MATLAB's
capabilities.