My figures are not plotting any data, I tried changing the number of points and step size multiple times but it didn't change
조회 수: 2 (최근 30일)
이전 댓글 표시
% THE PROJECT
%
clear
%
N=100 %number of points
h=0.1 % step size
ts=20 %starting time
%^
for i=1:N
t1(i)=exp(-2*ts)*sin(pi*ts);
F(i)=-exp(-2*t1(i))*(2*sin(pi*t1(i))-pi*cos(pi*t1(i))); %position
Fv(i)=-exp(-2*t1(i))*((pi^(2)-4)*sin(pi*t1(i))+4*pi*cos(pi*t1(i))); %velocity
Fa(i)=-exp(-2*t1(i))*((6*pi^(2)-8)*sin(pi*t1(i))+(12*pi-pi^(3)*cos(pi*t1(i)))); %acceleration
end
%
for i=1:N
if(i<=2) %forward
Fd(i)=(-F(i+2)+4*F(i+1)-3*F(i))/(2*h);
Fdd(i)=(-F(i+3)+4*F(i+2)-5*F(i+1)+2*F(i))/(h^2);
elseif ((i==N) | (i==N-1)) %backwards
Fd(i)=(3*F(i)-4*F(i-1)+F(i-2))/(2*h);
Fdd(i)=(2*F(i)-5*F(i-1)+4*F(i-2)-F(i-3))/(h^2);
else %center
Fd(i)=(-F(i+2)+8*F(i+1)-8*F(i-1)+F(i-2))/(12*h);
Fdd(i)=(-F(i+2)+16*F(i+1)-30*F(i)+16*F(i-1)-F(i-2))/(12*h^2)
end
end
%
%
figure (1)
plot(t1,F)
title('Rocket position')
xlabel('time(s)')
ylabel('position(m)')
%
figure(2)
plot(t1,Fv,t1,Fd)
title('Rocket velocity')
xlabel('time(s)')
ylabel('velocity(m/2)')
%
figure(3)
plot(t1,Fa,t1,Fdd)
title('Rocket acceleration')
xlabel('time(s)')
ylabel('acceleration(m/s^2)')
%
figure(4)
plot(t1,(Fv-Fd),t1,(Fa-Fdd))
legend('Vel error','Acc Err')
%
figure(5)
subplot(2,2,1),plot(t1,F)
title('Rocket position')
xlabel('time(s)')
ylabel('position(m)')
%
subplot(2,2,2),plot(t1,Fv,t1,Fd)
title('Rocket velocity')
xlabel('time(s)')
ylabel('velocity(m/2)')
%
subplot(2,2,3),plot(t1,Fa,t1,Fdd)
title('Rocket acceleration')
xlabel('time(s)')
ylabel('acceleration(m/s^2)')
%
subplot(2,2,4),
plot(t1,(Fv-Fd),t1,(Fa-Fdd))
legend('Vel error','Acc Err')
댓글 수: 0
답변 (1개)
Jason Shrand
2022년 4월 26일
They actually are being plotted, but you aren't seeing anything because every point in your data set is the same constant value.
For example, in the for loop at the top of the script, you have:
t1(i)=exp(-2*ts)*sin(pi*ts);
This value is always constant. I think what you need is something like
t1(i)=exp(-2*ts)*sin(pi*ts)*i;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!