Error using dde23 : Derivative and history vectors have different lengths.

6 visualizaciones (últimos 30 días)
Atharva Modi
Atharva Modi el 29 de Nov. de 2020
Editada: Stephan el 30 de Nov. de 2020
I am trying to solve a second order DE and I am not able to resolve this error. Please help and thanks in advance
sol = dde23(@ddex1de,[0.04],@ddex1hist,[0, 0.7]);
t = linspace(0.04,0.7,1000);
y = deval(sol,t);
ylag = deval(sol,t - 0.04);
F = ((K_f*a)/m)*(h - ylag + y)
plot(t,F);
xlabel('t');
ylabel('F');
% --------------------------------------------------------------------------
function s = ddex1hist(t)
% Constant history function for DDEX1.
s = zeros(2,1);
end
% --------------------------------------------------------------------------
function dydt = ddex1de(t,y,Z)
global m c n k K_f T h a
% Differential equations function for DDEX1.
ylag1 = Z(:,1);
dydt = [ y(2) ; (((K_f)*(a))/(m))*((h)-ylag1(1)+y(1))-(c/m)*y(2)-((k)/m)*y(1) ];
end

Respuestas (1)

Stephan
Stephan el 30 de Nov. de 2020
Editada: Stephan el 30 de Nov. de 2020
You did not define your constants - i took some fake values for them. n and T are unused. Also for good reasons, try to avoid global variables:
%% constants
m = 1;
c = 1;
n = 1;
k = 1;
K_f = 1;
T = 1;
h = 1;
a = 1;
%% code
sol = dde23(@(t,y,Z)ddex1de(t,y,Z,m,c,n,k,K_f,T,h,a),[0.04],@ddex1hist,[0, 0.7]);
t = linspace(0.04,0.7,1000);
y = deval(sol,t);
ylag = deval(sol,t - 0.04);
F = ((K_f*a)/m)*(h - ylag + y);
plot(t,F);
xlabel('t');
ylabel('F');
%% --------------------------------------------------------------------------
function s = ddex1hist(~)
% Constant history function for DDEX1.
s = zeros(2,1);
end
%% --------------------------------------------------------------------------
function dydt = ddex1de(~,y,Z,m,c,~,k,K_f,~,h,a)
% Differential equations function for DDEX1.
ylag1 = Z(:,1);
dydt = [ y(2) ; (((K_f)*(a))/(m))*((h)-ylag1(1)+y(1))-(c/m)*y(2)-((k)/m)*y(1) ];
end

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by