# Error in using ode45 for solution of nonlinear system of three equations which are interlinked to each other

2 visualizzazioni (ultimi 30 giorni)
FAIZ UL HASSAN il 12 Apr 2023
Commentato: FAIZ UL HASSAN il 12 Apr 2023
% 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 CommentiMostra -1 commenti meno recentiNascondi -1 commenti meno recenti

Accedi per commentare.

### Risposte (3)

Torsten il 12 Apr 2023
Spostato: Torsten il 12 Apr 2023
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 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
Torsten il 12 Apr 2023
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.

Accedi per commentare.

Bjorn Gustavsson il 12 Apr 2023
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
##### 1 CommentoMostra NessunoNascondi Nessuno
FAIZ UL HASSAN il 12 Apr 2023
D and u have same size and others are single value constant parameters.

Accedi per commentare.

Sam Chak il 12 Apr 2023
Modificato: Sam Chak il 12 Apr 2023
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 CommentiMostra 3 commenti meno recentiNascondi 3 commenti meno recenti
FAIZ UL HASSAN il 12 Apr 2023
Thanks @Sam Chak will try this way.

Accedi per commentare.

### Categorie

Scopri di più su Ordinary Differential Equations in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!