Hi, I want to solve these coupled set of odes. dy/dt =f1(y)+c1*x; dx/dt =f2(x)+c2*y; Where both x and y are vectors of different size. How to do it using ode45?

Réponses (1)

Alan Stevens
Alan Stevens le 31 Oct 2020

0 votes

The structure could look something like this
tspan = [0 tfinal];
IC = [x0 y0];
[t, xy] = ode45(@fn, tspan, IC);
x = xy(:,1);
y = xy(:,2);
function dxydt = fn(t,IC)
c1 = ...;
c2 = ...;
x = IC(1);
y = IC(2);
f1 = ... (using y);
f2 = ... (using x);
dxydt = [f2 + c2*y;
f1 + c1*x];
end
where you would have to fill in with your values of c1, c2 etc.

8 commentaires

Sib RV
Sib RV le 31 Oct 2020
Thank you. I'll try this way.
Sib RV
Sib RV le 31 Oct 2020
The trouble is, dimensions of x and y are different.'Vectors of different lengths'.
Alan Stevens
Alan Stevens le 31 Oct 2020
I took your expressions to mean f1 and f2 were functions (of y and x respectively).
When you say x and y are of different lengths, are you referring to values that represent initial conditions?
Sib RV
Sib RV le 31 Oct 2020
Modifié(e) : Sib RV le 31 Oct 2020
X and Y are vectors. x1,x2,x3. y1,y2,y3,y4. Real dimensions are around 50. And yes, f1 and f2 are functions of these vectors.
Alan Stevens
Alan Stevens le 31 Oct 2020
Modifié(e) : Alan Stevens le 31 Oct 2020
So what do the functions look like (i.e. their mathematical form); what is the time interval of integration and what are the values of x(t=0) and y(t=0)? And what are the values of c1 and c2?
Sib RV
Sib RV le 31 Oct 2020
Modifié(e) : Sib RV le 31 Oct 2020
c1 and c2 are constants. F1 and F2 are also similar,constants * (x or y). Like Y'= a y + c x. integration from 0 to arbitrary time.
Alan Stevens
Alan Stevens le 31 Oct 2020
If f1 and f2 are aso constants then it becomes even easier. Where I had
f1 = ... (using y);
f2 = ... (using x);
you simply put
f1 = ... ;
f2 = ... ;
i.e. you specify their values.
Then as long as you have intial values for x and y to go into IC you can integrate up to a time of your choosing.
I don't understand what you mean by having different numbers of x and y values. Do you mean you have values you want to compare the output against?
Do you know the values of f1, f2, c1 and c2, or are you trying to fit them by using x and y data values that you have?
Sib RV
Sib RV le 31 Oct 2020
Modifié(e) : Sib RV le 1 Nov 2020
I did it this way. x = xy(:,1:length(x)); y = xy(:,length(x)+1:end); And similarly for x and y inside the function fn also. If there is a better suggestion,you are welcome.
Thank you,

Connectez-vous pour commenter.

Question posée :

le 31 Oct 2020

Modifié(e) :

le 1 Nov 2020

Community Treasure Hunt

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

Start Hunting!

Translated by