Creating the nonlinear system with odeFunction
Show older comments
Hello everyone!
I'm trying to write something what would create the nonlinear system of differential equations automatically from linear system matrix.
I have some succes with it, but my solutions requires a lot of time when I "invent" this novelties in my main programm. The best result I get was 50 sec, while handwritten system requires less than 1.5 sec.
I was recommended to use the odeFunction(), in case of speed, but I meet some problems that I don't understand nor with documentation, nor while reading the other answers. There are them:
1)
syms xs(t) [1 3];
B=[0;0;1];
xs(t)
f = [xs2(t)^2;
-xs2(t)+xs3(t);
-2*xs3(t)];
f=f+B;
vars=xs;
initConditions=[-1 0 0];
odefun = odeFunction(f,vars);
ode45(odefun, [0 2], initConditions)
This works okay, but there the system is handwritten. So, I write something like this
syms xs(t) [1 SysOrder]
iN=1;
jN=2;
Nonlinearity=@(x) x^2;
A=[0 1 0; ...
0 -1 1;...
0 0 -2];
LinearSystemHomogen=A*xs(t).';
LinearSystemHomogen(iN)=subs(LinearSystemHomogen(iN), xs(jN),Nonlinearity(xs(jN)))
And I do not know how to correctly adress to the needed element of vector xs(t).
If anyone can suggest something good to approach this problem, I'll appreciate this.
Thank you in advance!
P.S. 2) Just a funny question: how to turn off the plot output when calling an ode45 with odeFunction()?
Answers (1)
Ivan Khomich
on 2 Aug 2020
Categories
Find more on Numeric Solvers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!