Recursive loop

  • Follow


Hi,

I want to compute the following loop:

a=2
for k=0:100
      
   
    x=a*x;
  
end

My problem is I only get the last value x(k=100).

How can I "collect" all the x(k) in a vector?

thanks in advance 
feelaex
0
Reply feelaex 11/19/2010 1:37:04 PM

> Hi,
> 
> I want to compute the following loop:
> 
> a=2
> for k=0:100
>       
>    
>     x=a*x;
>   
> end
> 
> My problem is I only get the last value x(k=100).
> 
> How can I "collect" all the x(k) in a vector?
> 
> thanks in advance 
> feelaex

a = 2;
n = 100;
x0 = 1.0;

x = zeros(n);

x(1) = x0 ;
For k = 1:(n-1)
x(k+1)=a*x(k);
end

Best wishes
Torsten.
0
Reply Torsten 11/19/2010 9:10:55 AM


1 Replies
239 Views

(page loaded in 0.026 seconds)

Similiar Articles:













7/22/2012 6:33:28 AM


Reply: