# Plotting as intregral the acceleration of a thing

1 Ansicht (letzte 30 Tage)
pauli relanderi am 26 Jan. 2023
Kommentiert: pauli relanderi am 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
v = 0
s(1) = 0
s = 0
N=100
N = 100
dt=T/N
dt = 0.1100
t=0:dt:T;
a1=2*t;
a2=A
a2 = 2
a3=-2*t+8
a3 = 1×101
8.0000 7.7800 7.5600 7.3400 7.1200 6.9000 6.6800 6.4600 6.2400 6.0200 5.8000 5.5800 5.3600 5.1400 4.9200 4.7000 4.4800 4.2600 4.0400 3.8200 3.6000 3.3800 3.1600 2.9400 2.7200 2.5000 2.2800 2.0600 1.8400 1.6200
a4=0
a4 = 0
a5=-2*t+14
a5 = 1×101
14.0000 13.7800 13.5600 13.3400 13.1200 12.9000 12.6800 12.4600 12.2400 12.0200 11.8000 11.5800 11.3600 11.1400 10.9200 10.7000 10.4800 10.2600 10.0400 9.8200 9.6000 9.3800 9.1600 8.9400 8.7200 8.5000 8.2800 8.0600 7.8400 7.6200
a6=A
a6 = 2
a7=2*t-22
a7 = 1×101
-22.0000 -21.7800 -21.5600 -21.3400 -21.1200 -20.9000 -20.6800 -20.4600 -20.2400 -20.0200 -19.8000 -19.5800 -19.3600 -19.1400 -18.9200 -18.7000 -18.4800 -18.2600 -18.0400 -17.8200 -17.6000 -17.3800 -17.1600 -16.9400 -16.7200 -16.5000 -16.2800 -16.0600 -15.8400 -15.6200
% < 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
v = 0
s(1)=0
s = 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 KommentareKeine anzeigenKeine ausblenden
Les Beckham am 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.
pauli relanderi am 29 Jan. 2023
Okey. Its a object moving forward. Trying to and atleat i think ive calculated the accelerations righ. The lines goin up, down, down, up. and i need to make a plot by calculating it with the : a=a1.*(t<=t1) + a2.*((t>t2)&(t>=t1)) + a3.*(t>t1) + a4.*(t==t3) + a5.*(t>t1) + a6.*(t==t2) + a7.*(t>t1);
But i cant for the life of me figure out how to plot with that a line goint forward in x but not changing y

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Sulaymon Eshkabilov am 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 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by