given this function is there a way in matlab with which i can know is its odd, even or neither?

 채택된 답변

Voss
Voss 2022년 5월 6일

1 개 추천

One thing you can do is to plot the function and visually inspect it:
f = @(x)0.5*(sin(x)+abs(sin(x)));
fplot(f,[-pi pi])
It doesn't look even or odd.
You could also evaluate the function at some values of x and -x and compare the results:
x = -pi:0.1:pi;
is_even = isequal(f(x),f(-x))
is_even = logical
0
is_odd = isequal(f(x),-f(-x))
is_odd = logical
0
(A sanity check with functions known to be odd or even)
f = @(x)sin(x);
is_even = isequal(f(x),f(-x))
is_even = logical
0
is_odd = isequal(f(x),-f(-x))
is_odd = logical
1
f = @(x)cos(x);
is_even = isequal(f(x),f(-x))
is_even = logical
1
is_odd = isequal(f(x),-f(-x))
is_odd = logical
0

댓글 수: 5

SSBGH
SSBGH 2022년 5월 6일
thanks
SSBGH
SSBGH 2022년 5월 6일
when i tried to plot it without [-pi pi] i got this
doesn't it look like an even function?
Voss
Voss 2022년 5월 6일
편집: Voss 2022년 5월 6일
No. An even function is symmetric about the y-axis.
f = @(x)0.5*(sin(x)+abs(sin(x)));
fplot(f,[-15 7.5]);
set(gca(),'YAxisLocation','origin','YLim',[-0.2 2.2])
SSBGH
SSBGH 2022년 5월 6일
thanks you are great
Voss
Voss 2022년 5월 6일
You're welcome!

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

추가 답변 (1개)

David Hill
David Hill 2022년 5월 6일

1 개 추천

x=-pi:.001:pi;
f=@(x).5*(sin(x)+abs(sin(x)));
if isequal(f(x),f(-x))
even_odd=2;%even
elseif isequal(-f(x),f(-x))
even_odd=1;%odd
else
even_odd=0;%neither
end

카테고리

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

질문:

2022년 5월 6일

댓글:

2022년 5월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by