Trouble plotting Second Order Equation
Show older comments
I'm trying to plot the numerical solution of the second order equation: y'' + sin(y) =0, with the intital values of y(0) being 0.1, 0.7, 1.5, and 3.0, and y'(0) =0. However, the following code is giving me an incorrect graph, and I'm not sure how to resolve this.
rhs = @(t, y) [y(2); -sin(y(1))];
[xa, ya] = ode45(rhs, [0 10], [0.1 0]);
figure, hold on
for y0 = 0:0
for yp0 = 0.1:0.7:1.5:3.0
[tfor, yfor] = ode45(rhs, [0 6.28], [y0 yp0]);
[tbak, ybak] = ode45(rhs, [0 6.28], [y0 yp0]);
plot(tfor, yfor(:,1))
plot(tbak, ybak(:,1))
end
end
Accepted Answer
More Answers (0)
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
