help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's the correct order of things in a file? (beginner's question)


From: Robert A. Macy
Subject: Re: What's the correct order of things in a file? (beginner's question)
Date: Mon, 13 Jun 2005 18:16:22 -0700

David,

Split the two sequences of instructions into two files.

first the...
 scriptfile.m

then the second... 
 population.m
which contains everything from the line 
function x = ... onwards

then you should be able to run the script file, it will use
the function file etc.  

             - Robert -


On Mon, 13 Jun 2005 16:51:47 -0700
 David Collett <address@hidden> wrote:
> Hi, everyone.
> 
> This is only my second post as I'm just starting to learn
> octave.
> I'm not a mathematician, nor a professional. I'm actually
>  interested  in algorithmic music composition.
> 
> I've been looking at several algorithms for translating
> the logistic  map (bifurcation) function onto music
> parameters.
> 
> I went to this Wikipedia site, and saw the mention of
> Octave (which I  had never heard of).
> 
>
http://en.wikipedia.org/wiki/Image:Logistic-burification.png
> 
> So, two days ago, I installed Octave (on Mac OS X), and
> Octave ran.
> 
> I decided to copy/paste the Octave lines given on
> Wikipedia into a  text file to see if it would run.
> 
> Here are the lines in the same order that they appear on
> Wikipedia's  site
> (Wikipedia refers to each of these 7 blocks as
> "scripts"):
> 
> -----
> 
> r_min = 2.5; r_max = 4; # the range of parameter values
> we study
> n = 1000; # the number of parameter values we consider in
> this range
> 
> t_max = 1000; # how many iterations to simulate per
> parameter value
> p_max = 100; # the last p_max iterations are plotted
> 
> x0 = 0.1; # we use the same initial value x0 for all
> parameters.
> 
> r = linspace(r_min, r_max, n);
> pop = zeros(p_max, n);
> 
> for k = 1:n
>    x = population(r(k), x0, t_max);
>    pop(:, k) = x(t_max-p_max+1:t_max);
> end
> 
> gset nokey;
> plot(r, pop, 'b.');
> 
> function x =  population(r, x0, n)
> # simulates n iterations of the logistic map with
> parameter
> # r and initial value x0. The results are returned in the
> # array x.
>    x = zeros(n, 1);
>    x(1) = x0;
>    for k = 1:n-1
>      x(k + 1) = r * x(k) * (1 - x(k));
>    end
> 
> -----
> 
> When I put this in a file and tried to run it, Octave
> gave several  error messages about 'population' not being
> defined, etc.
> So, unsure of what else to try, I tried rearranging these
> blocks  until one arrangement worked. Here's what I ended
> up with:
> 
> -----
> 
> r_min = 2.5; r_max = 4; # the range of parameter values
> we study
> n = 1000; # the number of parameter values we consider in
> this range
> 
> t_max = 1000; # how many iterations to simulate per
> parameter value
> p_max = 100; # the last p_max iterations are plotted
> 
> x0 = 0.1; # we use the same initial value x0 for all
> parameters.
> 
> r = linspace(r_min, r_max, n);
> pop = zeros(p_max, n);
> 
> function x =  population(r, x0, n)
> # simulates n iterations of the logistic map with
> parameter
> # r and initial value x0. The results are returned in the
> # array x.
>    x = zeros(n, 1);
>    x(1) = x0;
>    for k = 1:n-1
>      x(k + 1) = r * x(k) * (1 - x(k));
>    endfunction
> 
> for k = 1:n
>    x = population(r(k), x0, t_max);
>    pop(:, k) = x(t_max-p_max+1:t_max);
> endfor
> 
> gset nokey;
> plot(r, pop, 'b.');
> 
> -----
> 
> I have 3 questions:
> 
> 1.  Why did the order I have work, but the one that
> Wikipedia gave  wouldn't? In other words, why does the
> function have to be moved up?
> 
> 
> 2.  In the Wikipedia version, they use for...end, and
> function...end,
> whereas in the Octave manual, I believe it says to use:
> for...endfor, and function...endfunction  (which I did).
> 
> Can you use either? Are there different "flavors" of
> Octave that use  different commands?
> 
> 
> 3.  Finally, why does Wikipedia refer to their 7 blocks
> as "scripts"?  Why not just have all of these lines in a
> single file, as I have done?
> 
> 
> Thanks again for helping a beginner!
> 
> David Collett
> 
> 
> 
> 
>
-------------------------------------------------------------
> Octave is freely available under the terms of the GNU
> GPL.
> 
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:
>  http://www.octave.org/funding.html
> Subscription information:
>  http://www.octave.org/archive.html
>
-------------------------------------------------------------
> 



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]