Global versus Structure of Array
显示 更早的评论
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
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!