Results 1 to 3 of 3

Math Help - find intervals with just one root of function

  1. #1
    Newbie
    Joined
    May 2009
    Posts
    1

    find intervals with just one root of function

    hello,
    I have to write a script that will give me a matrix M, with the intervals of x-values of a function, and every interval has JUST ONE root of the function:
    every row of M has 2 elements (so M has 2 columns)
    the elements are the first and last number of the interval, so the first column of M has the numbers of the second column of M, only one row lower.
    The numbers has to be integers!!!:
    for example:
    y = x^3 - 9x + 0.1, that script should give me
    M = [-2 1;1 4]
    i have started a script like this:

    xt = test_fun([a:b]) is a reference to another script I already made, that just gives me a vector xt with the y-values of a function
    the function i have to work with
    y = x0*cos((sqrt(4*m*k - b.^2))*t/(2*m)).*exp(-b*t/(2*m)),
    but that shouldn't have any influence on the answer, note that we don't know in advance how many roots the function has...
    I know I'm probably supposed to use the 'sign' function, because if i want an interval with just one root, i have to see if the y-values have a different sign

    function [M] = intervals(a,b)
    xt = test_fun([a:b]);
    n = length(xt);
    y = zeros(1,n);
    for i = 1:n
    y(i) = sign(xt(i));
    for j = i+1:n
    if (y(i) == y(j)); break; end
    end
    how do I continue?
    I also started a while-loop once, "while the signs of the y values are the same, i don't have an interval yet...", but I got stuck there, too...

    As an alternative i could use the plot of the function to 'see' how many intervals I'm supposed to look for, but that wouldn't give me a totally correct answer, but i'ts something...

    This is due 5th of june, I hope someone can help me...
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Senior Member
    Joined
    Dec 2007
    From
    Melbourne
    Posts
    428
    y = x^3 - 9x + 0.1, that script should give me
    M = [-2 1;1 4]
    Either I am misunderstanding the question, or it shouldn't. There is no root between 1 and 4.

    The sign function won't be able to help you very much, I'm afraid, since it is possible to have a root without a change of sign if the graph just touches the x-axis.

    Are you sure you are not allowed to take advantage of the function? Cleaning up the constants produces y = x_0\cos(pt)e^{qt}. You probably know something about the roots of the cos and exponential functions that could allow you to calculate the roots from the values of p and q. I don't think that what the script is supposed to do is possible if it must work for every function.
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by Babs310788 View Post
    hello,
    I have to write a script that will give me a matrix M, with the intervals of x-values of a function, and every interval has JUST ONE root of the function:
    every row of M has 2 elements (so M has 2 columns)
    the elements are the first and last number of the interval, so the first column of M has the numbers of the second column of M, only one row lower.
    The numbers has to be integers!!!:
    for example:
    y = x^3 - 9x + 0.1, that script should give me
    M = [-2 1;1 4]
    i have started a script like this:

    xt = test_fun([a:b]) is a reference to another script I already made, that just gives me a vector xt with the y-values of a function
    the function i have to work with
    y = x0*cos((sqrt(4*m*k - b.^2))*t/(2*m)).*exp(-b*t/(2*m)),
    but that shouldn't have any influence on the answer, note that we don't know in advance how many roots the function has...
    I know I'm probably supposed to use the 'sign' function, because if i want an interval with just one root, i have to see if the y-values have a different sign

    function [M] = intervals(a,b)
    xt = test_fun([a:b]);
    n = length(xt);
    y = zeros(1,n);
    for i = 1:n
    y(i) = sign(xt(i));
    for j = i+1:n
    if (y(i) == y(j)); break; end
    end
    how do I continue?
    I also started a while-loop once, "while the signs of the y values are the same, i don't have an interval yet...", but I got stuck there, too...

    As an alternative i could use the plot of the function to 'see' how many intervals I'm supposed to look for, but that wouldn't give me a totally correct answer, but i'ts something...

    This is due 5th of june, I hope someone can help me...
    Try something like:

    Code:
     
    function [M] = intervals(a,b)
      xx=a:b
      xt = test_fun(xx);
      n = length(xt);
      ss=(xt>0);
      ss1=ss(1:n-1);
      ss2=ss(2:n);
      dss=ss1-ss2;
      idxs=find(dss);
      sz=length(idxs);
      M=zeros(sz,2);
      for ii=1 to idxs
         M(ii,:)=[xx(idxs(ii)),xx(idxs(ii)+1)];
      end
    Note all this does is find where your function changes sign on the grid defined by your arguments.

    Also code not tested in this form, so you may need to debug it.

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. factoring to find intervals of a function...
    Posted in the Calculus Forum
    Replies: 6
    Last Post: June 15th 2011, 09:32 PM
  2. how to find the intervals
    Posted in the Calculus Forum
    Replies: 0
    Last Post: February 4th 2010, 10:08 AM
  3. Find the intervals INC/DEC
    Posted in the Calculus Forum
    Replies: 1
    Last Post: November 23rd 2009, 06:00 AM
  4. Find zero/Find positive intervals
    Posted in the Pre-Calculus Forum
    Replies: 1
    Last Post: May 29th 2009, 08:22 PM
  5. Find the intervals?
    Posted in the Calculus Forum
    Replies: 1
    Last Post: August 13th 2008, 10:55 PM

Search Tags


/mathhelpforum @mathhelpforum