solving a dynamic equation
21 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I want to solve the following equationinMATLAB, namely obtain u and u'.
m*u''(t)=sign(u'(t))*c*m*g-m*u''g(t)
u''g=[0;0.002,0.003,0.004,0.001,-0.01,-0.02,0]
m=2kg,c=0.1,g=9.81
I would be really grateful if someone could help me to solve this eqution with ODE45.
Thak you very much
1 个评论
Sam Chak
2022-11-26
If g is gravitational acceleration, then what is g(t) in this product term m·u"·g(t)?
Mass m times Acceleration u" times a function g(t)?
回答(1 个)
Davide Masiello
2022-11-27
Hi @sam - you did not provide enough info for us to try and give a complete answer, but I did some guessing and came up with a solution nonetheless.
I am assuming that the term u''g(t) appearing in the equation and the array u''g are the same thing. That is to say that the term u''g(t) is given as a discrete time function.
You did not specify initial conditions and time span, so I made them up.
I am assuming that the body starts at a height of 50 and velocity 0, and that it falls for 10 s.
The problem can be solved in the following way.
m = 2;
c = 0.1;
g = 9.81;
tspan = [0,10];
u2g = [0,0.002,0.003,0.004,0.001,-0.01,-0.02,0];
f_u2g = @(x) interp1(linspace(tspan(1),tspan(end),length(u2g)),u2g,x); % interpolation to get continuous function from discrete data
[t,u] = ode45(@(t,u)model(t,u,m,c,g,f_u2g),tspan,[50,0]);
plot(t,u(:,1),t,u(:,2))
legend('u','u''')
function dudt = model(t,u,m,c,g,f_u2g)
dudt(1,1) = u(2);
dudt(2,1) = sign(u(2))*c*g-f_u2g(t);
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!