Question: MATLAB Develop a vectorized version of the following code: tst = 0; tnd = 20; ni=5; t(1)=tst; y(1)=15 + 5*cos(2*pi*t(1)/(tnd-tst)); for i=2:ni+1 t(i) = t(i-1)
MATLAB
Develop a vectorized version of the following code:
tst = 0; tnd = 20; ni=5;
t(1)=tst;
y(1)=15 + 5*cos(2*pi*t(1)/(tnd-tst));
for i=2:ni+1
t(i) = t(i-1) + (tnd - tst)/ni;
y(i) = 15 + 5*cos(2*pi*t(i)/(tnd - tst));
end
Write this as an M-file. Here, you are supposed to be slick and get rid of the for-loop. Hint:
x=2:4:10 is the vectorized version of the for-loop
for i = 1:3
x(i) = 2+4*(i-1);
end
Step by Step Solution
3.46 Rating (156 Votes )
There are 3 Steps involved in it
MATLAB CODE clearclc close all tst0t... View full answer
Get step-by-step solutions from verified subject matter experts
