How to Simulate Nonlinear Model Discrete Time?

19 visualizaciones (últimos 30 días)
Ivan Dwi Putra
Ivan Dwi Putra el 19 de Nov. de 2020
Respondida: Jaynik el 30 de Jul. de 2024
This is My Nonlinear Model
function [PositionN, VelocityN, TorqueN] = traindiscretemodel(u,Tim_step,Position,Velocity,Torque,Mass,Ca_0,Ca_1,Ca_2,Tao,R,Eta)
% Train Model
PositionN = Position + Velocity*Tim_step;
VelocityN = Velocity + 1/Mass *(Eta*Torque/R - (Ca_0 + Ca_1*Velocity + Ca_2*Velocity^2))*Tim_step;
TorqueN = Torque - 1/Tao*Torque*Tim_step + 1/Tao*u*Tim_step;
end
This is parameters i used
clc;clear;close all;
Eta = 0.96;
% Parameter Massa
Mass = [8095;8500;8457;8500;8443;8396;8491];
Tim_step = 0.01;
R = [0.290736184319659;0.295289596853781;0.256349340814675;0.295668792806951;0.281617962311270;0.254877020249970;0.263924910943352];
Tao = [0.744417105917954;0.771737581122686;0.538096044888052;0.774012756841706;0.689707773867623;0.529262121499823;0.583549465660115];
Torquebound = [-3297.53650110286,3297.53650110286;-3517.25332991404,3517.25332991404;-1805.63954664794,1805.63954664794;-3535.78455981619,3535.78455981619;-2873.13552926226,2873.13552926226;-1748.36142518872,1748.36142518872;-2108.92205347325,2108.92205347325];
% Parameter Resistansi
Ca_0 = [5.2;5.2;5.2;5.2;5.2;5.2;5.2;];
Ca_1 = [0.038;0.038;0.038;0.038;0.038;0.038;0.038;];
Ca_2 = [0.00112;0.00112;0.00112;0.00112;0.00112;0.00112;0.00112;];
v0 = 20;
cd('G:\Ivan\Semester 10\Tugas Akhir II\matlab\Train Model Open Loop');
save parametersvalue.mat
with that discrete time model and parameters i used, I want simulated the model open loop. Can i used ode45?

Respuestas (1)

Jaynik
Jaynik el 30 de Jul. de 2024
Hi,
The ode45 function is used for solving ordinary differential equations (ODEs) and it is typically used for continuous-time models. However, the model given is a discrete-time model as it uses a time step (Tim_step) for updating the states.
For discrete-time models, you can use a simple loop to update the states at each time step. Here’s a basic example of how you can simulate your model in an open-loop fashion:
% Initial conditions
Position = 0;
Velocity = v0;
Torque = 0;
T_end = 10; % for example, simulate for 10 seconds
t = 0:Tim_step:T_end;
PositionN = zeros(size(t));
VelocityN = zeros(size(t));
TorqueN = zeros(size(t));
% Open-loop control input
u = 0; % for example, no control input
% Simulation loop
for i = 1:length(t)
[PositionN(i), VelocityN(i), TorqueN(i)] = traindiscretemodel(u,Tim_step,Position,Velocity,Torque,Mass(1),Ca_0(1),Ca_1(1),Ca_2(1),Tao(1),R(1),Eta);
Position = PositionN(i);
Velocity = VelocityN(i);
Torque = TorqueN(i);
end
plot(t, PositionN);
xlabel('Time (s)');
ylabel('Position');
This code will simulate the model for 10 seconds with no control input (u = 0). The simulation time and the control input can be adjusted as needed. Also, please make sure to use the correct parameters for your model. This is just a basic example and might need to be adjusted based on your specific needs.
Hope this helps!

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by