Global versus Structure of Array
Mostrar comentarios más antiguos
For solving ODE using ODE suit, I have to deal with more than 30 constant parameters. The question whether using Global or structure-of-array is the best coding practice to represent the constant parameter.
Most of the advice I read on the net suggest that structure of array is indeed memory efficient. However,from my experience, by using structure-of-array for calculating the derivative inside the ODE suite, MATLAB will re-assess the structure within the array repetitively. Somehow, I guest this will consume the processing time. Second, in term of readability, this will make the code rather long. for example, see the representation in (A) and (B)
(A): structure-of-array Assume we fill the structure s.someval=12; s.de.val=1000;
So, I will write it as
c=time.*s.someval./s.de.val;
Whereas,
(B): Global Assume we define the global parameter someval=12; val=1000; c=time.*someval./val
As you can see, if the equation is complex and long, the equation represent under the structure-of-array compare to global-type will be hard to read and maintain.
May I know, in practice, which is the best approach?
Thanks
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Ordinary Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!