Issues when stracting from an ODE 45 that depends on a derivative
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!