How to write proper convergence criteria?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am writing a code to simulate the similarity solution for flow over a flat plate. I input some guess value for df2deta2 and want the code to run until it satisfies the boundary condition dfdeta=1 and eta_max. Even when the criteria is not met inside the while loop, it will still output a graph. This is my code so far:
clear all;
eta_max=10;
N=101;
Delta_eta=eta_max/(N-1);
for i=1:N
eta(i)=(i-1)*Delta_eta;
end
f=zeros(1,N);
dfdeta=zeros(1,N);
df2deta2g=zeros(1,N);
for i=1:N
df2deta2g(i)=0.2;
end
tol=0.01;
err=2*tol;
while (err>tol)
f(1)=-0.2;
dfdeta(1)=0;
df2deta2g(1)=0.3; %guess value for df2deta2
for i=1:(N-1)
f(i+1)=f(i)+(dfdeta(i)+dfdeta(i+1))*Delta_eta/2;
dfdeta(i+1)=dfdeta(i)+(df2deta2g(i)+df2deta2g(i+1))*Delta_eta/2;
df2deta2g(i+1)=df2deta2g(i)-(2*f(i)*df2deta2g(i)+2*f(i+1)*df2deta2g(i+1))*Delta_eta/2;
end
dfdeta(N)=1;
dfdeta=dfdeta+(df2deta2g+df2deta2g)*Delta_eta/2;
err=(1-max(dfdeta));
df2deta2=df2deta2g;
end
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!