Substitute the nonlinearity in the linear system
Afficher commentaires plus anciens
Hello everyone! I have a question about possibility of substituting some nonlinear function in system of lode’s.
For example, I have a system:
iN=1;%line
jN=2;%row
Nonlinearity=@(x) x^2;
[T,X]=ode45(@(t,x) odesys(t,x,Nonlinearity,iN,jN), [0 2],[0 0.1]
function RPF=odesys(t,x,Nonlinearity, iN, jN)
A=[0 1;0 -1];
B=[0 1];
A(iN,jN)=A(iN,jN)*Nonlinearity(x(jN))/x(jN);
RPF=A*x+B;
end
Obviously this works only if x(jN) does’nt equal zero during the integration progress, and I may suppose that this will produce some calculating errors because of dividing.
So I want to know is there better way to do this.
Thank you in advance!
Réponse acceptée
Plus de réponses (1)
Ivan Khomich
le 30 Juil 2020
3 commentaires
Walter Roberson
le 30 Juil 2020
You should read the documentation for odeFunction and follow the flow in the first example, to come up with a numeric anonymous function to pass to ode45() . Doing symbolic calculations within your ode function is always going to be notably slower than numeric work, and so should be avoided unless there happen to be functions that are only implemented through the symbolic toolbox, or if you need higher precision or higher value range than numeric can give you
Ivan Khomich
le 31 Juil 2020
Modifié(e) : Walter Roberson
le 31 Juil 2020
Ivan Khomich
le 31 Juil 2020
Catégories
En savoir plus sur Numeric Solvers dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!