Help needed with finding good convergence values for X1, to X7

2 Ansichten (letzte 30 Tage)
Cody Crouse
Cody Crouse am 15 Mär. 2024
Beantwortet: Kartik Saxena am 22 Mär. 2024
clear all
clc
%Initial Guesses
X1 = 25; %p in kPa
X2 = 40; %w in kg/s
X3 = 20; %E_c in kW
X4 = 60; %t_3 in Celcius
X5 = 30; %E_t in kW
X6 = 65; %t_2 in Celcius
X7 = 10; %E_s in kW
%Solution Vector
X = [X1; X2; X3; X4; X5; X6; X7];
%Jacobian Matrix Initialization
J = zeros(7,7);
%RHS Vector Initialization
F = zeros(7,1);
%First Iteration in the Iteration Process
J = JMat(J,X1,X2,X3,X4,X5,X6,X7);
F = RHS(F,X1,X2,X3,X4,X5,X6,X7);
%Tolerance counter of Initial
I = 0;
%Tolerance
T = 10^(-4); %Larger to Save Time on Processing of Program.
%Error
E = 10^2; %Smaller to decrease time to get final iteration result.
%Additional Iterations
while (E > T)
X_Prev = X;
%Computation of Equation
X = X - (F'/J');
%Incremental Increase of Interations
I = I + 1;
%Solutions Get Updated with Each Iteration
X1 = X(1); X2 = X(2); X3 = X(3); X4 = X(4); X5 = X(5); X6 = X(6); X7 = X(7);
%New Jacobian Matrix with each Iteration
J = JMat(J,X1,X2,X3,X4,X5,X6,X7);
%New RHS Vector with each Iteration
F = RHS(F,X1,X2,X3,X4,X5,X6,X7);
X_New = X;
%Determination of Error
E = find_E(X_Prev, X_New);
end
%Jacobian Matrix Computation
function J = JMat(J,X1,X2,X3,X4,X5,X6,X7)
J(1,1) = 1;
J(1,2) = -20.5 + 5.6*X2;
J(1,3) = 0;
J(1,4) = 0;
J(1,5) = 0;
J(1,6) = 0;
J(1,7) = 0;
J(2,1) = .2 - .004*X1 + 103*X1*exp(-abs(103*X1))/abs(X1);
J(2,2) = 0;
J(2,3) = 1;
J(2,4) = 0;
J(2,5) = 0;
J(2,6) = 0;
J(2,7) = 0;
J(3,1) = -.02332 - .96e-4*X1 -.000121*X4 + .5472e-5*X1*X4 + .1137e-6*X2^(2) - .4248*1.995e-08*X1*X4^(2);
J(3,2) = 1;
J(3,3) = .02644 - .3698e-4 -.000121 + .2736e-4*X1^(2) + .2274*X1*X4 - 4248*1.995e-08*X1^(2)*X4;
J(3,4) = 0;
J(3,5) = 0;
J(3,6) = 0;
J(3,7) = 0;
J(4,1) = 10.06 - .066066*X1 -.050921*X4 + 1.705e-4*X1*X4 + .2356e-4*X4^(2) - .8946*3.162e-06*X1*X4^(2);
J(4,2) = 0;
J(4,3) = 0;
J(4,4) = -7.4709 -.0078388*X4 - 0.050921*X1 + .8525E-4*X1^(2) + .4712e-4*X1*X4 - .8946*3.162e-06*X1*X4^(2);
J(4,5) = 1;
J(4,6) = 0;
J(4,7) = 0;
J(5,1) = 0;
J(5,2) = 1.03*25 - 1.03*X6;
J(5,3) = 1;
J(5,4) = 0;
J(5,5) = 0;
J(5,6) = - X2*1.03;
J(5,7) = 0;
J(6,1) = 0;
J(6,2) = -X6*1.03;
J(6,3) = 0;
J(6,4) = X6*1.03;
J(6,5) = 0;
J(6,1) = X4*1.03 - X2*1.03;
J(6,7) = 0;
J(7,1) = 0;
J(7,2) = 0;
J(7,3) = -1;
J(7,4) = 0;
J(7,5) = 1;
J(7,6) = 0;
J(7,7) = -1;
end
%Computation of RHS Vector
function F = RHS(F,X1,X2,X3,X4,X5,X6,X7)
F(1) = X1 - 279 - 20.5*X2 + 2.8*X2^(2);
F(2) = X3 - 999 + .2*X1 - .002*X1^(2) - 1.5e-8 - exp(-abs(103*X1));
F(3) = X2 - 9.22 - .2342*X1 - .48e-4*X1^(2) + .02644*X4 - .1849e-4*X4^(2) - .000121*X1*X4 + .2736e-4*X1^(2)*X4 + .1137e-6*X1*X4^(2) - .2124*1.995e-08*(X1*X4)^2;
F(4) = X5 - 1693.2 + 10.06*X1 - .033033*X1^(2) - 7.4709*X4 - .003919*X4^(2) - .050921*X1*X4 + .8525e-4*X1^(2)*X4 + .2356e-4*X1*X4^(2) - .4473*3.162e-06*(X1*X4)^2;
F(5) = X3 - X2*1.03 + X2*1.03*25;
F(6) = 6500 -X6*X2*1.03 + X6*1.03*X4;
F(7) = X5 - X3 - X7;
end
function E = find_E(X_Prev, X_New)
termA = (X_New - X_Prev).^2;
termA = sum(termA(:))^0.5;
termB = X_New.^2;
termB = sum(termB(:))^0.5;
E = termA/termB;
end

Antworten (1)

Kartik Saxena
Kartik Saxena am 22 Mär. 2024
Hi,
To find good convergence values for 'X1' to 'X7', you can try adjusting the initial guesses and the convergence tolerance. You can also experiment with different iterative methods or optimization algorithms to improve convergence.
Here are a few suggestions to improve convergence:
  1. Adjust the initial guesses: Try different values for 'X1' to 'X7' to see if it helps the convergence. Sometimes, starting with values closer to the actual solution can improve convergence.
  2. Modify the convergence tolerance: The convergence tolerance 'T' is currently set to 10^(-4). You can try making it smaller to increase the accuracy of the solution. However, keep in mind that a smaller tolerance may require more iterations to converge.
  3. Try different iterative methods: The code currently uses a simple iterative method to update the solution. You can explore other iterative methods.
I hope it helps.

Kategorien

Mehr zu Fluid Dynamics 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!

Translated by