help-octave
[Top][All Lists]
Advanced

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

Re: infinite geometric series


From: Fausto Arinos Barbuto
Subject: Re: infinite geometric series
Date: Mon, 06 Jan 2014 00:59:16 -0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

On 01/04/2014 05:12 PM, Fullfill wrote:
<http://octave.1599824.n4.nabble.com/file/n4660654/1471116_731146650246828_979308716_n.jpg>

Hello !

I'm trying to implement infinite geometric series in octave but i don't know
if I'm doing it correctly.

function y=myfun(x)
  an=0;
  n=0;
  s=1;
  while abs(an)< 0.3
  n=n+1;
  an=(-3*x).^n;
  s=s+an;
  end%while
  endfunction

Also I don't know how to read in x-values as a vector to this function and
get y-values as a vector.

All helpful ideas great to see.




--
View this message in context: 
http://octave.1599824.n4.nabble.com/infinite-geometric-series-tp4660654.html
Sent from the Octave - General mailing list archive at Nabble.com.


Hello,

Write the function below into a file and save it as infinite.m:

%----------------------
function y=infinite(x)
    an = 0;
    n = 0;
    s = 1;
    while abs(an)< 0.3
        n = n + 1;
        an = (-3*x).^n;
        s = s + an;
    end
    y = s;
endfunction
%----------------------

Then, in a command line, try this:

x = linspace(1,5,40)
z = zeros(1,40)
z = infinite(x)

You should get something.  Hopefully, it's what you want.

Fausto





reply via email to

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