Please help solve a system of differential equation
Mostra commenti meno recenti
I have a system of differential equation in x,y with boundary conditions. I want to solve it analytically and numerically. The analytical solutions coming in the form of error functions. Can someone please help me find analytical and numerical solution for this, I have been trying for weeks now, really need to solve this for my thesis. Please help.

Risposte (1)
Here's a numerical approach:
First manipulate the equations

tspan = [0, 120];
ic = [80000, 0.001];
[t, xy] = ode45(@rate, tspan, ic);
x = xy(:,1); y = xy(:,2);
subplot(2,1,1)
plot(t,x),grid
xlabel('t'), ylabel('x')
subplot(2,1,2)
plot(t,y),grid
xlabel('t'), ylabel('y')
function dxydt = rate(~,xy)
a = 0.1; b = 0.2; c = -0.1; % Replace with desired values
x = xy(1); y = xy(2);
dxydt = [a-b+c*x*y; % eqn (3)
c*y*(1-y) - a*y/x]; % eqn (5)
end
19 Commenti
Jayesh Jawandhia
il 15 Mar 2023
Modificato: Jayesh Jawandhia
il 15 Mar 2023
Alan Stevens
il 15 Mar 2023
Do you know the values of a, b and c, or do you need to fit them using the experimental data? If the latter you will need to upload the data if you want any help.
Jayesh Jawandhia
il 15 Mar 2023
Alan Stevens
il 16 Mar 2023
I'm puzzled! Looking at your data I see the initial value of x is likely to be around 10 to 15, not 80000. Where does the latter come from? The data file also lists different values of a and b for every data point. Are these just for guidance to typical values?
This data looks more like it's related to the logistic function than the error function. The following shows a purely empirical fit:
t = 5:5:120;
x = [15.6700 18.0000 19.0000 19.3300 19.5000 19.6700 19.3300 ...
18.7700 18.6000 18.2000 17.9300 17.9300 17.6700 17.3300 ...
17.1700 16.8300 16.8300 16.1700 15.5000 15.5000 15.8300 ...
15.6700 15.6700 15.6700];
y = [53.4467 61.4233 63.9467 64.6933 65.6633 65.7567 65.6100 ...
65.3000 65.6133 65.9367 66.2833 66.0300 67.0500 65.9600 ...
66.3733 66.7867 66.5233 66.3533 66.6567 66.6400 66.4267 ...
67.3067 67.0300 67.3133];
a = 67; b = 0.2; c = 0.01; abc = [a, b, c];
abc = fminsearch(@(abc) fny(abc, t, y), abc);
a = abc(1); b = abc(2); c = abc(3);
Y = a.*exp(-c*t)./(1+exp(-b*t));
A = 20; B = 0.2; C = 0.01; ABC = [A, B, C];
ABC = fminsearch(@(ABC) fnx(ABC, t, x), ABC);
A = ABC(1);B = ABC(2); C = ABC(3);
X = A.*exp(C*t)./(1+exp(-B*t));
plot(t,x,'ko',t,y,'rs',t,Y,'k',t,X), grid
xlabel('t'),ylabel('x and y')
legend('x','y','yfit','xfit')
axis([0 120 0 90])
hold on
function Fy = fny(abc, t, y)
a = abc(1); b = abc(2); c = abc(3);
Y = a.*exp(-c*t)./(1+exp(-b*t));
d = Y-y;
Fy = sum(norm(d));
end
function Fx = fnx(ABC, t, x)
A = ABC(1); B = ABC(2); C = ABC(3);
X = A.*exp(C*t)./(1+exp(-B*t));
d = X - x;
Fx = sum(norm(d));
end
Jayesh Jawandhia
il 16 Mar 2023
Alan Stevens
il 17 Mar 2023
- What is the system you are trying to calculate? i.e. What do x and y physically represent?
- How did you derive the equations, and why does your data set contain estimates for a and b, but not c?
- How did you derive the point estimates for a and b in the data set?
I ask because your equations look strange and don't seem to represent the data, whereas your x and y data just look something close to logistic equations.
Jayesh Jawandhia
il 17 Mar 2023
Alan Stevens
il 18 Mar 2023
Hmm. Well, the approach I'd take is as follows:
- Estimate initial values for a, b and c.
- Numerically solve the equations to get predicted values at the experimental timesteps.
- Form residuals at those timesteps: Experimental - predicted.
- Calculate the sum of squared residuals.
- Use fminsearch to try to find values of a, b and c that minimises the sum of squared residuals.
Jayesh Jawandhia
il 18 Mar 2023
Alan Stevens
il 18 Mar 2023
I did have a quick go at this. Unfortunately, I wasn't able to make a sufficiently good estimate of intial values to get converged results!
Jayesh Jawandhia
il 19 Mar 2023
@Jayesh Jawandhia, If the process system is controllable, can you inject a Manipulated Variable u so that you can freely change to see how the State Variables
respond?
It will be way more flexible and practical to design
(that drives the system to behave as desired) than to repeatedly guess a unique set of initial values to arrive at the desired converged result.
A Continuous Stirred Tank Reactor (CSTR) is a controllable process system.
Jayesh Jawandhia
il 19 Mar 2023
Modificato: Jayesh Jawandhia
il 19 Mar 2023
I'm no expert in CSTR. I read your comments and Google the keywords. Since CSTR is a vessel in the industrial process, it is definitely controllable. Compare the equations in the journal papers and identify the manipulated variables, which can be more than 1. The math can come later.
More importantly, get familiar with the CSTR differential equations with the manipulated variables.
Alan Stevens
il 19 Mar 2023
@Jayesh Jawandhia Ok. Here is the code I put together to have a quick look. Change the values of a, b and c to your heart's content! I'm not convinced that your odes describe your data, but more than happy to be proved wrong. If you are successful, post your results here. Good luck..
t = 0:300:7200;
x = [15.0000 17.2300 18.1900 18.5000 18.6600 18.8200 18.5000 ...
17.9600 17.8000 17.4200 17.1600 17.1600 16.9100 16.5900 ...
16.4300 16.1100 16.1100 15.4700 14.8400 14.8400 15.1500 ...
15.0000 15.0000 15.0000];
y = [0.5345 0.6142 0.6395 0.6469 0.6566 0.6576 0.6561 ...
0.6530 0.6561 0.6594 0.6628 0.6603 0.6705 0.6596 ...
0.6637 0.6679 0.6652 0.6635 0.6666 0.6664 0.6643 ...
0.6731 0.6703 0.6731];
% Add initial values to data
x = [12.5 x];
y = [0.001 y];
% Initial guesses for a, b and c
% [a, b, c]
abc = [1, 1, 1];
% Try fminsearch to estimate better values of a, b and c
ABC = fminsearch(@(abc) compare(abc, t, x, y), abc);
disp(ABC) % Display resulting values
% Numerically integrate the odes with resulting values
[t, XY] = runode(ABC,t);
% Extract fitted values and plot fits vs data
X = XY(:,1); Y = XY(:,2);
subplot(2,1,1)
plot(t, X, 'r', t, x, 'ro'),grid
ylabel('x')
axis([0 7200 0 20])
subplot(2,1,2)
plot(t, Y, 'r', t, y, 'ro'),grid
ylabel('y')
axis([0 7200 0 1])
% Calculate sum of squared residuals
function F = compare(abc, t, x, y)
[~, XY] = runode(abc, t);
X = XY(:,1); Y = XY(:,2);
dx = x - X;
dy = y - Y;
F = norm(dx)+norm(dy);
end
% Call the odes with current values of a, b and c
function [t, XY] = runode(abc, t)
ic = [12.5, 0.001];
[t, XY] = ode45(@(t,xy) odefn(t, xy, abc), t, ic);
end
% ODE equations
function dxydt = odefn(~,xy, abc)
a = abc(1); b = abc(2); c = abc(3);
x = xy(1); y = xy(2);
dxydt = [a-b+c*x*y;
c*y*(1-y)-a*y/x];
end
Jayesh Jawandhia
il 19 Mar 2023
Jayesh Jawandhia
il 4 Apr 2023
Torsten
il 4 Apr 2023
What's the problem ?
function dxydt = rate(t,xy);
m = ...;
n = ...;
r = ...;
p = ...;
q = ...;
s = ...;
a = m*t^2+n*t+r;
b = p*t^2+q*t+s;
x = xy(1);
y = xy(2);
dxydt = [a-b+c*x*y;c*y*(1-y)-a*y/x];
end
Categorie
Scopri di più su Linear Algebra in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


