1. How do I write a program to calculate the golden section?

I want to use Euphoria to make a fibonacci series like:
        1,2,3,5,8,13,24,37,51
Where each term is the sum of the last two terms
       As the terms get larger, the value for the golden section gets
more exact. I downloaded a program that calculates pi to any number of
digits specified. I'm looking for something like that.I examined the
code, but I couldn't figure out how I'd introduce the formula to
calculate the series.
       I'm new to Euphoria and would greatly appreciate it if anyone
could help out!
Rafael Skovron


_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

new topic     » topic index » view message » categorize

2. Re: How do I write a program to calculate the golden section?

-- code begins --
atom height, width, old_height, gold_sect
height = 1
width = 1
for i = 1 to 50 do
  gold_sect = height / width
  printf(1, "height: %d  width: %d  ratio: %1.16f\n", {height, width,
 gold_sect})
  old_height = height
  height = width
  width = old_height + width
end for
-- code ends

 _______  ______  _______  ______
[    _  \[    _ ][ _   _ ][    _ ]
[/| [_] |[/| [_\][/ | | \][/| [_\]
  |  ___/  |  _]    | |     |  _]
[\| [/]  [\| [_/] [\| |/] [\| [_/]
[_____]  [______] [_____] [______]
xseal at harborside.com  ICQ:13466657
http://www.harborside.com/home/x/xseal/euphoria/

new topic     » goto parent     » topic index » view message » categorize

3. Re: How do I write a program to calculate the golden section?

On Wed, 10 Jun 1998, Rafael Skovron wrote:

> I want to use Euphoria to make a fibonacci series like:
>         1,2,3,5,8,13,24,37,51
> Where each term is the sum of the last two terms
>        As the terms get larger, the value for the golden section gets
> more exact. I downloaded a program that calculates pi to any number of

Basically the golden section is given by the formula:

                     1 + square_root_of 5
               Phi = --------------------
                               2

or the Iterative formula:

                             1
               Phi    = 1 + ---
                  n+1       Phi
                               n

So you could use these:
-- This code is from my mathbag.e:

global constant Phi = (1 + sqrt(5))/2
    -- The golden section in it's entirety!
global constant Psi = (1 - sqrt(5))/2
    -- The -ve "golden section"

-- Fibonacci

global function fibonacci(integer n)
    return (power(Phi,n) - power(Psi,n)) / sqrt(5)
end function

global function lucas(integer n)
    return power(Phi,n) + power(Psi,n)
end function

However I suspect you may be wanting to calculate Phi to 'n' decimal
places rather than calculate the Fibonacci & Lucas Series from Phi!

If that's the case, you'd have to write your own number handling routines
as Euphoria is usually good for only 15 decimal places...

The formula you'd have to use (assuming you don't have sqrt() available)
would be:

include bigatom.e -- This is something I'm working on. I haven't released
                  -- it yet...
bigatom One -- I'll assume this data type and associated routines have
bigatom Phi -- been coded already in bigatom.e...

One = make_bigatom(1)
Phi = One

puts(1, "Hit SpaceBar to stop me!\n")

while get_key != ' ' do
    Phi =
        add_bigatoms(One,
            divide_bigatoms(One, Phi)
        ) -- Phi = 1 + (1 / Phi)
    display_bigatom(Phi)
end while

--
Carl R White
E-mail...: cyrek- at -bigfoot.com              / Remove the hyphens before
Finger...: crwhite- at -dcsun1.comp.brad.ac.uk \ mailing or fingering...
Url......: http://www.bigfoot.com/~cyrek/

new topic     » goto parent     » topic index » view message » categorize

4. Re: How do I write a program to calculate the golden section?

Hi Rafael
The Fibonacci series is the series where each term is the sum of the
preceding two terms, starting with 1,1 as the first two terms

A code snippit like this will print a Fibonacci series L terms long
<<begin code>>
integer L
sequence Fib
Fib={1,1}
L=100
for n=3 to L by 1 do
    Fib=append(Fib,(Fib[n-1]+Fib[n-2]))
end for
?Fib
<< end code>>

You'll note that the ratio of adjacent terms does approach the golden
mean the farther into the series you go.

Bye
Martin

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu