Getting a system of equations and the using ODE45
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Shreshtha Chaturvedi
le 31 Juil 2022
Commenté : Torsten
le 31 Juil 2022
Hi, I have a coefficient matrix -
Xi=
1.0e+03 *
0.3002 0.3832 0.0577
0 0 0
0 0 0
0 0 0
-0.1425 -0.1576 -0.0162
0 0 0
0 0 0
-0.0352 -0.0601 -0.0140
0 0 0
0 0 0
-0.0941 -0.1304 -0.0245
0.1394 0.1897 0.0296
0.7197 0.8981 0.1662
0.0058 0.0024 0.0061
-1.0007 -1.2808 -0.2519
0 0 0
-0.0211 -0.0250 -0.0060
0.3760 0.4933 0.0964
-0.0242 -0.0253 0.0097
0 0 0
%
To get the system of ODEs I first defined the variables, and then multiplied it by transpose(Xi) to get the system-
syms x y z xx xy xz yy yz zz xxx xxy xxz xyy xyz xzz yyy yyz yzz zzz
var = [1;x;y;z;xx;xy;xz;yy;yz;zz;xxx;xxy;xxz;xyy;xyz;xzz;yyy;yyz;yzz;zzz]
A = transpose(Xi)
Xdot = A*var
where Xdot is the column containing the derivatives, ie. Xdot = [x' ; y' ; z']. The code above gives me the output:
Xdot =
(4905784495475543*xxy)/35184372088832 - (6622198076817333*xxx)/70368744177664 - (1253707074885461*xx)/8796093022208 + (6330728071069091*xxz)/8796093022208 + (6526091537672905*xyy)/1125899906842624 - (550152702477171*xyz)/549755813888 - (4953639297776579*yy)/140737488355328 - (743004146196139*yyy)/35184372088832 + (6615295418414269*yyz)/17592186044416 - (3404894971584935*yzz)/140737488355328 + 2640157789935161/8796093022208
(6675905246377611*xxy)/35184372088832 - (4586552884284477*xxx)/35184372088832 - (2773298922331439*xx)/17592186044416 + (987449040685507*xxz)/1099511627776 + (2666532593051851*xyy)/1125899906842624 - (5632811008410909*xyz)/4398046511104 - (8464188990339351*yy)/140737488355328 - (7048704279715849*yyy)/281474976710656 + (4339015521236507*yyz)/8796093022208 - (7129115399973291*yzz)/281474976710656 + 3370686532933275/8796093022208
(2082177599331991*xxy)/70368744177664 - (863749208859729*xxx)/35184372088832 - (4564685191010399*xx)/281474976710656 + (5847277141854391*xxz)/35184372088832 + (6877937169110265*xyy)/1125899906842624 - (8862390418139439*xyz)/35184372088832 - (491773253308733*yy)/35184372088832 - (3353395911004425*yyy)/562949953421312 + (6782944326528325*yyz)/70368744177664 + (5481194070111587*yzz)/562949953421312 + 2029864570192639/35184372088832
My question is
a) Is there a better way to define the system of ODEs?
b) How do I solve this system using ODE45? I do not want to manually input the equations, as my coefficient matrix will vary if I have a different dataset, so I cannot manually input equations everytime.
c) If I have 5 variables, say, x1,x2,x3,x4,x5 can I still use ODE45 to solve a system of ODEs containing 5 equations?
2 commentaires
Torsten
le 31 Juil 2022
As far as I can see, you have 3 equations for 19 unknowns. What are the missing 16 equations ?
Réponse acceptée
Torsten
le 31 Juil 2022
Modifié(e) : Torsten
le 31 Juil 2022
fun = @(x) Xi.'*[1;x(1);x(2);x(3);x(1)^2;x(1)*x(2);x(1)*x(3);x(2)^2;x(2)*x(3);x(3)^2;x(1)^3;x(1)^2*x(2);x(1)^2*x(3);x(1)*x(2)^2;x(1)*x(2)*x(3);x(1)*x(3)^2;x(2)^3;x(2)^2*x(3);x(2)*x(3)^2;x(3)^3];
tspan = [0 1]; % time interval of integration
x0 = [1; 1; 1]; % Initial conditions
[T,X] = ode45(fun,tspan,x0) % solver call
5 commentaires
Plus de réponses (1)
Walter Roberson
le 31 Juil 2022
I recommend that you read the first example for odeFunction() to see the flow to turn an array of equations into something that can be evaluated numerically by ode45()
0 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!