How to get eqns datatype from equations in function?

I can use functions like A = equationsToMatrix(eqns) with direct eqns input parameters, e.g.
A = equationsToMatrix([x+y,4*x-2*y]);
but when storing equation systems in functions like
function dZ = ODE(~,z)
x = z(1);
y = z(2);
dZ = [x+y;...
4*x-2*y];
end
I need a reference to the equations in the function so that i could use it like
A = equationsToMatrix([oderef(1),oderef(2)]); %does not work!
oderef(1) and oderef(2) must stand for the 2 equations defined in my function ODE and must be of datatype eqns so that equationsToMatrix can accept these as a parameter. How do I do that? Thanks.

Answers (1)

There is no "eqns" datatype.
It looks to me as if you should be using
odehandle = matlabFunction(A(:), 'vars', {t, [x, y]});

3 Comments

Thanks, I think I understand what the approach is here but I don't see yet how this goes along with my concept of having different ODEs defined in several functions. My goal is to use these functions of ODEs (like the one above) to store equation systems and use these via function handles in different other (generic) numerical functions (like plot_eigenvectors, plot_vectorfield or ode45).
Maybe my idea of storing these ODEs is not appropriate, is there any other data structure (like a struct or something) to store and use several ODEs for generic use in numerical functions? There will be only one ODE used in a run, which is choosen before a run by typing it's name in a section of the code called "settings", like odename = 'Chaos42-ODE'; (which is the name of the corresponding function containing this ODE).
Is there a particular form that your original ODE must be in?
Do any of the ODE involve second derivative? Are any of them second order? Do any of them involve mass matrices? With your reference to eigenvectors, does that imply you are working with Matrix Differential Equations?
My ODEs will be linear only, have no second derivative, will be 1st order only and yes, I am working with Matrix Differentials. It's fine and wanted to have the equations as input constant and transform them back to a matrix if needed.

Sign in to comment.

Asked:

on 24 Sep 2017

Edited:

on 26 Sep 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!