Im super new to Matlab so im confused on how to do this assignment. I know it is
ID: 2081432 • Letter: I
Question
Im super new to Matlab so im confused on how to do this assignment. I know it is supposed to be realy easy i am just confused. Thank you and ill rate the response!
i. Create a row matrix that is going to be a time axis from -2 to 6 seconds. The step size must be 1ms. ii. Create a function x (t) sin(2nt) iii. The following function v2 (t is shown in problem 5.5b in Luaby. Create this function in Matlab using IF statements. Be sure to use the same time vector so that x(t) and v2 (t) have the same number of points. Otherwise the following steps will result in errors. iv. Create a new function yt) x(t).* v2(t) This is a point by point multiplication of these two functions. v. Create a subplot showing all three plots separately in one single figure. Place x(t) on top v2(t) second and y(t)on the bottom. Properly label each plot. vi. Repeat this project but find a better (smaller step size. The best step size is the smallest one that doesn't noticeably degrade the plots. You can use linspace0 or the colon operator to set the independent variable (in this case, time). What is the best step size Compare the number of points with this best step size to the one I made you use in part i)Explanation / Answer
Copy the following code to a new script in MATLAB.
close all; clear all; clc;
t = -2:0.001:6; % time interval
x = sin(2*pi*t); % x(t)
N = length(t); % number of points in time interval
v2 = zeros(1,N); % initializing v2(t) to zero
% v2(t) function
for i=1:N
if (t(i)>=-2 && t(i)<0)
v2(i) = 0;
else if (t(i)>=0 && t(i)<2)
v2(i)=2*t(i);
else if (t(i)>=2 && t(i)<4)
v2(i)=4;
else if (t(i)>=4 && t(i)<=6)
v2(i)=4-2*(t(i)-4);
end
end
end
end
end
y = x.*v2; % y(t)
% plotting x(t),v2(t) and y(t)
figure; subplot(3,1,1);
plot(t,x); title('x(t)');
xlabel('t(s)');
subplot(3,1,2);
plot(t,v2); title('v_2(t)');
xlabel('t(s)');
subplot(3,1,3);
plot(t,y); title('y(t)');
xlabel('t(s)');
The smallet step size that does not cause degradation is 0.000001 second or 1 microsecond. Number of points = 8000001
The largest step size that does not cause degradation is 0.05 second or 50 millisecond. Number of points = 161