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