@(T,X)SSMODEL must return a column vector ERROR
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2022-12-28
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 个评论
更多回答(1 个)
Jan Studnicka
2022-12-28
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!