Matlab
Matlab
plot(y)
plot(x,y)
x = 0:2*pi
x=0:0.1:2*pi
y=sin(2*x)
plot(y)
plot(x,y)
xlabel('THE X VALUES')
y2=2*cos(3*x)
y3=3*sin(cos(x))
plot(x,y,x,y2,x,y3)
legend('Funct One', 'Funct Two', 'Funct Three')
help plot
plot(x,y,'ro:')
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,
'MarkerEdgeColor','k',
'MarkerFaceColor','g',
'MarkerSize',10)
x = -pi:pi/10:pi; y = tan(sin(x)) - sin(tan(x)); plot(x,y,'--rs','LineWidth',
2,'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10)
%-- 9/22/2023 8:11 AM --%
pi
% NUMERICAL ANALYSIS LAB TWO
x = [4 5 7 9]; y = [5 8 13 15];
plot(x,y)
help plot
xlabel("Values of x")
ylabel("Values of y")
title('Plotting x against y")
title("Plotting x against y")
legend('show')
x= -1*pi : pi
y1 = sin(x)
y2 = 2*cos(x)
y3 = 3 * sin(2*x)
plot(x,y1,x,y2,x,y3)
xlabel("Pi values")
ylabel("Y Axis")
legend("y1","y2","y3")
plot(x,y1,'b.-', 'LineWidth',2,x,y2,'g+:','LineWidth',3,x,y3, 'rp--', 'LineWidth',4)
plot(x,y1,'b.-',x,y2,'g+:',x,y3, 'rp--')
p = plot(x,y1,'b.-',x,y2,'g+:',x,y3, 'rp--')
p(1).LineWidth = 2;
legend("y1","y2","y3")
p(2).LineWidth = 2.5
p(3).LineWidth = 3
%vectors and Matrices operations in matlab
%arrays of numbers
%-one col/row -- vector
% Matrix A(mxn)
% Row Vector 1xn
MATLAB Command History Page 3
Oct 6, 2023 8:43:19 AM
b
rand(3)
magic(3)
help magic
help elmat
C = [1 2; 3 4]
D = [C zeros(2); ones(2) eye(2)]
A = rand(3)
B = rand(3)
C = a*b
C = A * B
D = A.*B
% .* -- element by element multiplication
% * -- normal multiplication
E = A ^ 2
F = A .^ 2
G = A + B
H = A .+B
2*A
inv(A), %inverse of a
b = rand(3,1)
b = b'
X = inv(A) * b
b = rand(3,1)
X = inv(A) * b
x = A\b
x = b/A
det(A)
rank(A)
help rank
norm(A)
help norm
%norm tells whether the system has a solution or not
%-- 10/6/2023 8:33 AM --%
%LAB THREE
A = [1 3 5; 2 8 6; 1 2 4]
A(2,2)=9
A(3,:) = []
% above command deleted row 3
size(A)
%find order of A ^
[m,n] = size(A)
u = [1;3;5]
length(u)
%^^return no of rows
length(A)
help length
%^^length returns max row/column
eye(3)
zeros(3)
ones(3)