while loop convergence for sum
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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
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.
Respuestas (0)
Ver también
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!