while loop convergence for sum

1 visualización (últimos 30 días)
Magnus
Magnus el 16 de Dic. de 2014
Comentada: Magnus el 16 de Dic. de 2014
Dear all,
I'm using a while loop in order to find a value etapl iteratively. The code looks like follows where eta(:) is a first guess (which is close to the desired solution). For N=3 it seems to work but for N>5 the solution doesnt converge but jumps between two values. It doesnt appear to be an issue with the initial values X.
for jj=1:dp % looking for a number dp of etapl
etapl=eta(jj); %assign etapl to the first guess
eta_old=etapl+0.01; %introduce an error to go into the while loop
while abs(etapl-eta_old) > 0.001 % convergence criterion
eta_old = etapl;
sum_eta=0;
for n=2:2:N-1 % a sum from n=2,4,... to N-1 that contains etapl
sum_eta=sum_eta+sinh(n*pi/X(1)*(d+etapl))*(X(n)*...
cos(n*pi/X(1)*x(jj))+X(n+1)*sin(n*pi/X(1)*x(jj)));
end
etapl=Psi/(X(1)/T-U)-1/(X(1)/T-U)*sum_eta;
end
eta(jj)=etapl;
end
Any assistance is very much appreciated!
Kind regards,
  2 comentarios
Star Strider
Star Strider el 16 de Dic. de 2014
What are T and U? Maybe I’m missing something, but I don’t see them in the code you posted. They might be important.
Magnus
Magnus el 16 de Dic. de 2014
Hey, I'm sorry. If you want to run the code they might be helpful.
T=1;
N=5; %can be changed to any other odd number but then extend the X(n) by any %value smaller than the values before, i.e. X(n+1)<<X(n)
U=0;
dp=100;
Psi=0; % or any small value e.g. 1e-2
X(1)=1.5506;
x=linspace(0,X(1),dp);
eta=0.01/2*cos(2*pi/X(1)*x(jj)); %for initial guess
X(2)=0.0013;
X(3)=8.2545e-2
X(4)=0.001e-3
X(5)=0.001e-3
Cheers

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by