Error in using ode45 for solution of nonlinear system of three equations which are interlinked to each other
조회 수: 2 (최근 30일)
이전 댓글 표시
% Define the ODE system
f = @(t,x) [-(p1 + x(2)) * x(1) + p1 * Gb + D; -p2 * x(2) + p3 .* x(3) + p3.* Ib; -n * (x(3) - Ib) + u];
% Solve the ODE system
[t,x] = ode45(f, tspan, [x1; x2; x3]);
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in UpdatedTrialsmc>@(t,x)[-(p1+x(2))*x(1)+p1*Gb+D;-p2*x(2)+p3.*x(3)+p3.*Ib;-n*(x(3)-Ib)+u] (line 51)
f = @(t,x) [-(p1 + x(2)) * x(1) + p1 * Gb + D; -p2 * x(2) + p3 .* x(3) + p3.* Ib; -n * (x(3) - Ib) + u];
Error in UpdatedTrialsmc (line 54)
[t,x] = ode45(f, tspan, [x1; x2; x3]);
댓글 수: 0
답변 (3개)
Torsten
2023년 4월 12일
이동: Torsten
2023년 4월 12일
Check
size(p1)
size(Gb)
size(D)
size(p2)
size(p3)
size(Ib)
size(n)
size(u)
If one of the sizes is not 1x1 (a scalar), your code won't work.
댓글 수: 2
Torsten
2023년 4월 12일
All are scalar, have single constant value which is defined earlier in the code.
If you get the error message as stated, this can't be true.
Bjorn Gustavsson
2023년 4월 12일
Perhaps you need to check the size of each component in your ode-function:
f = @(t,x) [-(p1 + x(2)) * x(1) + p1 * Gb + D; -p2 * x(2) + p3 .* x(3) + p3.* Ib; -n * (x(3) - Ib) + u];
What are the sizes of p1, Gb, D, p2, p3, Ib, n, Ib and u? The error-message you get is what I typically get when I try to concatenate arrays of incompatible sizes.
HTH
Sam Chak
2023년 4월 12일
편집: Sam Chak
2023년 4월 12일
Try this:
% Define the time-varying Disturbance
D = @(t) sin(pi/10*t);
% Define the scalar parameters
Gb = 1;
n = 1;
p1 = 1;
p2 = 1;
p3 = 1;
Ib = 1;
% Define the feedback input u
u = @(x) - x(1) - 2*x(2);
% Define the system dynamics
f = @(t, x) [-(p1 + x(2))*x(1) + p1*Gb + D(t);
- p2*x(2) + p3*x(3) + p3*Ib;
- n*(x(3) - Ib) + u(x)];
% Define the initial conditions
x0 = [1; 0; 0];
% Define the time interval
tspan = [0 20];
% Solve the system using the ode45 solver
[t, x] = ode45(f, tspan, x0);
% Plot the result
plot(t, x); grid on
xlabel('t')
댓글 수: 4
Sam Chak
2023년 4월 12일
편집: Sam Chak
2023년 4월 12일
Thanks @FAIZ UL HASSAN. It looks a little complicated to read the equation this way without breaking up the terms. But some parameters are unavailable. Try simplifying u by making up u1, u2, u3, ... This helps troubleshooting later. I guess that the error "Dimensions of arrays being concatenated are not consistent" is caused by u.
Edit: On a second look, I'm just guessing...💡 that u is some kind of a sliding mode forcing input structure and e, ed, edd refers to , respectively. S must be the sliding surface then.
Besides, check if sign(S) is a discontinuous function or just a scalar like this
sign(3.14159)
The ode45() solver does not work well with discontinuous function when .
참고 항목
카테고리
Help Center 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!