フィルターのクリア

How to find sign of a function

5 ビュー (過去 30 日間)
Tina
Tina 2013 年 2 月 4 日
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!)

回答 (2 件)

Kye Taylor
Kye Taylor 2013 年 2 月 4 日
編集済み: Kye Taylor 2013 年 2 月 4 日
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 件のコメント
Tina
Tina 2013 年 2 月 4 日
Thanks I am gonna try this right now

サインインしてコメントする。


Walter Roberson
Walter Roberson 2013 年 2 月 4 日
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 件のコメント
Tina
Tina 2013 年 2 月 4 日
my function is not a polynomial :(
Walter Roberson
Walter Roberson 2013 年 2 月 4 日
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()

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by