Hi all,
I'm trying to plot the position and velocity from a created function in twos different plots using subplot, the function solves a second order differential equation and I am getting the result in one plot, as I try to create two different graphics I got different errors or unexpected results, what could I do?
Here is part of my code:
yu = [x0 y0 z0 Vx0 Vy0 Vz0];
opts1 = odeset('InitialStep',5,'MaxStep',5);
[t,y] = ode23(@yprime, t, yu, opts1);
subplot(2,1,1);
plot(t,y,'-');
subplot(2,1,2);
plot(t,y,'-');
function [yp] = yprime(t,y)
GM = (6.67408e-11)*(5.9722e24);
yp = zeros(6,1);
yp(1) = y(4);
yp(2) = y(5);
yp(3) = y(6);
r = sqrt((y(1))^2+(y(2))^2+(y(3))^2);
yp(4) = (-GM/(r)^3)*y(1);
yp(5) = (-GM/(r)^3)*y(2);
yp(6) = (-GM/(r)^3)*y(3);
end
2 Comments
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/721364-plotting-elements-from-a-function#comment_1278018
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/721364-plotting-elements-from-a-function#comment_1278018
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/721364-plotting-elements-from-a-function#comment_1279108
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/721364-plotting-elements-from-a-function#comment_1279108
Sign in to comment.