Plotting as intregral the acceleration of a thing
1 view (last 30 days)
Show older comments
pauli relanderi
on 26 Jan 2023
Commented: pauli relanderi
on 29 Jan 2023
Hello.
Im stuck at a problem. Cant figure out how to plot my ploblem and if its my plot at fault or the math. Any help would be great !
I've tried to plot it and get right equtions for the acceleratons lines.
This is the plot im trying to get from the math/plot
Let me know if this doesnt belong here.
This is my code :
clear all
t1=1;
t2=2;
t3=3;
T=11;
A =2;
v(1) = 0
s(1) = 0
N=100
dt=T/N
t=0:dt:T;
a1=2*t;
a2=A
a3=-2*t+8
a4=0
a5=-2*t+14
a6=A
a7=2*t-22
% < less than
% > greater than
a=a1.*(t<=t1) + a2.*((t>t2)&(t>=t1)) + a3.*(t>t1) + a4.*(t==t3) + a5.*(t>t1) + a6.*(t==t2) + a7.*(t>t1);
v(1)=0
s(1)=0
for k=1:N
v(k+1)=v(k)+a(k)*dt;
s(k+1)=s(k)+v(k)*dt+1/2*a(k)*dt^2;
end
figure(4)
subplot(3,1,1)
plot(t,a,'linewidth',2)
grid
subplot(3,1,2)
plot(t,v,'linewidth',2)
grid
subplot(3,1,3)
plot(t,s,'linewidth',2)
grid
2 Comments
Les Beckham
on 26 Jan 2023
You haven't explained what the problem is. What are you seeing vs. what you expect?
I don't think your calculation of a is doing what your sketch shows.
Accepted Answer
Sulaymon Eshkabilov
on 27 Jan 2023
This is how you can solve this exercise:
N=100;
T=11;
dt=T/N;
t=0:dt:T;
F = [0 2 2 0 0 -2 -2 0]; % Acceleration pattern
Time = [0 1 3 4 7 8 10 11]; % Time intervals corresponding the Acceleration pattern
FF = griddedInterpolant(Time, F); % Grid interpolation w.r.t time intervals
a = FF(t); % Compute the gridded acceleration values according to time signal values of t
v(1)=0;
s(1)=0;
for k=1:N
v(k+1)=v(k)+a(k)*dt;
s(k+1)=s(k)+v(k)*dt+1/2*a(k)*dt^2;
end
figure
subplot(3,1,1)
plot(t,a,'linewidth',2, 'DisplayName','Acceleration: a(t)', 'Color','r')
grid on; legend show
ylabel('$a(t)$', 'Interpreter','latex')
subplot(3,1,2)
plot(t,v,'linewidth',2, 'DisplayName', 'Velocity: v(t)', 'Color',[0 .75 .5])
grid on; legend show
ylabel('$v(t)$', 'Interpreter','latex')
subplot(3,1,3)
plot(t,s,'linewidth',2, 'DisplayName','s(t)', 'Color',[0 0.25 0.85])
legend show; grid on
ylabel('$s(t)$', 'Interpreter','latex')
xlabel('Time, [s]')
0 Comments
More Answers (0)
See Also
Categories
Find more on Subplots 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!