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

조회 수: 2(최근 30일)
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 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 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

댓글을 달려면 로그인하십시오.

### 범주

Find more on Programming in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by