What is the problem with the heaviside function?

fun =
@(p,x)p(1)*heaviside(x-p(2))
Undefined function 'heaviside' for input arguments of type 'double'.

 채택된 답변

Star Strider
Star Strider 2015년 9월 10일

5 개 추천

Your function works for me. Do you have the Symbolic Math Toolbox?
If you don’t substitute a call to this one for the heaviside call:
hvsd = @(x) [0.5*(x == 0) + (x > 0)];
I tested both, they give equivalent results.

댓글 수: 2

Mr M.
Mr M. 2015년 9월 10일
Symbolic Math Toolbox for what? for the heaviside function??
Star Strider
Star Strider 2015년 9월 10일
편집: Star Strider 2015년 9월 10일
Yes. The heaviside function is only in the Symbolic Math Toolbox. My function provides the same results, so you can use it instead. I abbreviated its name to ‘hvsd’ be sure it didn’t overshadow heaviside on my computer so I could test both of them. You can obviously name it whatever you want.

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

추가 답변 (1개)

Thorsten
Thorsten 2015년 9월 10일
편집: Thorsten 2015년 9월 10일

1 개 추천

The error means that Matlab cannot find the heaviside function. Try
which heaviside
to locate the function. The heaviside function is part of the Symbolic Math Toolbox. If you do not have this TB, you can write your own heaviside function
function y = heaviside(x)
y = (x > 0) + 0.5*(x == 0);

댓글 수: 1

@Thorsten Thanks for your answer. It helped me debug my code.

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

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

질문:

2015년 9월 10일

댓글:

2022년 2월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by