heaviside.m is slow

7 visualizaciones (últimos 30 días)
Taehun Kim
Taehun Kim el 13 de Abr. de 2022
Comentada: Taehun Kim el 19 de Abr. de 2022
I am using heaviside.m inside the right hand side function for ode45. There is a for loop within the right hand side function that gets evaluated at each time point the integrator takes a step into. I profiled the result because the code has gotten much slower. This is where I learned that heaviside.m is very slow.
We can use logical indexing to replace the heaviside.m function. I did this and this is much faster but not as fast as it should be... Unfortunately, the for loop cannot be vectorized because the system is a linear system with a non linear right hand side vector.
Do you think the logical indexing is the fastest way to map a real number to 0 or 1, depending on it sign, in MATLAB? Also, could there be any speed up with the for-loop, if we cannot get rid of it?
Thanks a lot for your help!
Sincerely,
Tae
  2 comentarios
Mike Croucher
Mike Croucher el 19 de Abr. de 2022
Hi Tae
You are much more likely to get an answer if you post your code. Help us help you: Post your code - (mathworks.com)
We can't promise anything of course but it definitely helps.
Best Wishes,
Mike
Taehun Kim
Taehun Kim el 19 de Abr. de 2022
Thanks Mike for sharing the article! I do really appreciate the MATLAB Answers community! These people are the best!

Iniciar sesión para comentar.

Respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by