Clear Filters
Clear Filters

The code below runs nonstop, and the results are not shown. why is that?

35 views (last 30 days)
syms J1 J5 J6 J7 Jm T1 T2 T3 T4 T5 T6 Tm
%Jm = 1000; %5077.12;
Js = 301.32;
Je = 7;%330.136;
A2 = 449200;
A4 = 519000;
Fms = 0.305;
Fm1 = 0.45;
Fme = 0.245;
F1s = 0.610;
F1m = 0.389;
eps = 0.85;
Te = 215;
K1 = 60; %solar cell
L1 = 0.2e-3; %solar cell
R1 = 0.6e-4;
K2 = 15; %solar panel
L2 = 0.03; %solar panel
F5e = 0.1;
F5s = 0.03;
Fem = 0.1;
Fe5 = 0.01;
S0 = -Jm + eps*5.67e-8*Tm^4 + ((1-eps)*5*1360);
S1 = -(5.67e-8*Tm^4 - Jm)*(A2*eps)/(1-eps) + (Jm - Js)*(A2*Fms) + (Jm - J1)*(A2*Fm1) + (Jm - Je)*(A2*Fme);%J1
S2 = -(5.67e-8*T1^4 - J1)*(A4*eps)/(1-eps) + (J1 - Js)*(A4*F1s) + (J1 - Jm)*(A4*F1m);%T1
S3 = -(5.67e-8*T1^4 - J1)*(A4*eps)/(1-eps) + (T1-T2)*K1*A4/L1;%T2
S4 = -(T1 - T2)*K1/L1 + (T2-T3)/R1;
S5 = -(T2-T3)/R1 + (T3-T4)/L2*K2;
S6 = -(T3 - T4)/L2*K2 + (5.67e-8*T4^4 - J6)*A4*eps/(1-eps);
S7 = -(5.67e-8*T4^4 - J6)*eps/(1-eps) + (J6 - J7);
S8 = -(J6-J7) + (5.67e-8*T5^4 - J7)*eps/(1-eps) - 185.95;
S9 = -(5.67e-8*T5^4 - J7)*eps/(1-eps) + (T5 - T6)*K2/L2;
S10 = -(5.67e-8*T6^4 - J5)*eps/(1-eps) + (J5 - Je)*F5e + (J5 - J1)*F5s;
S11 = -(5.67e-8*Te^4 - Je)*eps/(1-eps) + (Je - Jm)*Fem + (Je- J5)*Fe5;
S = [S0,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11];
vars = [J1, J5, J6, J7, Jm, T1, T2, T3, T4, T5, T6, Tm];
sol = solve(S, vars);
T1_val = real(double(sol.T1(1)))
T2_val = real(double(sol.T2(1)))
T3_val = real(double(sol.T3(1)))
T4_val = real(double(sol.T4(1)))
T5_val = real(double(sol.T5(1)))
T6_val = real(double(sol.T6(1)))

Answers (1)

Torsten
Torsten on 26 May 2024 at 22:41
Edited: Torsten on 26 May 2024 at 22:54
The code below runs nonstop, and the results are not shown. why is that?
"solve" won't succeed for your system of equations because it is too complicated. Try the numerical solver "fsolve" instead. I hope you know better initial guesses for the solution variables than just random values.
x0 = rand(12,1);
options = optimset('MaxIter',300000,'MaxFunEvals',300000);
x = fsolve(@(x)fun(x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),x(12)),x0,options)
Solver stopped prematurely. fsolve stopped because it exceeded the function evaluation limit, options.MaxFunctionEvaluations = 3.000000e+05.
x = 12x1
3.9894 0.0280 0.7814 0.3784 1.2731 0.0304 0.0305 0.0546 -0.0699 8.1945
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
function res = fun(J1,J5, J6, J7, Jm, T1, T2, T3, T4, T5, T6, Tm)
%Jm = 1000; %5077.12;
Js = 301.32;
Je = 7;%330.136;
A2 = 449200;
A4 = 519000;
Fms = 0.305;
Fm1 = 0.45;
Fme = 0.245;
F1s = 0.610;
F1m = 0.389;
eps = 0.85;
Te = 215;
K1 = 60; %solar cell
L1 = 0.2e-3; %solar cell
R1 = 0.6e-4;
K2 = 15; %solar panel
L2 = 0.03; %solar panel
F5e = 0.1;
F5s = 0.03;
Fem = 0.1;
Fe5 = 0.01;
S0 = -Jm + eps*5.67e-8*Tm^4 + ((1-eps)*5*1360);
S1 = -(5.67e-8*Tm^4 - Jm)*(A2*eps)/(1-eps) + (Jm - Js)*(A2*Fms) + (Jm - J1)*(A2*Fm1) + (Jm - Je)*(A2*Fme);%J1
S2 = -(5.67e-8*T1^4 - J1)*(A4*eps)/(1-eps) + (J1 - Js)*(A4*F1s) + (J1 - Jm)*(A4*F1m);%T1
S3 = -(5.67e-8*T1^4 - J1)*(A4*eps)/(1-eps) + (T1-T2)*K1*A4/L1;%T2
S4 = -(T1 - T2)*K1/L1 + (T2-T3)/R1;
S5 = -(T2-T3)/R1 + (T3-T4)/L2*K2;
S6 = -(T3 - T4)/L2*K2 + (5.67e-8*T4^4 - J6)*A4*eps/(1-eps);
S7 = -(5.67e-8*T4^4 - J6)*eps/(1-eps) + (J6 - J7);
S8 = -(J6-J7) + (5.67e-8*T5^4 - J7)*eps/(1-eps) - 185.95;
S9 = -(5.67e-8*T5^4 - J7)*eps/(1-eps) + (T5 - T6)*K2/L2;
S10 = -(5.67e-8*T6^4 - J5)*eps/(1-eps) + (J5 - Je)*F5e + (J5 - J1)*F5s;
S11 = -(5.67e-8*Te^4 - Je)*eps/(1-eps) + (Je - Jm)*Fem + (Je- J5)*Fe5;
res = [S0;S1;S2;S3;S4;S5;S6;S7;S8;S9;S10;S11];
end
  4 Comments
Ghanim
Ghanim on 29 May 2024 at 22:52
I found some errors with the equations and the modifed code is below. A new error appears as follow:
"Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems; using Levenberg-Marquardt algorithm instead. > In fsolve (line 348)
In SS2 (line 50)
No solution found.
fsolve stopped because the problem appears regular as measured by the gradient,
but the vector of function values is not near zero as measured by the
value of the function tolerance.
<stopping criteria details>
fsolve stopped because the sum of squared function values, r, has gradient with relative
norm 8.408653e-13; this is less than 1e-4*options.OptimalityTolerance = 1.000000e-10.
However, r = 1.335682e+06, exceeds sqrt(options.FunctionTolerance) = 1.000000e-03."
% Define the function representing the system of equations
Js = 301.32;
Je = 7;%330.136;
A2 = 449200;
A4 = 519000;
Fms = 0.305;
Fm1 = 0.45;
Fme = 0.245;
F1s = 0.610;
F1m = 0.389;
eps = 0.85;
Te = 215;
K1 = 60; %solar cell
L1 = 0.2e-3; %solar cell
R1 = 0.6e-4;
K2 = 15; %solar panel
L2 = 0.03; %solar panel
F5e = 0.1;
F5s = 0.03;
Fem = 0.1;
Fe5 = 0.01;
fun = @(x) [
-x(1) + eps*5.67e-8*x(2)^4 + ((1-eps)*5*1360);
-(5.67e-8*x(2)^4 - x(1))*eps/(1-eps) + (x(1) - Js)*Fms + (x(3) - x(1))*F1m + (x(1) - Je)*Fme;
-(x(3) - 5.67e-8*x(4)^4)*eps/(1-eps) + (x(3) - Js)*F1s + (x(3) - x(1))*F1m;
-(x(3) - 5.67e-8*x(4)^4)*eps/(1-eps) + (x(4)-x(5))*K1/L1;
-(x(4) - x(5))*K1/L1 + (x(5)-x(6))/R1;
-(x(5) - x(6))/R1 + (x(6)-x(7))/L2*K2;
-(x(6) - x(7))/L2*K2 + (5.67e-8*x(7)^4 - x(8))*eps/(1-eps);
-(5.67e-8*x(7)^4 - x(8))*eps/(1-eps) + (x(8) - x(9));
-(x(8)-x(9)) + (5.67e-8*x(10)^4 - x(9))*eps/(1-eps) - 185.95;
-(5.67e-8*x(10)^4 - x(9))*eps/(1-eps) + (x(10) - x(11))*K2/L2;
-(x(10) - x(11))*K2/L2 + (5.67e-8*x(11)^4 - x(12))*eps/(1-eps);
-(5.67e-8*x(11)^4 - x(12))*eps/(1-eps) + (x(12) - Je)*F5e + (x(12) - x(3))*F5s;
-(5.67e-8*Te^4 - Je)*eps/(1-eps) + (Je - x(1))*Fem + (Je- x(12))*Fe5;
];
% Initial guess for the solution
x0 = [4000; 400; 4000; 450; 450; 420; 400; 4000; 4000; 400; 390; 4000];
options.StepTolerance = 1e-15;
%options = optimset('MaxIter',40000,'MaxFunEvals',40000);
%options = optimoptions('fsolve','Display','iter');
% Solve the system of equations
x = fsolve(fun, x0, options);
Torsten
Torsten on 29 May 2024 at 23:30
You specify 13 equations for 12 unknowns. Usually, such a system is unsolvable and only permits as least-squares solution.

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!