where do i make mistake in my loop

1 visualizzazione (ultimi 30 giorni)
mehmet salihi
mehmet salihi il 5 Giu 2021
Commentato: mehmet salihi il 5 Giu 2021
dear friends, i am facing problem in my for loop to draw the itertaion number versus w.
w has an effect to the iteration number of this problem, when Wopt is 1.78 and the iteration number is 63.
i am checking the number for w from 0 up to 2. for an example, i am sharing the iteration versus graph below my code.
thanks for your support.
clear
close all, clc
format short
%Defining the constants
L=5; % length
H=5; % Height
deltax=0.2
deltay=0.2
Beta=deltax/deltay
Beta2=Beta^2
jn=H/deltay % Maximum number of grid points along y
im=L/deltax % Maximum number of grid points along x
Si1=100; Si2=0; % boundary conditions
y=H:-deltay:0;
x=0:deltax:L;
a= round(((cos(pi/im)+cos(pi/jn))/2)^2,4)
Wopt= round(( (2-2*(sqrt(1-a)))/a ),2) % Relaxation Method
w=0:0.01:2; % to draw iteration graph
% initialize T_old to the initial guess values
Si_old=zeros(jn+1,im+1);
% set boundary conditions
Si_old(1,7:im+1)=Si1; % 5 ft TOP
Si_old(jn+1,1:im+1)=Si2; % 3 ft bottom
Si_old(1,6)=0.001; % inlet
Si_old(1:jn+1,1)=Si2; % 5 ft left side
Si_old(1:16,im+1)=Si1; % 3.8 ft right side
Si_old(17,im+1)=0.001; % outlet
Si_new = Si_old;
Error = 0.011; % could be any number that is greater than Errormax
Errormax=0.01;
iter=0;
for o=1:length(w) %the loop for iteration graph
while Error > Errormax
iter(o)=iter+1;
for i=2:jn
for j=2:im
Si_new(i,j)=(1-w(o))*Si_new(i,j) + (w(o)/(2*(1+Beta2)))* (Si_new(i-1,j)+Si_new(i+1,j)+Beta2*(Si_new(i,j+1)+Si_new(i,j-1)) ) ;
end
end
Error = sum(sum(abs(Si_old-Si_new),2)) ;
Si_old = Si_new;
end
if o==Wopt
Si_new=flip(Si_new);
disp(' ');disp(' Y x=0.0 X=1.0 X=2.0 X=3.0 X=4.0 X=5.0 ')
disp(' ');
disp([y' Si_new(:,find(abs(x-0.0) < 0.001)) Si_new(:,find(abs(x-1) < 0.001))...
Si_new(:,find(abs(x-2) < 0.001)) Si_new(:,find(abs(x-3) < 0.001))...
Si_new(:,find(abs(x-4) < 0.001)) Si_new(:,find(abs(x-5.0) < 0.001))])
disp(' '); disp(['Number of iteration for Point Successive Over Relaxation method is ',int2str(iter)])
end
figure(2)
plot(t(o),w(o)); hold on
end
  2 Commenti
Walter Roberson
Walter Roberson il 5 Giu 2021
Wopt= round(( (2-2*(sqrt(1-a)))/a ),2) % Relaxation Method
so Wopt is rounded to two decimal places
for o=1:length(w) %the loop for iteration graph
o will be an integer
if o==Wopt
are you sure you want to compare your two-decimal-place Wopt to the integer o ??
mehmet salihi
mehmet salihi il 5 Giu 2021
i had to put all matrix initialization inside the first loop. and some modification as you wrote have been done
thank you for help.

Accedi per commentare.

Risposte (1)

Houssem
Houssem il 5 Giu 2021
First t is not defined in the program, second w is not calculated in your program
  2 Commenti
mehmet salihi
mehmet salihi il 5 Giu 2021
i had to put all matrix initialization inside the first loop.
thank you for help.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by