How to find sign of a function

8 visualizaciones (últimos 30 días)
Tina
Tina el 4 de Feb. de 2013
Hello;
I have a function let's say y=x-c where c is a constant. I want to find when y is positive or negative, as c is changed. Is there a MATLAB function that can do this for me?
(Actually the function I have is a more complex one!)

Respuestas (2)

Kye Taylor
Kye Taylor el 4 de Feb. de 2013
Editada: Kye Taylor el 4 de Feb. de 2013
If you can evaluate your function with a command like
y = yourFcn(x);
then you can determine the sign with a logical variable, as in the command:
yPos = y>0;
yPos will be 1 where y is positive, and 0 where y is non-positive. So you can do stuff like
figure(1),hold on
plot(x( yPos ), y( yPos ),'r.')
plot(x( ~yPos ), y( ~yPos ),'b.')
legend('Positive values','Negative Values')
You may also be interested in the sign function
doc sign
  1 comentario
Tina
Tina el 4 de Feb. de 2013
Thanks I am gonna try this right now

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 4 de Feb. de 2013
If you have the symbolic toolbox, and you have the function in symbolic form,
y = f(x) - c
then the zeros, y = 0, are 0 = f(x) - c, and thus f(x) = c, so solve that
syms x c
solve( f(x) - c, x)
If your f(x) is not a polynomial, or is a polynomial of degree 5 or higher, there might not be an explicit solution.
  2 comentarios
Tina
Tina el 4 de Feb. de 2013
my function is not a polynomial :(
Walter Roberson
Walter Roberson el 4 de Feb. de 2013
solve() works with some non-polynomials.
Is your function such that you can constrain the maximum number of roots? For example with some trig functions roots can appear in strange places and it can be hard to guess how many you will have.
Systems that have roots that are very close together can be tricky to deal with.
The symbolic toolbox has a routine named numeric::solve that has an option to request that "all" roots be found numerically. The documentation talks about the limitations on finding the roots. numeric::solve has no direct MATLAB interface but can be accessed using feval() or evalin()

Iniciar sesión para comentar.

Categorías

Más información sobre Descriptive Statistics 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