while loop convergence for sum

2 次查看(过去 30 天)
Magnus
Magnus 2014-12-16
评论: Magnus 2014-12-16
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 个评论
Star Strider
Star Strider 2014-12-16
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 2014-12-16
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

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by