Vectorization of a function with system of ODE's
1 view (last 30 days)
Show older comments
George Bashkatov
on 17 Apr 2021
Answered: Walter Roberson
on 17 Apr 2021
I want to modify famp so that it accepts a vector of y values, and reshapes the values to 2 columns, and then computes values for each row, but I don't know how I can do it. Can you help me, please?
function dydz = famp(pa,N0,pe,se,k,y,z)
k=Par.N0*pa/(pa+pe);
dy1 = y(1).*(pa.*N0+(pa+pe).*(k.*y(1)./(y(1)+y(2)+1)));
dy2 = y(2).*se.*(k.*y(1)./(y(1)+y(2)+1));
dydz = [dy1; dy2];
What can you advice to read to understand vectorization and optimization in a whole? By the way I know about documentation, but it is not enough.
0 Comments
Accepted Answer
Walter Roberson
on 17 Apr 2021
function dydz = famp(pa,N0,pe,se,k,y,z)
y = reshape(y, [], 2);
k=Par.N0*pa/(pa+pe);
dy1 = y(:,1).*(pa.*N0+(pa+pe).*(k.*y(:,1)./(y(:,1)+y(:,2)+1)));
dy2 = y(:,2).*se.*(k.*y(:,1)./(y(:,1)+y(:,2)+1));
dydz = reshape([dy1, dy2],[],1);
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!