Jimmy19001

128 Reputation

2 Badges

14 years, 279 days

MaplePrimes Activity


These are answers submitted by Jimmy19001

yh but what values would it be? Would it be the two values just before a??, so %% stands for the previuous 2 values? and % stands for the previous value?

Yes Jabz, i couldnt agree more. Who ever this is i think is doing this for a joke and is just trying to be funny. But if they use this exact code then they will be failed automatically. I have used my own code which is similar to my bubble sort but i have included code after it. See ypu in next lecture.

Bogosort is used to basically randomlys sort a list. Bogo-sort is equivalent to repeatedly throwing a deck of cards in the air, picking them up at random, and then testing whether they are in order.

So which of the two procedures above would you recommend me following in order to compare them to bubble and cocktail sort?

Using it to compare this method to the likes of bubble and cocktail sort and then see which method is more effective.

Much appriciated

I tried this but still no luck.

bubblesort:=proc(C)
local n,o,r,k,i:
n:=rtable_dims(C):
o:=rhs(n):
r:=lhs(n):
for i from r to o - 1 do
if C[i] > C[i+1] then
(C[i], C[i+1] ) := (C[i+1], C[i]);
else
(C[i], C[i+1] ) := (C[i], C[i+1] );
fi:
od:
for k from r to o - 1 do
if C[k] < C[k-1] then
(C[k-1],C[k]) := (C[k],C[k-1]);
else
(C[k-1],C[k]) := (C[k-1], C[k]);
fi:
od:
return(C);
end proc:

 C:=rtable(1..6,random(1..50));
bubblesort(C);

Error, (in bubblesort) Array index out of range

 

What would the nested loop look like, its similar to the cocktail sort code, but cant seem to notice what differs,

 

I understand now.

thanks a lot

Cheers Joe.

Just one final question for you.

Why is it that you have to do bisection2(x -> x^2-2, 1, 3, 1e-7); and when doing it for cos you oly have to do bisection2(cos, 1, 3, 1e-7); i thought you would have to put x-> infront of the cos.

Still new to maple and don't get all these rule sorry lol.

Joe the method you showed above doesnt work with certain values. If you do;

bisection2(x^2-2, 1, 3, 1.0e-7); in your procedure i get an error when debugging.

Error, unable to evaluate sign
bisection2:
   5     if sign(f(c)) = sign(f(a)) then
           ...
         else
           ...
         end if

Many thanks if you could explain what ive done wrong

 

Many thanks acer, you've been a great help.

Many thanks

Many thanks Joe and Acer...

My next question is how is Joes procedure just a bisection method and Acers is a recursive version?

Thanks

Acer could you explain a bit more please. I'm still new to maple and dont understand it that easy.

How is your code above recursive?

Many Thanks

Page 1 of 1