Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Cover Page

Mohammad Tasnimul Hasan


19121063
Sec-22
CSE-330 (Lab)
Assignment-01

EEE-330 (Assignment-01)
Sec-22

01.
X1 = -pi : 0.5 : pi;
Y1 = sin(X1);

X2 = -pi : 0.1 : pi;


Y2 = sin(X2);

X3 = -pi : 0.01 : pi;


Y3 = sin(X3);

plot(X1,Y1,'magenta', X2,Y2,'cyan', X3,Y3,'red', 'LineWidth',0.7)


axis([-pi pi -1 1])

xlabel('X')
ylabel('Y')

title('Problem 01: Graph of Sin(x)')


legend('sin(X) 1','sin(X) 2','sin(X) 3')

First, setting the range of values for X1 as -pi to pi with increments of 0.5 and then setting the
equation Y1 as the sine of X1. For the X2 setting range of values -pi to pi with increments of 0.1
and declare Y2 as the sine of X2. I did the same for X3 and Y3 as well. Then I use different
colors to plot the graph with a line width of 0.7 and then label them as X and Y in the graph plot
and also add title to the graph. Lastly, use the legend command to declare which color plot is for
which function.

02.
X1 = -2*pi : 0.1 : 2*pi;
Y1 = 5*cos(X1.^2+1);
Y2 = 8*sin(X1.^3-8);

plot(X1,Y1,'magenta', X1,Y2,'red','LineWidth',0.7)
axis([-2*pi 2*pi -8 8])

xlabel('X')
ylabel('Y')

title('Problem 02: Graph of 5cos(x^2+1) and 8sin(x^3-8)')


legend('5cos(X^2+1)','8sin(X^3-8)')

First declare the X1 as a range from -2pi to 2pi with an increment of 0.1 and then declare the Y1
as the function of cos and Y2 as the function of sin. Again use color command to color the plot
line and label the plot as X and Y. Lastly add title command to add a title to the plot and legend
to function as the specific colored line.

03.
ID = [1 9 1 2 1 0 6 3];
X = [1 2 3 4 5 6 7 8];

element_mult = ID.*X;
norm_mult = ID*(X');
final_value = element_mult.*norm_mult;
root_fv = sqrt(final_value);
sz = size(element_mult);
p = root_fv.^ID(end);
summation = 0;
for a = 1:1:length(p)
summation = summation + p(a);
end
summation = summation + sz(2);

disp('ID : ')
disp(ID)
disp('element_mult : ')
disp(element_mult)
disp('norm_mult : ')
disp(norm_mult)
disp('final_value : ')
disp(final_value)
disp('root_fv : ')
disp(root_fv)
disp('sz : ')
disp(sz)
disp('p : ')
disp(p)
disp('summation : ')
disp(summation)
Here first declare the ID number as a row vector and take numbers from 1 to 8 as another row
vector. We then multiply both vectors with each other as one value multiplied with the other
value of the other vector individually to get a new vector “element_multi”. Again we multiply
the second vector normally to get a single value. We multiply the individual elements in
“element_multi” with the value stored in “norm_multi” to get the “final_value” . 'root_fv' is after
we individually square root every element in the vector 'final_value'. We then find the
dimensions of 'element_multi' vector using 'size()' function and store it under the 'sz' variable.
We now raise all the values in 'root_fv' to the power of the last digit of our 'id' and store it under
'p'. We then initialize the 'summation' value to 0 and run a loop to add all the values in 'p' into
'summation' for the final output.

04.

T = 0 : 0.001 : 80;
X1 = 10*sin(T*(15*2*pi/80));
X2 = 2*sin(T*(30*2*pi/80));

figure(1)
plot(T,X1,'green', 'LineWidth',1.2)
axis([0 80 -10 10])
xlabel('X/ms')
ylabel('Y')

legend('10*sin(15*t)')
figure(2)
plot(T,X2,'red','LineWidth',1.2)
axis([0 80 -2 2])
xlabel('X/ms')
ylabel('Y')

legend('2*sin(30*t)')

figure(3)
plot(T,X1,'cyan',T,X2,'red','LineWidth',1.2)
axis([0 80 -10 10])
xlabel('X/ms')
ylabel('Y')

legend('10*sin(15*t)','2*sin(30*t)')

figure(4)
subplot(2,1,1)
plot(T,X1,'blue', 'LineWidth',1.2)
axis([0 80 -10 10])
xlabel('X/ms')
ylabel('Y')

legend('10*sin(15*t)')

subplot(2,1,2)
plot(T,X2,'magenta','LineWidth',1.2)
axis([0 80 -2 2])
xlabel('X/ms')
ylabel('Y')

legend('2*sin(30*t)')
grid

figure(5)
subplot(2,1,1)
stem(T,X1,'cyan', 'LineWidth',1.2)
axis([0 80 -10 10])
xlabel('X/ms')
ylabel('Y')
legend('10*sin(15*t)')

subplot(2,1,2)
stem(T,X2,'red','LineWidth',1.2)
axis([0 80 -2 2])
xlabel('X/ms')
ylabel('Y')

legend('2*sin(30*t)')

Figure-01
Figure-02

Figure-03
Figure-04

Figure-05

Here we declare the range of values for 'T'. Then set up the graphs of Y1 and Y2 by fitting 15
and 30 complete cycles inside the range of 80ms respectively.Then first we run Y1 plot on a
separate figure, Y2 plot on a separate figure, Y1 and Y2 on the same plot. On the fourth figure
we have Y1 and Y2 on separate graphs but on the same figure. On the fifth figure it is the same,
only with a stem option used to display all the points in the graphs using lines and a dot to give
a different picture.

05.
function geometric_series = geometric_series(r,n)
sum_of_series = 0;
for counter = 0:1:n
sum_of_series = sum_of_series + r^counter;
end
disp(sum_of_series)
end

r=5;
n=7;
geometric_series(r,n)

Here first we take 2 numbers as parameters value and then we run a loop through 0 to n, have r
to the power of a in every iteration operated and also add every number to the summation
variable. Thus we get to follow the mentioned formula.

06.
function temperature_converter = temperature_converter(ti,tf)
for counter = ti:1:tf
celcius(counter - ti + 1) = counter;
end
fahrenheit = celcius.* ( 9 / 5 ) + 32;
disp(celcius)
disp(fahrenheit)
celcius(2:2,1:tf-ti+1) = fahrenheit;
disp(' celcius, fahrenheit')
disp(celcius')
end

ti=10;
tf=20;
temperature_converter(ti,tf)
At first we take 2 numbers as parameters and print the headers and then we run loop through
'ti' to 'tf', to go through all the temperatures in celcius and then convert to Fahrenheit and then
we print each row in the table.

You might also like