help-octave
[Top][All Lists]
Advanced

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

Re: how to use for loop and convert summation in code


From: Juan Pablo Carbajal
Subject: Re: how to use for loop and convert summation in code
Date: Mon, 10 Oct 2011 10:55:31 +0200

On Mon, Oct 10, 2011 at 10:30 AM, preeti gaikwad
<address@hidden> wrote:
> Hello I am the new user of octave and getting problem in using for loop for
> value N=-10 to 10......using the code for the same
>
> ..............................
>
> N=10;
>
> for i=N:-1:1
>
> Taui=0.2;
>
> L=4.08;% in mm
>
> li=2; %inelastic absorption length in mm
>
> lt=0.5; %scattering length in mm
>
> R=0.5; %reflection coefficient
>
> D=li^2/Taui;% diffusion constant
>
> z0 = (2/3)*lt*(1+R)/(1-R);
>
> ze = (li/2)*log((1+(1/li)*z0)/(1-(1/li)*z0));
>
> zp = ze;
>
>
>
> A=(1-2*i)*(L+2*ze)-2*(zp+lt); B=(2*i+1)*(L+2*ze);
>
> T=exp(-(x./Taui))./(4.*x.*(4.*pi.*x.*D).^(3./2)).*(A.*exp([(-(A^2))/4*D.*x])-B*exp([(-B^2)/4*D.*x]));
>
>  end
>
> ......................................................................................................................................................
>
> so basically I find that my loop is not working why not getting it....could
> u please help me?
>
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>
>

Preeti,
Here is your loop corrected. Please note the changes. As a general
comment, people will be more wiling to look at your code if it is
clean and organized (I removed extra parenthesis and brackets). Also,
try always to reduce the problem to its minimum expression (most of
the time you find your errors just by doing this). Finally, do not
forget to check Octave's manual here
http://www.gnu.org/software/octave/doc/interpreter/index.html#Top

% Set parameters that do not change outside of loops
Taui = 0.2;
L = 4.08;% in mm
li = 2; %inelastic absorption length in mm
lt = 0.5; %scattering length in mm
R = 0.5; %reflection coefficient
D = li^2 / Taui; % diffusion constant
z0 = (2/3) * lt * (1 + R) / (1 - R);
ze = (li/2) * log ( (1 + (1/li) * z0) / (1 - (1/li) * z0) );
zp = ze;

nx = 10;
x = linspace(0,0.1,nx); % values for x
T = zeros(N,nx); % Preallocate vector

N = 10; % loop
for i = N:-1:1
  A = (1 - 2*i) * (L + 2*ze) - 2 * (zp + lt);
  B = (2*i + 1) * (L + 2*ze);
  T(i,:) = exp (-(x ./ Taui)) ./ ( 4.*x.*(4.*pi.*x.*D).^(3./2) ) .* (
A .* exp (-(A^2) /4*D.*x) - B * exp (-B^2/4*D.*x) );
end

-- 
M. Sc. Juan Pablo Carbajal
-----
PhD Student
University of Zürich
http://ailab.ifi.uzh.ch/carbajal/


reply via email to

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