odd and even functions

31 visualizaciones (últimos 30 días)
SSBGH
SSBGH el 6 de Mayo de 2022
Comentada: Voss el 6 de Mayo de 2022
given this function is there a way in matlab with which i can know is its odd, even or neither?

Respuesta aceptada

Voss
Voss el 6 de Mayo de 2022
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 comentarios
SSBGH
SSBGH el 6 de Mayo de 2022
thanks you are great
Voss
Voss el 6 de Mayo de 2022
You're welcome!

Iniciar sesión para comentar.

Más respuestas (1)

David Hill
David Hill el 6 de Mayo de 2022
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

Categorías

Más información sobre Just for fun 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