HOw to find displacement integrating velocity?

45 次查看(过去 30 天)
Hi, i need to find the displacement of a moving object x(t) knowing its velocity as a function of the displacement itself v(x). The function i have used is the following
I imposed that dx / dt = v(x) and then I tryed to use ODE 45 to find x(t) but I always get a vector full of zeros but i can't understand where the mistake is. This is the code that I wrote:
%% data
Po=1.5; % [bar] absolute feeding pressure
P1=1.01315; % [bar] absolute atmosferic pressure
rho=2700; %[kg/m^3] projectile density
D=0.048; % [m] projectile diameter
Length=0.10; % [m] projectile length
A=(pi/4)*D.^2; % [m^2] projectile face area
m=rho*A*Length; % [kg] projectile mass
L=0.90; %[m] useful barrell length
L_d=0.4; %[m] decelleration barrel length
Vol=0.0095; %[m^3] chamber volume
gamma=1.4; % air constant
% friction forces with 0.47 friction coefficient between aluminium and% steel
f=0.47*m*9.81;
%% model
x_dot=@(t,x) sqrt((2./m).*((Po.*1e5.*Vol)./(gamma-1).*(1-(Vol./(A.*x+Vol)).^(gamma-1))-A.*x.*P1.*1e5-x.*f));
x0=0;
tspan=0:0.1:1;
[t,x]=ode45(x_dot,tspan,x0);
plot(t,x)
  3 个评论
Shivam Gothi
Shivam Gothi 2024-11-8,10:15
hello @Riccardo,
can you please explain in brief what does this equation do? which system dynamics does it represents ?
I am getting some non-zero imaginery solution for velocity if I put "x0=1".
This is because, I found that the value of expression inside the sqrt() function is coming out to be negative (for positive "x", take x=1 as an example).
So sqrt() applied on negative number gives imaginary value. What does the imaginery "x_dot" represent here ?
Riccardo
Riccardo 2024-11-10,18:12
This equation should reperesent the velocity of a projectile being accelerated by an adiabatic expansion of gas.
Vol represent the volume of the chamber containing the gas, L the length of the barrel, m the mass of the projectiel and A the cross section of the barrel

请先登录,再进行评论。

采纳的回答

Torsten
Torsten 2024-11-10,19:09
编辑:Torsten 2024-11-10,19:36
The equation from above describes the stationary velocity profile over the length L. Thus replacing v by dx/dt does not make sense in this case because there is no movement of x: x is the static position over the length L.
Or do you try to compute the position of a massless particle moving in x-direction over time ? Then use
%% data
Po=1.5; % [bar] absolute feeding pressure
P1=1.01315; % [bar] absolute atmosferic pressure
rho=2700; %[kg/m^3] projectile density
D=0.048; % [m] projectile diameter
Length=0.10; % [m] projectile length
A=(pi/4)*D.^2; % [m^2] projectile face area
m=rho*A*Length; % [kg] projectile mass
L=0.90; %[m] useful barrell length
L_d=0.4; %[m] decelleration barrel length
Vol=0.0095; %[m^3] chamber volume
gamma=1.4; % air constant
% friction forces with 0.47 friction coefficient between aluminium and% steel
f=0.47*m*9.81;
%% model
x_dot=@(t,x) sqrt((2./m).*((Po.*1e5.*Vol)./(gamma-1).*(1-(Vol./(A.*x+Vol)).^(gamma-1))-A.*x.*P1.*1e5-x.*f));
x0=1e-8;
tspan=0:0.01:1;
options = odeset('Events',@(t,x)event(t,x,L));
[t,x]=ode45(x_dot,tspan,x0,options);
plot(x,t)
xlabel('Length')
ylabel('Time')
grid on
function [position,isterminal,direction] = event(t,x,L)
position = x(1)-L; % The value that we want to be zero
isterminal = 1; % Halt integration
direction = 0; % The zero can be approached from either direction
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by