How to create a Matlab object that simulates a spring-mass system without Simulink

2 次查看(过去 30 天)
I am trying to model a dynamic system (e.g., a spring-mass system) withing a big project, that may be deployed on a machine that doesn't have Simulink.
I would like to create a spring-mass system object, which has a method that takes time as input and return the position, and that stores all the history of states, to be used for the numerical integration.
How can I do it, without SImulink?
Note: I am aware of ODE solvers (e.g., ode45), but my problem with these solvers is that they solve for the all time steps at once, which contrary to what I need. I need to solve for only one time step, as needed.
Thanks :)

采纳的回答

Sam Chak
Sam Chak 2022-4-11
If the spring-mass system is non-stiff, and you want to solve for only one step time, then the conventional Runge–Kutta 4th-order formula should be good enough for the job.
For example, given the dynamical system:
and the initial value ,
select a sufficiently small step size h, and compute the following
to obtain 1-step propagated solution:
  1 个评论
Mahmoud Elzouka
Mahmoud Elzouka 2022-4-11
Thanks @Sam Chak for the solution. It is similar to what I am currently doing.
I was hoping Matlab can give us access to the Simulink-like classes, rather than implement the numerical technique of handling the DE.

请先登录,再进行评论。

更多回答(0 个)

类别

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

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by