Substitute the nonlinearity in the linear system
Show older comments
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!
Accepted Answer
More Answers (1)
Ivan Khomich
on 30 Jul 2020
3 Comments
Walter Roberson
on 30 Jul 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
on 31 Jul 2020
Edited: Walter Roberson
on 31 Jul 2020
Ivan Khomich
on 31 Jul 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!