filmov
tv
How to use matlabFunction and Lagrangian to simulate a model

Показать описание
The code is available on my GitHub:
And the correct equation at 02:24 is:
euler_lagrangian_eqn = [q_dot; jacobian(L, q)' - jacobian(jacobian(L, q_dot), q) *q_dot];
Please, contact me if needed:
00:00 - 00:52 Introduction
00:52 - 03:45 Programing "gen_model"
03:45 - 05:05 Programing "main"
--
Hi, I'm Eita. Today I'd like to share with you how to construct a dynamic model in MATLAB.
Although the topic demonstrated today is relatively simple, I will be using some more complex features or commands in order to complete the model as some models may be more complex. These features or commands will help during constructing more complex systems in the future.
Let's analyze the model of free-falling ball first. There is a ball with a mass m kilograms which starts from a static initial state and falls freely from a height h. It will be affected only by gravity, undergoing a vertical downward motion until it reaches the ground.
Next, we set up the coordinate for the system. Since it is a free-falling ball, we only need the velocity and acceleration in one direction. Then, we write the Lagrangian of the system, describing the kinetic energy T and potential energy V of the free-falling ball, subtracting T from V, forming the Lagrangian.
After writing down the Lagrangian, we can plug it into the Euler-Lagrangian equation. This equation describes the q double dot in state space form, which is a function of q and q dot. It is also applicable to different generalized coordinates. To further describe the trajectory of motion of the model, we can use MATLAB’s command ode45 to solve the numerical solution of the equation via Runge-Kutta method.
After writing out the Euler-Lagrangian equation, we can use MATLAB's computation to generate and simplify the equations. We need two equations: the first one is the main equation which describes the model's motion, which I have named "free_falling_ball_function"; and the second one is the event function for numerical computation, which is named "Event_touch_down" and is set to terminate the solving of the main equation when the position is equal to zero.
We've already finished the generate model program, then we just have to run it to obtain all the required .m and .mat files. Afterwards, with just reading these files, we can easily solve the motion of the model.
And the correct equation at 02:24 is:
euler_lagrangian_eqn = [q_dot; jacobian(L, q)' - jacobian(jacobian(L, q_dot), q) *q_dot];
Please, contact me if needed:
00:00 - 00:52 Introduction
00:52 - 03:45 Programing "gen_model"
03:45 - 05:05 Programing "main"
--
Hi, I'm Eita. Today I'd like to share with you how to construct a dynamic model in MATLAB.
Although the topic demonstrated today is relatively simple, I will be using some more complex features or commands in order to complete the model as some models may be more complex. These features or commands will help during constructing more complex systems in the future.
Let's analyze the model of free-falling ball first. There is a ball with a mass m kilograms which starts from a static initial state and falls freely from a height h. It will be affected only by gravity, undergoing a vertical downward motion until it reaches the ground.
Next, we set up the coordinate for the system. Since it is a free-falling ball, we only need the velocity and acceleration in one direction. Then, we write the Lagrangian of the system, describing the kinetic energy T and potential energy V of the free-falling ball, subtracting T from V, forming the Lagrangian.
After writing down the Lagrangian, we can plug it into the Euler-Lagrangian equation. This equation describes the q double dot in state space form, which is a function of q and q dot. It is also applicable to different generalized coordinates. To further describe the trajectory of motion of the model, we can use MATLAB’s command ode45 to solve the numerical solution of the equation via Runge-Kutta method.
After writing out the Euler-Lagrangian equation, we can use MATLAB's computation to generate and simplify the equations. We need two equations: the first one is the main equation which describes the model's motion, which I have named "free_falling_ball_function"; and the second one is the event function for numerical computation, which is named "Event_touch_down" and is set to terminate the solving of the main equation when the position is equal to zero.
We've already finished the generate model program, then we just have to run it to obtain all the required .m and .mat files. Afterwards, with just reading these files, we can easily solve the motion of the model.