Bayquin Bernadas Cuesta Gantes Segovia

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Names: Tom Ashley Bayquin, Sean Duke Bernadas, Ashley Mervin Cuesta, Edric Kristian Gantes, Nelson Miguel

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))

3. Create a vector of the even whole numbers between 31 and 75.

[31+1:2:75]'

4. Let x = [2 5 1 6].

a) Add 16 to each element

x((1:1),(1:4))+16

ans = [18 21 17 22]

b) Add 3 to just the odd-index elements

x(1:2:end)+3
ans = [5 4]
Compute the square root of each element

sqrt(x(1:end))

ans = [1.4142 2.2361 1.0000 2.4495]

c) Compute the square of each element

(x(1:end)).^2
ans = [4 25 1 36]

5. Let x = [3 2 6 8]' and y = [4 1 3 5]' (x and y should be column vectors).

a) Add the sum of the elements in x to y


x + y
ans =
7
3
9
13
b) Raise each element of x to the power specified by the corresponding element in y.
x .^ y
ans =
81
2
216
32768
c) Divide each element of y by the corresponding element in x
y ./ x
ans =
1.3333
0.5000
0.5000
0.6250
d) Multiply each element in x by the corresponding element in y, calling the result "z".
z = (x .* y)
z =
12
2
18
40
e) Add up the elements in z and assign the result to a variable called "w".
w = sum(z)
w =

72

f) Compute x'*y - w and interpret the result


Ans = 0
Vector in variable x is converted into row,
x = {3 , 2 , 6 , 8] and y = [4 1 3 5]’
Then, the two matrices are multiplied such that:
3(4)+2(1)+6(3)+8(5) = 72
With w = 72, the difference of 72 – w is 0.
6. Using MATLAB, plot the graphs of the following trigonometric functions given -360<x<360.
a) sin x 4 sin(5x) 2 sin(3x)

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 = 2.* sind(3 .* x);


x = -360:360;
plot(x,y,"color",'g',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
title("Graph");
grid on
b) cos x 7 cos(3x) 4 cos(4x)

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

y = 4.* cosd(4 .* x);


x = -360:360;
plot(x,y,"color",'g',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');

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 = 5.* tand(2 .* x);


x = -360:360;
plot(x,y,"color",'g',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
grid on
d) csc x 3 csc(4x) 3 csc(5x)

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 = 3.* cscd(5 .* x);


x = -360:360;
plot(x,y,"color",'g',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
grid on
e) sec x 2 sec(4x) 7 sec(2x)

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 = 7.* secd(2 .* x);


x = -360:360;
plot(x,y,"color",'g',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
grid on
f) cot x 5 cot(2x) 2 cot(4x)

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

y = 2.* cotd(4 .* x);


x = -360:360;
plot(x,y,"color",'g',"LineStyle","-","LineWidth",1.5,"Marker","+")
xlabel('x');
ylabel('y');
grid on
7. Recreate FIGURE 2.1 (page 35) of our reference: plot of two-dimensional circle and three-dimensional helix.

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");

subplot (1,2,2); plot3 (sin(t), cos(t), t,"color", 'b', "LineStyle","-


","LineWidth",1.5,"Marker","+")
title("3D HELIX");
8. Create and run a script file of the following
a. Volume of a sphere

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);

9. Recreate the function “roots of a quadratic equation” (page 63):


a. Using output and input parameters (arguments)

function quadroots(a, b, c)

a = 1
b = 1
c = 1
if a == 0

if b ~= 0

r1 = -c / b
else

disp('Trivial solution. Try again')


end
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

b. Using input() and display()

function quadroots(a, b, c)

a = input("Enter the second-order coefficient (a): ");


b = input("Enter the first-order coefficient (b): ");
c = input("Enter the zero-order coefficient (c): ");
if a == 0

if b ~= 0

r1 = -c / b
else

disp('Trivial solution. Try again')


end
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

b. Using for loops

Count Up:

for x = 1:10
disp(x);
end

Count Down:

for x = 10:-1:1
disp(x)
end

You might also like