Sin and Cosine curves are coming out like zigzags

6 views (last 30 days)
I am working on a project in which a 2 mass, 2 spring system was given. From there, i found an equation for y1(t) and y2(t) using eigenvalues and eigenvectors.
I solved for 6 sets of equations for y2 and y1 using these six sets of initial conditions. I am now attempting to use matlab to complete the requirements pictured below. My current code is copied below. When I run these graphs, they come out very 'zig-zagged' instead of smooth sin and cosine curves. Some graphs even come up as just straight lines.
What am I doing incorrect?
This is my first time using matlab so it may be something silly that i am missing.
t=0:0.001:10;
period1 = 2 * pi / 3.39;
period2 = 2 * pi / 1.59;
shortestPeriod = min([period1, period2]);
finalTime = 3 * shortestPeriod;
numSamples = 12;
t = linspace(0, finalTime, numSamples);
y11=0.2763*cos(1.59*t) + 0.7237*cos(3.39*t);
y12=0.4469*cos(1.59*t)-0.4469*cos(3.39*t);
y21=0.4474*cos(1.59*t)-0.4474*cos(3.39*t);
y22=0.7237*cos(1.59*t)+0.2763*cos(3.39*t);
y31=0.7237*cos(1.59*t)+0.2763*cos(3.39*t);
y32=1.1706*cos(1.59*t)-0.1706*cos(3.39*t);
y41=1.2763*cos(1.59*t)-0.2763*cos(3.39*t);
y42=2.064*cos(1.59*t)+0.1706*cos(3.39*t);
y51=cos(1.59*t);
y52=1.6175*cos(1.59*t);
y61=cos(3.39*t);
y62=-0.6175*cos(3.39*t);
figure
plot(t, y11,'k-',t,y12,'k-.');
legend('y11','y12')
title('Initial Condition 1')
figure
plot(t,y21,'k-',t,y22,'k-.');
legend('y21','y22')
title('Initial Condition 2')
figure
plot(t,y31,'k-',t,y32,'k-.');
legend('y31','y32')
title('Initial Condition 3')
figure
plot(t,y41,'k-',t,y42,'k-.');
legend('y41','y42')
title('Initial Condition 4')
figure
plot(t,y51,'k-',t,y52,'k-.');
legend('y51','y52')
title('Initial Condition 5')
figure
plot(t,y61,'k-',t,y62,'k-.');
legend('y61','y62')
title('Initial Condition 6')
figure
plot(t, y12./y11);
title('y12/y11')
figure
plot(t, y22./y21);
title('y22/y21')
figure
plot(t, y32./y31);
title('y32/y31')
figure
plot(t, y42./y41);
title('y42/y41')
figure
plot(t, y52./y51);
title('y52/y51')
figure
plot(t, y62./y61);
title('y62/y61')

Accepted Answer

Star Strider
Star Strider on 2 Jun 2020
Increase ‘numSamples’.
Try this:
numSamples = 120;
It can be anything you want (within limits). A higher number creates better resolution.

More Answers (1)

Steven Lord
Steven Lord on 2 Jun 2020
Let's draw sine curves with varying numbers of points.
for pts = 1:9
subplot(3, 3, pts)
x = linspace(0, 2*pi, 2^pts);
y = sin(x);
plot(x, y)
axis([0 2*pi -1 1])
title("sine curve with " + 2^pts + " points")
end
Your 12 sample points curve probably looks something between the subplot with 8 points and the one with 16. Not terrible, but you can still tell MATLAB played "connect the dots". If you have more dots spaced more closely together, the curve looks smoother.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!