How can I find the last alpha_k value?
Show older comments
function main % Hauptfunktion
x0 = 200; % Startwert für die erste Iteration. Ermittelt anhand des Plots der Funktion
eps = 0.4; % Emissionsverhältnis
c_s = 5.67*10^(-8); % Strahlungskonstante
c12 = eps * c_s; %
alpha_k = 4; % Wärmeübergangskoeffizient bei ruhender Luft
s1 = 0.250; % Wanddicke der feruerfesten Stein
s2 = 0.015; % Wandddicke der äußeren Stahlwand
lamda1 = 0.35; % Wärmeleitfähigkeit der feuerfesten Stein
lamda2 = 22.7; % Wärmeleitfähigkeit der Stahlwand
Tw_1 = 1200; % Wandtemperatur der feuerfesten Stein
T_l = 10; % temperatur der Umgebungsluft
Pr = 0.7095;
lambda_L = 25.12;
betha = 3.543*10^(-3);
v = 144.0*10^(-7);
L = 7;
B = 15;
A = B * L;
g = 9.81;
Ra = @(x)Pr*(g*L^3*betha*(x-T_l))/v^2;
q1=0.825;
q2=0.387/((1+((0.492/Pr)^9/16))^(8/27));
q3=lambda_L/L;
alpha_k=@(x) ((q1+q2*(Ra(x)^(1/6)))^2)*q3;
%alpha_k = @(x)((0.825+(0.387*Ra(x)^1/6)/(1+(0.492/Pr)^9/16)^8/27)^2)*lambda_L/L;
func = @(x) eps * c_s * x^4 + (alpha_k(x) + 1/(s1/lamda1+s2/lamda2)) * x - ((1/(s1/lamda1+s2/lamda2)) * Tw_1 + alpha_k(x) * T_l); % Die Funktion
difft = @(x) (1713652349303737*x^3)/18889465931478580854784 - (138885763149071439966638298011785481*((6966792533989255*((2726811173664208678832570368*x)/66848762121410525 - 5453622347328417357665140736/13369752424282105)^(1/6))/18014398509481984 + 33/40))/(736008079697311707955200*((2726811173664208678832570368*x)/66848762121410525 - 5453622347328417357665140736/13369752424282105)^(5/6)) + (628*((6966792533989255*((2726811173664208678832570368*x)/66848762121410525 - 5453622347328417357665140736/13369752424282105)^(1/6))/18014398509481984 + 33/40)^2)/175 + (138885763149071439966638298011785481*x*((6966792533989255*((2726811173664208678832570368*x)/66848762121410525 - 5453622347328417357665140736/13369752424282105)^(1/6))/18014398509481984 + 33/40))/(7360080796973117079552000*((2726811173664208678832570368*x)/66848762121410525 - 5453622347328417357665140736/13369752424282105)^(5/6)) + 31780/22721;
xsol = newton_raphson(func, difft, x0)
wl = (1/(s1/lamda1+s2/lamda2))*(Tw_1-xsol) % Wärmestrom für Wärmeleitung
wsk = alpha_k(xsol) * (xsol-T_l) + (eps*c_s*xsol^4) % Wärmestrom für Konvektion + Strahlung
end
function xsol = newton_raphson(func, difft, x0)
x(1) = x0;
maxiter = 500; % maximale Anzahl an Iterationen
Abbr = 10^(-5); % Abbruchkriterium
eps = 0.4; % Emissionsverhältnis
c_s = 5.67*10^(-8); % Strahlungskonstante
c12 = eps * c_s; %
alpha_k = 4; % Wärmeübergangskoeffizient bei ruhender Luft
s1 = 0.250; % Wanddicke der feruerfesten Stein
s2 = 0.015; % Wandddicke der äußeren Stahlwand
lamda1 = 0.35; % Wärmeleitfähigkeit der feuerfesten Stein
lamda2 = 22.7; % Wärmeleitfähigkeit der Stahlwand
Tw_1 = 1200; % Wandtemperatur der feuerfesten Stein
T_l = 10; % temperatur der Umgebungsluft
H = 7; % Höhe
B = 15; % Breite
A = B * H; % Fläche
for i = 1:maxiter
if difft(x(i)) < Abbr % Ünerprüfung, ob die Ableitung von x Null ergibt. Falsches Startwert gewählt. Dadurch ergibt sich eine horizontale Tangente, welche die X-Achse nicht schneidet.Es kann keine weitere Nährungswert für die Nullstelle ausgeliefert weden.
fprintf('Die Ableitung von x ist Null, ein anderes Startwert wählen\n');
return;
end
x(i+1) = x(i) - func(x(i))/difft(x(i)); % Berechung mithilfe von Newton Verfahren (Hier befindet sich die Formel der Newton Verfahren)
abs_error(i+1) = abs((x(i+1)-x(i))/x(i+1))*100;
if abs(x(i+1) - x(i)) < Abbr
fprintf('Das Verfahren hat konvergiert bei x = %.10f\n', x(i+1));
else
fprintf('Iteration Nr: %d, aktuelle Schätzwert x = %.10f, error = %.5f, ', i, x(i+1), abs_error(i+1));
end
end
xsol = x(end); % Oberflächentemperatur der Außenwand
alpha_k; % therefore I get the value 4. But the alpha k value changes after the iteration and is calculated depending on x. I need this value
alpha_k = alpha_k(xsol); % I need this value
alpha_ges = alpha_k + eps *c_s*(xsol^4-(T_l+273.15)^4)/(xsol-(T_l+273.15)) % Wärmeübergangskoeffizient-Gesamt
Q_ges = (1/((s1/lamda1+s2/lamda2)+1/alpha_ges))*A*(Tw_1-T_l) % Wärmestrom-Gesamt
end
Array indices must be positive integers or logical values.
Error in Copy_of_ruhender_Luft_rev1>newton_raphson (line 75)
alpha_k = alpha_k(xsol);
Error in Copy_of_ruhender_Luft_rev1 (line 32)
xsol = newton_raphson(func, difft, x0)
1) Can someone please help me to see the last value for alpha k (xsol) ? I need the alpha value calculated depending on x.
2) I would also like to put this code in a live script. Unfortunately it does not work. I want to keep the code but change some parameters and then put both codes (original and parameter modified ) in one script. can someone please tell me how to do this? Thanks in advance
5 Comments
Torsten
on 27 Jan 2022
The value for xsol is passed to function main after successful Newton iteration.
Why do you want to calculate alpha_k twice : once in newton_raphson and once in main ?
But if this is necessary for some reason, I'd pass the function handle alpha_k to newton_raphson together with func, difft and x0, and remove the line alpha_k = 4 there.
Concerning the live script I have no experience - somebody else might help you in this respect.
Aryo Aryanapour
on 27 Jan 2022
Aryo Aryanapour
on 27 Jan 2022
Torsten
on 27 Jan 2022
The function func has integrated the expression for alpha_k you defined in main as
alpha_k= @(x) ...
The value 4 for alpha_k set in newton_raphson is never used.
If you comment out this line
alpha_k = 4
you'll see that you arrive at the same result for xsol as before.
Aryo Aryanapour
on 27 Jan 2022
Accepted Answer
More Answers (1)
Benjamin Thompson
on 27 Jan 2022
0 votes
See the article "Anonymous Functions" in the MATLAB help. You must pass all parameters to the anonymous function as inputs, so maybe
Ra = @(x,Pr,g,L,betha,T_1,v) Pr*(g*L^3*betha*(x-T_l))/v^2;
Unless you want to declare all the parameters as globals.
Also, do not overwrite your function handle for alpha_k. Try:
alpha_k_output = alpha_k(xsol);
alpha_k will also need all those parameters that Ra needs unless you want them to be global. Try a smaller example to debug how you are using alpha_k and Ra first before trying to use them in the newton_raphson local function.
1 Comment
Aryo Aryanapour
on 27 Jan 2022
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!