Question: Filtering Output of Program

I'm have used a program to find the roots of a function 

 

f:=x*cos(x)-sin(x)*sin(x/1000);
/ 1 \
x cos(x) - sin(x) sin|---- x|
\1000 /

x_max:=50; x_min:=-50; step:=2; i_max:=(x_max-x_min)/step;
50
-50
2
50

j:=1:
for i from 0 to i_max by 1 do
x0:=x_min+i*step;
x[j]:=fsolve(f=0,x=x0);
j:=j+1;
end:

 

and my output was of the form of multiple "potential" roots and a bunch of which are the same. So I tried to get rid of the ones which were the same before actually finding the ones which ARE roots. To do that I done....

 

 

j := 1; for j to 50 do if x[j]-x[j+1] = 0 then ignore(x[j]) else print(x[j]) end if end do:

 

and it got rid of the ones which are of the above form but some roots are the same and seperated by more than 1 ... i.e x[ j ]= x[j + 2] or some other number. 

 

Basically I am trying to generalise the above for loop for all "numbers" instead of 1 but when I try some things the for loop doesnt like it. 

Any help would be good!

 

 

Please Wait...