- #1
- 23,073
- 7,447
I'm trying to plot 5 periodic functions on the same graph in MATLAB and I can't seem to figure out how to do it correctly. The following code will work, except that I still need to change the line style for each line so that they are easy to tell apart.
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:
But this just gives me an error, saying that the inner matrices must match or something.
Any ideas?
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?