简体   繁体   中英

How to write more than 100 differential equation in MATLAB ode function and to solve it?

I want to solve 100 differential equation by ode45. My entire 100 ode equation has same pattern ie in the form of xdot= A x + B y + C u where xdot, A, B and C have n 1 order. So the first equation is xdot(1)=A(1)*x(1) + B(1)*y(1) +C(1)*u(1) and nth equation is xdot(n)= A(n)*x(n) + B(n)*y(n) +C(n)*u(n). It is very hectic to write this 100 equation in function script file of ode MATLAB. My question is that how to write this hundred equation using for loop or any other methods in MATLAB function script and solve the ode equation?

You can define your system using matrices instead of a list of ODE's.

Given your vectors a , b and c

A = diag(a); B = diag(b); C = diag(c);
xdot = @(x, y, u) A*x + B*y + C*u;

then solve xdot using some solver like ode45 .

Edit

Of course you can also use dot-notation. I initially wrote my answer in matrix form due to that being the standard in linear algebra.

xdot = @(x, y, u) a.*x + b.*y + c.*u;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM