@(T,X)SSMODEL must return a column vector ERROR

2 ビュー (過去 30 日間)
EREN ÖZGÜR
EREN ÖZGÜR 2022 年 12 月 28 日
回答済み: Jan Studnicka 2022 年 12 月 28 日
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.

採用された回答

Star Strider
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
.

その他の回答 (1 件)

Jan Studnicka
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

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by