Bayquin Bernadas Cuesta Gantes Segovia
Bayquin Bernadas Cuesta Gantes Segovia
Bayquin Bernadas Cuesta Gantes Segovia
Segovia
Course/Year/Section: BSECE 3A Date: January 16, 2023
Seatwork/Activity No. 1
1. Let the variable A be a row matrix (2, 4, 0, -1, 3), and B be a column matrix whose five elements are 2, 5, 8, 3, -
5, in that order. Calculate the quantity A * (B+1).
A = [2 4 0 -1 3]
B = [2 5 8 3 -5]’
A *(B+1)
Ans = 14
2. Set up the vector v = (0,1, 2,...,50) and calculate the length, | v1|, as given by the formula:
v = [0 1 2 : 50]'
v1= abs(sqrt(v.* v))
max(size(v1))
[31+1:2:75]'
4. Let x = [2 5 1 6].
x((1:1),(1:4))+16
x(1:2:end)+3
ans = [5 4]
Compute the square root of each element
sqrt(x(1:end))
(x(1:end)).^2
ans = [4 25 1 36]
72
y = sind(x);
x = -360:360;
plot(x,y,"color",'b',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
title("Graph");
hold on
grid on
y = 4 .* sind(5.*x);
x = -360:360;
plot(x,y,"color",'r',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
title("Graph");
hold on
grid on
y = cosd(x);
x = -360:360;
plot(x,y,"color",'b',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
title("Graph Cosine");
hold on
grid on
y = 7 .* cosd(3.*x);
x = -360:360;
plot(x,y,"color",'r',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
hold on
grid on
grid on
c) tan x 3 tan(3x) 5 tan(2x)
y = tand(x);
x = -360:360;
plot(x,y,"color",'b',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
title("Graph Tangent");
hold on
grid on
y = 3 .* tand(3.*x);
x = -360:360;
plot(x,y,"color",'r',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
hold on
grid on
y = cscd(x);
x = -360:360;
plot(x,y,"color",'b',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
title("Graph Cosecant");
hold on
grid on
y = 3 .* cscd(4.*x);
x = -360:360;
plot(x,y,"color",'r',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
hold on
grid on
end
y = secd(x);
x = -360:360;
plot(x,y,"color",'b',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
title("Graph Secant");
hold on
grid on
y = 2 .* secd(4.*x);
x = -360:360;
plot(x,y,"color",'r',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
hold on
grid on
y = cotd(x);
x = -360:360;
plot(x,y,"color",'b',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
title("Graph Cotangent");
hold on
grid on
y = 5 .* cotd(2.*x);
x = -360:360;
plot(x,y,"color",'r',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
hold on
grid on
t = 0:pi / 50:10*pi;
subplot (1,2,1); plot (sin(t), cos(t), "color", 'r', "LineStyle","-","LineWidth",1.5,"Marker","+")
axis square
title("TWO DIMENSIONAL CIRCLE");
display("Volume of a Sphere");
r = input("Enter Radius: ");
V = (4 * pi * r .^3) / 3;
format bank;
display("Volume: "+V);
b. Volume of a pyramid
display("Volume of a Pyramid");
b = input("Enter Base: ");
h = input("Enter Height: ");
V = 13 .* b .* h;
format bank;
display("Volume: "+V);
function quadroots(a, b, c)
a = 1
b = 1
c = 1
if a == 0
if b ~= 0
r1 = -c / b
else
d = b ^ 2 - 4 * a * c;
if d >= 0
r1 = (-b + sqrt(d)) / (2 * a)
r2 = (-b - sqrt(d)) / (2 * a)
else
r1 = -b / (2 * a)
i1 = sqrt(abs(d)) / (2 * a)
r2 = r1
i2 = -i1
end
end
Output:
a=
b=
c=
1
r1 =
-0.5000
i1 =
0.8660
r2 =
-0.5000
i2 =
-0.8660
function quadroots(a, b, c)
if b ~= 0
r1 = -c / b
else
d = b ^ 2 - 4 * a * c;
if d >= 0
r1 = (-b + sqrt(d)) / (2 * a)
r2 = (-b - sqrt(d)) / (2 * a)
else
r1 = -b / (2 * a)
i1 = sqrt(abs(d)) / (2 * a)
r2 = r1
i2 = -i1
end
end
10. Create a function that displays numbers counting up or counting down (in one function only)
a. Using while loops
Count Up:
x = 0
while x < 10
x = x + 1;
disp(x);
end
Count Down:
x = 10;
while x>1
x = x-1;
display(x);
end
Count Up:
for x = 1:10
disp(x);
end
Count Down:
for x = 10:-1:1
disp(x)
end