New Reply

I need help writing a mathematica function.

 
Share Thread Thread Tools
Apr9-11, 04:01 PM   #1
 

I need help writing a mathematica function.


The Farey sequence F_n (F subscript n) for any positive integer n is the set of irreducible rational numbers a/b with 0<(or equal to)a<(or equal to)b<(or equal to) n and (a,b)=1 arranged in increasing order. The first one should be:

F_1 = {0/1,1/1}

F_2 = {0/1,1/2,1/1}

F_3 = {0/1,1/3,1/2,2/3,1/1}

F_4 = {0/1,1/4,1/3,1/2,2/3,3/4,1/1}

F_5 = {0/1,1/5,1/4,1/3,2/5,1/2,3/5,2/3,3/4,4/5,1/1}

I need to write a mathematica function that takes a positive integer n and returns, as a list, the nth Farey sequence, I really need some help?
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Bird's playlist could signal mental strengths and weaknesses
>> Minus environment, patterns still emerge: Computational study tracks E. coli cells' regulatory mechanisms
>> Bacterium uses natural 'thermometer' to trigger diarrheal disease, scientists find
Apr11-11, 09:29 PM   #2
 
Some hints that should help you get started.

What if you made a Table[] containing all i/j? where 0<=i<=n and 1<=j<=n?

There are several things wrong with that, it has extra {} and duplicate values and values in the wrong order and extra values you don't want.

What can you do to get rid of what you don't want and leave what you need?

Try addressing those problems, perhaps one at a time, and show what progress you have made.

You should be able to accomplish all this with a single line.

Note: Most Mathematica questions usually go in the OtherSciences/Math&ScienceSoftware section.
Apr12-11, 10:21 AM   #3
 
I tried this, but it still doesn't work, I am very new at using this program.


FareySequence[n_] := local a, b, c, d, k;
a := 0; b := 1; c := 1; d := n;
printf (` % d/% d \n `, a, b);
while (c < n) do
k := floor ((n + b)/d);
a := c; b := d; c := k*c - a; d := k*d - b;
printf (` % d/% d \n `, a, b);
od : end :
Apr12-11, 03:06 PM   #4
 

I need help writing a mathematica function.


What you wrote isn't Mathematica.

FareyFirstStep[n_]:=Table[i/j,{i,0,n},{j,1,n}]

will do the very first step I suggested.

If you look at the result of that, for say FareyFirstStep[4], can you identify that it seems to be providing some interesting and useful bits that are going in the direction of what you need?

Now describe one thing that is wrong with the result from FareyFirstStep and how can you fix that using a single Mathematica supplied function?

Hint: There are several different things wrong and it may be easier to fix those in one particular order than trying to fix them in some other order so think about what fix might make your next needed fix easier to do. You are nibbling away at the problem a little at a time while you try to make sense of the Mathematica language.
Apr12-11, 09:20 PM   #5
 
Would I have to use the flatten command?
Apr13-11, 02:17 PM   #6
 
Is this a homework problem?
New Reply

Tags
farey, mathematica, number, sequence, theory
Thread Tools


Similar Threads for: I need help writing a mathematica function.
Thread Forum Replies
Writing the sum of a series as a function of x Calculus & Beyond Homework 1
Help needed in writing the Hamiltonian function Classical Physics 2
Give to an interpolation function an analitic function with mathematica Math & Science Software 1
Writing a function as an exponent - please clarify General Math 1
Writing down the step function Precalculus Mathematics Homework 2