heaviside.m is slow

조회 수: 3 (최근 30일)
Taehun Kim
Taehun Kim 2022년 4월 13일
댓글: Taehun Kim 2022년 4월 19일
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
Mike Croucher
Mike Croucher 2022년 4월 19일
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 2022년 4월 19일
Thanks Mike for sharing the article! I do really appreciate the MATLAB Answers community! These people are the best!

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by