@(T,X)SSMODEL must return a column vector ERROR
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
EREN ÖZGÜR
el 28 de Dic. de 2022
Respondida: Jan Studnicka
el 28 de Dic. de 2022
function dx = ssmodel(t,x)
syms alpha1 alpha2 alpha3 alpha4 x
A = [0 1 0 0; 0 0 1 0; 0 0 0 1; -alpha4 -alpha3 -alpha2 -alpha1];
B = [0; 0; 0; 1];
K = [16-alpha4 32-alpha3 24-alpha2 8-alpha1];
u = -K*x;
dx = A*x + B*u;
end
x0 = [-1; -1; -2; -2];
tspan = [0, 10, 100];
[t,x] = ode45(@(t,x) ssmodel,tspan,x0);
plot(t,x)
Error using odearguments (line 93)
@(T,X)SSMODEL must return a column vector.
Error in ode45 (line 106)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in multiodev (line 23)
[t,x] = ode45(@(t,x) ssmodel,tspan,x0);
How can i solve this error ? Please help me.
0 comentarios
Respuesta aceptada
Star Strider
el 28 de Dic. de 2022
I have no idea what ‘alpha’ is, however it must be numeric and not symbolic. It needs to be passed as an extra argument to ‘ssmodel’ in any event.
This works, however it will be necessary to understand what you want to do in order to provide a complete answer —
x0 = [-1; -1; -2; -2];
tspan = [0, 10, 100];
a = randn(1,4);
[t,x] = ode45(@(t,x)ssmodel(t,x,a),tspan,x0);
plot(t,x)
function dx = ssmodel(t,x,alpha)
A = [0 1 0 0; 0 0 1 0; 0 0 0 1; -alpha(4) -alpha(3) -alpha(2) -alpha(1)];
B = [0; 0; 0; 1];
K = [16-alpha(4) 32-alpha(3) 24-alpha(2) 8-alpha(1)];
u = -K*x;
dx = A*x + B*u;
end
.
0 comentarios
Más respuestas (1)
Jan Studnicka
el 28 de Dic. de 2022
The ssmodel function must be defined as described in the documentation:
You cannot use symbolic expressions with ode45:
and I believe that you want to create a model with parameters alpha1 alpha2 alpha3 alpha4. I suggest you do that this way:
x0 = [-1; -1; -2; -2];
tspan = [0, 10, 100];
alpha = [0 0 0 0]; % You need to set alpha before applying ode45
[t,x] = ode45(@(t,x) ssmodel(t,x,alpha),tspan,x0);
plot(t,x)
function dx = ssmodel(t,x, alpha)
% alpha is vector of length 4
A = [0 1 0 0; 0 0 1 0; 0 0 0 1; -alpha(4) -alpha(3) -alpha(2) -alpha(1)];
B = [0; 0; 0; 1];
K = [16-alpha(4) 32-alpha(3) 24-alpha(2) 8-alpha(1)];
u = -K*x;
dx = A*x + B*u;
end
0 comentarios
Ver también
Categorías
Más información sobre Ordinary Differential Equations 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!