Issues when stracting from an ODE 45 that depends on a derivative

조회 수: 2 (최근 30일)
Mikel
Mikel 2023년 4월 21일
편집: Torsten 2023년 4월 21일
Hello,
I'm using ode 45 for some operations but I have a small issue when It comes to extract intermediate variables, it gives me ereor when I try to extract them.
I went into the function and it seems that the variables (dyc,u and ,yc) are filling with empty values as one of the term needs to be derivated inside the function. How can I extract this values?
I'm new to ODEs and Im having some issues using them, sorry!
clear variables;
close all;
clc;
%% INIT
% load("trac.mat","qtraj","dqtraj","ddqtraj")
% solving the ode
t0=0;
tfinal=8;
tspan = linspace(t0, tfinal, 8e4);
x0 = [1 -2];
[t, x] = ode45(@(t,x) smc_obsv(t,x), tspan, x0);
s = zeros(numel(t),1);
u = s;
yc = s;
% THIS LINE GIVES ME error, I dont know how to solve it
for i = 1:numel(t)
[~, s(i),u(i),yc(i)] = smc_obsv(t(i), x(i,:));
end
%compute tracking error
y = x(:,1);
e = yc - y;
%% LOOP
% describing the ode
function [dot,s,u,yc] = smc_obsv(t, x)
% parameters
f = sin(2*t); % disturbance
c = 1.5; %
r = 2;
% yc, desired track
yc = 2*cos(t);
% compute desired velocity and acceleration
% THIS VALUE IS EMPTY!!
dyc = diff(yc)./diff(t);
%sliding variable
s= dyc+c*yc-x(1)*c-x(2);
%control law U
u = - r*tanh(s);
x1dot = x(2);
x2dot = f' + u;
x3dot = x(1);
dot = [x1dot x2dot x3dot]';
end

채택된 답변

Torsten
Torsten 2023년 4월 21일
편집: Torsten 2023년 4월 21일
yc and t are scalars, thus single values.
diff(yc)/diff(t) makes no sense in this case.
Simply use
dyc = -2*sin(t)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by