In: Electrical Engineering
Use for statements to find the values of x(t) = 3 cos (2?ft + 0.1) for t = 0,
01, 0.2, 0.3, 0.4 s when f =10, 15, and 20 Hz. Use one set ofstatements to compute the values for all three frequencies and store the results in a two-dimensional array. Use two nested for loops and double indexing.
Type the following code in MATLAB
clc
clear all
t= 0:0.1:0.4;
f = 10:5:20;
for f = 10:5:20
for t= 0:0.1:0.4
xt=3.*cos((2*pi.*f.*t)+0.1);
xtt=[xt;f]
%making two d array of frequency and xt function output
end
end
REsult
xtt = 2.9850 %this is out put 10.0000 %at 10hzfrequency xtt = 2.9850 10.0000 xtt = 2.9850 10.0000 xtt = 2.9850 10.0000 xtt = 2.9850 10.0000 xtt = 2.9850 15.0000 xtt = -2.9850 15.0000 xtt = 2.9850 15.0000 xtt = -2.9850 15.0000 xtt = 2.9850 15.0000 xtt = 2.9850 20.0000 xtt = 2.9850 20.0000 xtt = 2.9850 20.0000 xtt = 2.9850 20.0000 xtt = 2.9850 20.0000
Type the following code in MATLAB
%here we will also include time to see at what time at what frequency what is value ofx(t)
clc
clear all
t= 0:0.1:0.4;
f = 10:5:20;
for f = 10:5:20
for t= 0:0.1:0.4
xt=3.*cos((2*pi.*f.*t)+0.1);
xtt=[xt;f;t]
%time parameter is included
end
end
Result
xtt = 2.98501 %output value of x(t) 10.00000 %at 10 hz frequency 0.00000 %at time t=0 seconds xtt = 2.98501 10.00000 0.10000 xtt = 2.98501 10.00000 0.20000 xtt = 2.98501 10.00000 0.30000 xtt = 2.98501 10.00000 0.40000 xtt = 2.98501 15.00000 0.00000 xtt = -2.98501 15.00000 0.10000 xtt = 2.98501 15.00000 0.20000 xtt = -2.98501 15.00000 0.30000 xtt = 2.98501 15.00000 0.40000 xtt = 2.98501 20.00000 0.00000 xtt = 2.98501 20.00000 0.10000 xtt = 2.98501 20.00000 0.20000 xtt = 2.98501 20.00000 0.30000 xtt = 2.98501 20.00000 0.40000