Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Torsten
Torsten il 21 Apr 2023
Modificato: Torsten il 21 Apr 2023
yc and t are scalars, thus single values.
diff(yc)/diff(t) makes no sense in this case.
Simply use
dyc = -2*sin(t)

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by