Vectorization of a function with system of ODE's

2 visualizaciones (últimos 30 días)
George Bashkatov
George Bashkatov el 17 de Abr. de 2021
Respondida: Walter Roberson el 17 de Abr. de 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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Abr. de 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);

Más respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by