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

...