Question: Multiple crossing points???

Hi
 

i am trying to code a proc that tells me when a certain function is better than another. My proc works fine for functions that have a single crossing point but it does not seem to work for inputs that have multiple crossing points.
 

f:=x->(10*x):
g:=x->(x^2):
Better:=proc(n,m,c)
local r,d,f,g,i,w:
f:=n:
g:=m:
d:=[solve(f(x)=c*g(x),x)];
if d = [0] then
printf("%a and %a do not cross each other",f(x),g(x)):
plot({f(x),c*g(x)},x=-0..10);
return():
else
for i from 1 to nops(d) do
r:=op(i,d);
if r = 0 then NULL else
w:=r:
lprint(f(x), `is better than`,g(x),`at`,w):
fi:
od:

#printf("%a is better than %a for any list larger than %a",f(x),g(x),w):
plot({f(x),c*g(x)},x=-0..w+10);
fi:
end proc:
Better(f,g,1);

f:=x->sin(2*x):
g:=x->cos(x):
Better:=proc(n,m,c)
local r,d,f,g,i,w:
f:=n:
g:=m:
d:=[solve(f(x)=c*g(x),x)];
if d = [0] then
printf("%a and %a do not cross each other",f(x),g(x)):
plot({f(x),c*g(x)},x=-0..10);
return():
else
for i from 1 to nops(d) do
r:=op(i,d);
if r = 0 then NULL else
w:=r:
lprint(f(x), `is better than`,g(x),`at`,w):
fi:
od:

#printf("%a is better than %a for any list larger than %a",f(x),g(x),w):
plot({f(x),c*g(x)},x=-0..w+10);
fi:
end proc:
Better(f,g,1)
 

f:=x->ln(x):
g:=x->(x):
Better:=proc(n,m,c)
local r,d,f,g,i,w:
f:=n:
g:=m:
d:=[solve(f(x)=c*g(x),x)];
if d = [0] then
printf("%a and %a do not cross each other",f(x),g(x)):
plot({f(x),c*g(x)},x=-0..10);
return():
else
for i from 1 to nops(d) do
r:=op(i,d);
if r = 0 then NULL else
w:=r:
lprint(f(x), `is better than`,g(x),`at`,w):
fi:
od:

#printf("%a is better than %a for any list larger than %a",f(x),g(x),w):
plot({f(x),c*g(x)},x=-0..w+10);
fi:
end proc:
 

Please Wait...