- #1

- 23,073

- 7,447

Matlab:

```
k = 1; %spring constant
w0 = sqrt(k);
z = 0; %Used to count the elements of y, which is used in the for loops below.
%loop to plot a periodic function for 5 different values of r, the damping coefficient.
for r = 0:0.5:2
w1 = sqrt(w0^2-(r^2/4));
for t = 0:0.1:10
z=z+1;
%Performs the calculation for each data point.
y(z) = exp(-r*t/2)*sin(w1*t);
end
%Performs the plot of each function for each iteration of the outer loop.
plot(y);
z=0;
end
```

According to my book, the command used to plot with a different line style is: plot(x, y, '--')

However, any time I try to plot the above function using a command similar to plot(x, y), I just get a blank plot.

I've also tried using:

Matlab:

```
t = 0:0.1:10;
plot(t, exp(-r*t/2)*sin(w1*t));
```

Any ideas?