Vectorization of a function with system of ODE's

1 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2021-4-17
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 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by