i have been trying to solve 50 nonlinear equations simultaneously
1 view (last 30 days)
Show older comments
this is my function file
function F=my_fin(X)
%parameters
L=1; %length of fin
%W=0.0598; %width og fin
%T=50;
%T_b=100; %base temperature of fin
%T_a=20; %ambient temperature of fin
% k_a=30; %ka is the thermal conductivity at the ambient fluid temperature of the fin
%alpha=0.01; %? is the parameter describing the variation of thermal conductivity 0r temperature coefficient of thermal conductivity
% h=11; %heat transfer coefficient
%t=0.001; %thickness of fin
%P=2*(W+t); %fin perimeter...m(unit)
% A_c=(W*t); %cross-sectional area of the fin
%M=sqrt((h*P*L^2)/(A_c*k_a)); %thermo-geometric fin parameter
M=0.5;
n=50; % no of nodes
dx=(L/(n-1)); %space between nodes
%B=alpha*(T_b-T_a); % B dimensionless parameter describing variation of the thermal conductivity
B=0.2;
X(1)=0;
X(51)=1;
F=zeros(1,50);
R=1;
%X(N)=(T-T_b)/(T_a-T_b);
F(1)=(1+B*(X(R+1)))*(X(R+2)-2*X(R+1)+X(R))+((B/4)*(X(R+2))^2)-((B/2)*(X(R+2)*X(R)))+((B/4)*(X(R))^2)-((M)*(X(R+1))*(dx)^2); %let (X(0))=X(1))=1 which is base temp
for j=1:n-3
%X(j)=(T-T_b)/(T_a-T_b);
F(j+1)=(1+B*(X(j+2)))*(X(j+3)-2*X(j+2)+X(j+1))+((B/4)*(X(j+3))^2)-((B/2)*(X(j+3)*X(j+1)))+((B/4)*X(j+1)^2)-((M)*(X(j+2))*(dx)^2);
end
k=1;
% X(k)=(T-T_b)/(T_a-T_b);
F(50)=(1+B*X(k+50))*(X(k+48)*X(k+50))+(B/2)*(X(k+50)-X(k+49))^2-(M*(2*(dx)^2)*X(k+50)); %X(20)=X(21)=0 insulated boundary
end
this is my fsolve command file
clc
clear all
mata=zeros(1,50);
N=100;
OPTs = optimoptions('fsolve', 'MaxIter', N, 'Display','iter');
fun=@my_fin;
x=fsolve(fun,mata);
[Solution, Fval] = fsolve(fun, mata , OPTs)
plot(x)
and output is
Solver stopped prematurely.
fsolve stopped because it exceeded the iteration limit,
options.MaxIterations = 4.000000e+02.
Norm of First-order Trust-region
Iteration Func-count f(x) step optimality radius
0 51 0.00991687 0.12 1
1 102 0.00781698 0.0172541 0.0707 1
2 153 0.0070298 0.0103857 0.0477 1
3 204 0.00649362 0.0084817 0.0461 1
4 255 0.00606564 0.00754073 0.0329 1
5 306 0.00570042 0.00690803 0.0347 1
6 357 0.00537765 0.00649566 0.0281 1
7 408 0.00508647 0.00612239 0.028 1
8 459 0.00482033 0.00586997 0.0244 1
9 510 0.00457487 0.00559464 0.0234 1
10 561 0.00434705 0.00541385 0.0213 1
11 612 0.00413458 0.00518789 0.0202 1
12 663 0.00393573 0.00504675 0.0189 1
13 714 0.0037491 0.00485059 0.019 1
14 765 0.00357353 0.00473455 0.0168 1
15 816 0.00340806 0.00455874 0.0182 1
16 867 0.00325188 0.00446011 0.016 1
17 918 0.00310427 0.00429948 0.0174 1
18 969 0.0029646 0.00421372 0.0154 1
19 1020 0.00283233 0.00406518 0.0166 1
20 1071 0.00270694 0.00398941 0.0149 1
21 1122 0.00258801 0.00385093 0.0159 1
22 1173 0.00247512 0.0037832 0.0143 1
23 1224 0.00236789 0.00365338 0.0152 1
24 1275 0.002266 0.00359227 0.0138 1
25 1326 0.00216913 0.00347009 0.0145 1
26 1377 0.00207699 0.00341458 0.0132 1
27 1428 0.00198932 0.00329925 0.0138 1
28 1479 0.00190587 0.00324854 0.0127 1
29 1530 0.00182639 0.00313944 0.0132 1
30 1581 0.0017507 0.0030929 0.0122 1
31 1632 0.00167857 0.00298952 0.0126 1
32 1683 0.00160983 0.00294665 0.0116 1
33 1734 0.00154429 0.00284855 0.012 1
34 1785 0.00148179 0.00280892 0.0112 1
35 1836 0.00142217 0.00271574 0.0115 1
36 1887 0.0013653 0.00267902 0.0107 1
37 1938 0.00131103 0.00259042 0.011 1
38 1989 0.00125922 0.0025563 0.0102 1
39 2040 0.00120977 0.00247201 0.0105 1
40 2091 0.00116255 0.00244025 0.0098 1
41 2142 0.00111745 0.00235999 0.01 1
42 2193 0.00107437 0.00233038 0.00938 1
43 2244 0.00103322 0.00225392 0.00958 1
44 2295 0.000993894 0.00222626 0.00898 1
45 2346 0.000956312 0.00215339 0.00916 1
46 2397 0.000920391 0.00212751 0.00859 1
47 2448 0.00088605 0.00205804 0.00875 1
48 2499 0.000853216 0.0020338 0.00822 1
49 2550 0.000821818 0.00196753 0.00836 1
50 2601 0.000791789 0.0019448 0.00787 1
51 2652 0.000763065 0.00188157 0.00799 1
52 2703 0.000735586 0.00186024 0.00753 1
53 2754 0.000709294 0.00179989 0.00764 1
54 2805 0.000684135 0.00177985 0.0072 1
55 2856 0.000660056 0.00172222 0.0073 1
56 2907 0.000637008 0.00170338 0.00689 1
57 2958 0.000614945 0.00164835 0.00697 1
58 3009 0.000593822 0.00163062 0.00659 1
59 3060 0.000573595 0.00157806 0.00667 1
60 3111 0.000554226 0.00156136 0.00631 1
61 3162 0.000535674 0.00151114 0.00637 1
62 3213 0.000517905 0.00149541 0.00603 1
63 3264 0.000500881 0.00144742 0.00609 1
64 3315 0.000484571 0.0014326 0.00577 1
65 3366 0.000468943 0.00138672 0.00582 1
66 3417 0.000453966 0.00137274 0.00552 1
67 3468 0.000439611 0.00132889 0.00556 1
68 3519 0.000425852 0.0013157 0.00528 1
69 3570 0.000412662 0.00127377 0.00532 1
70 3621 0.000400015 0.00126132 0.00505 1
71 3672 0.000387889 0.00122122 0.00508 1
72 3723 0.00037626 0.00120947 0.00483 1
73 3774 0.000365107 0.00117112 0.00486 1
74 3825 0.000354408 0.00116003 0.00462 1
75 3876 0.000344145 0.00112333 0.00464 1
76 3927 0.000334299 0.00111286 0.00442 1
77 3978 0.000324851 0.00107776 0.00444 1
78 4029 0.000315784 0.00106787 0.00423 1
79 4080 0.000307082 0.00103428 0.00424 1
80 4131 0.000298729 0.00102494 0.00404 1
81 4182 0.00029071 0.000992789 0.00406 1
82 4233 0.000283011 0.00098397 0.00386 1
83 4284 0.000275619 0.0009532 0.00388 1
84 4335 0.000268519 0.000944873 0.00369 1
85 4386 0.000261701 0.000915419 0.0037 1
86 4437 0.000255151 0.000907557 0.00353 1
87 4488 0.000248858 0.000879359 0.00354 1
88 4539 0.000242812 0.000871937 0.00338 1
89 4590 0.000237002 0.000844939 0.00338 1
90 4641 0.000231418 0.000837935 0.00323 1
91 4692 0.000226051 0.000812082 0.00323 1
92 4743 0.000220892 0.000805475 0.00309 1
93 4794 0.000215931 0.000780716 0.00309 1
94 4845 0.000211161 0.000774486 0.00295 1
95 4896 0.000206573 0.000750773 0.00295 1
96 4947 0.00020216 0.0007449 0.00282 1
97 4998 0.000197915 0.000722186 0.00282 1
98 5049 0.00019383 0.000716654 0.00269 1
Solver stopped prematurely.
fsolve stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 5.000000e+03.
Solution =
Columns 1 through 10
0 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000
Columns 11 through 20
0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000
Columns 21 through 30
0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0001 0.0000
Columns 31 through 40
0.0001 -0.0001 -0.0001 -0.0004 -0.0004 -0.0006 -0.0001 0.0006 0.0022 0.0038
Columns 41 through 50
0.0054 0.0055 0.0032 -0.0030 -0.0139 -0.0299 -0.0503 -0.0733 -0.0958 -0.1136
Fval =
Columns 1 through 10
0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0000
Columns 11 through 20
0.0000 -0.0000 0.0000 -0.0000 0.0000 -0.0001 0.0001 -0.0001 0.0001 -0.0001
Columns 21 through 30
0.0001 -0.0001 0.0001 -0.0001 0.0002 -0.0002 0.0002 -0.0002 0.0002 -0.0003
Columns 31 through 40
0.0002 -0.0003 0.0003 -0.0001 0.0006 0.0003 0.0008 0.0001 -0.0001 -0.0015
Columns 41 through 50
-0.0023 -0.0040 -0.0046 -0.0051 -0.0042 -0.0025 0.0006 0.0047 0 0.0086
now why my output show me it is not fully solved prematurely stop how i can increase iteration
3 Comments
Answers (2)
Torsten
on 14 Jan 2024
Edited: Torsten
on 14 Jan 2024
Does the approximate solution below look correct ?
Note that you don't set F(49) in your code.
clc
clear all
mata=zeros(1,50);
OPTs = optimoptions('fsolve', 'MaxIterations', 100000, 'MaxFunctionEvaluations',100000);
fun=@my_fin;
[x, Fval,errorflag] = fsolve(fun, mata , OPTs);
errorflag
plot(linspace(0,1,50),x)
function F=my_fin(X)
%parameters
L=1; %length of fin
%W=0.0598; %width og fin
%T=50;
%T_b=100; %base temperature of fin
%T_a=20; %ambient temperature of fin
% k_a=30; %ka is the thermal conductivity at the ambient fluid temperature of the fin
%alpha=0.01; %? is the parameter describing the variation of thermal conductivity 0r temperature coefficient of thermal conductivity
% h=11; %heat transfer coefficient
%t=0.001; %thickness of fin
%P=2*(W+t); %fin perimeter...m(unit)
% A_c=(W*t); %cross-sectional area of the fin
%M=sqrt((h*P*L^2)/(A_c*k_a)); %thermo-geometric fin parameter
M=0.5;
n=50; % no of nodes
dx=(L/(n-1)); %space between nodes
%B=alpha*(T_b-T_a); % B dimensionless parameter describing variation of the thermal conductivity
B=0.2;
X(1)=0;
X(51)=1;
F=zeros(1,50);
R=1;
%X(N)=(T-T_b)/(T_a-T_b);
F(1)=(1+B*(X(R+1)))*(X(R+2)-2*X(R+1)+X(R))+((B/4)*(X(R+2))^2)-((B/2)*(X(R+2)*X(R)))+((B/4)*(X(R))^2)-((M)*(X(R+1))*(dx)^2); %let (X(0))=X(1))=1 which is base temp
for j=1:n-3
%X(j)=(T-T_b)/(T_a-T_b);
F(j+1)=(1+B*(X(j+2)))*(X(j+3)-2*X(j+2)+X(j+1))+((B/4)*(X(j+3))^2)-((B/2)*(X(j+3)*X(j+1)))+((B/4)*X(j+1)^2)-((M)*(X(j+2))*(dx)^2);
end
k=1;
% X(k)=(T-T_b)/(T_a-T_b);
F(50)=(1+B*X(k+50))*(X(k+48)*X(k+50))+(B/2)*(X(k+50)-X(k+49))^2-(M*(2*(dx)^2)*X(k+50)); %X(20)=X(21)=0 insulated boundary
end
2 Comments
Walter Roberson
on 14 Jan 2024
clc
clear all
mata=zeros(1,50);
OPTs = optimoptions('fsolve', 'MaxIterations', 100000000, 'MaxFunctionEvaluations', 100000000);
fun=@my_fin;
[x, Fval,errorflag] = fsolve(fun, mata , OPTs);
errorflag
plot(linspace(0,1,50),x)
function F=my_fin(X)
%parameters
L=1; %length of fin
%W=0.0598; %width og fin
%T=50;
%T_b=100; %base temperature of fin
%T_a=20; %ambient temperature of fin
% k_a=30; %ka is the thermal conductivity at the ambient fluid temperature of the fin
%alpha=0.01; %? is the parameter describing the variation of thermal conductivity 0r temperature coefficient of thermal conductivity
% h=11; %heat transfer coefficient
%t=0.001; %thickness of fin
%P=2*(W+t); %fin perimeter...m(unit)
% A_c=(W*t); %cross-sectional area of the fin
%M=sqrt((h*P*L^2)/(A_c*k_a)); %thermo-geometric fin parameter
M=0.5;
n=50; % no of nodes
dx=(L/(n-1)); %space between nodes
%B=alpha*(T_b-T_a); % B dimensionless parameter describing variation of the thermal conductivity
B=0.2;
X(1)=0;
X(51)=1;
F=zeros(1,50);
R=1;
%X(N)=(T-T_b)/(T_a-T_b);
F(1)=(1+B*(X(R+1)))*(X(R+2)-2*X(R+1)+X(R))+((B/4)*(X(R+2))^2)-((B/2)*(X(R+2)*X(R)))+((B/4)*(X(R))^2)-((M)*(X(R+1))*(dx)^2); %let (X(0))=X(1))=1 which is base temp
for j=1:n-3
%X(j)=(T-T_b)/(T_a-T_b);
F(j+1)=(1+B*(X(j+2)))*(X(j+3)-2*X(j+2)+X(j+1))+((B/4)*(X(j+3))^2)-((B/2)*(X(j+3)*X(j+1)))+((B/4)*X(j+1)^2)-((M)*(X(j+2))*(dx)^2);
end
k=1;
% X(k)=(T-T_b)/(T_a-T_b);
F(50)=(1+B*X(k+50))*(X(k+48)*X(k+50))+(B/2)*(X(k+50)-X(k+49))^2-(M*(2*(dx)^2)*X(k+50)); %X(20)=X(21)=0 insulated boundary
end
Torsten
on 14 Jan 2024
Edited: Torsten
on 14 Jan 2024
epsilon = 0.2;
N = 0.5;
L = 1;
bvpfcn = @(x,y)[y(2);(-epsilon*y(2)^2+N^2*y(1))/(1+epsilon*y(1))];
bcfcn = @(ya,yb)[ya(2);yb(1)-1];
guess = @(x)[0;1];
xmesh = linspace(0,L,100);
solinit = bvpinit(xmesh, guess);
sol = bvp4c(bvpfcn, bcfcn, solinit);
figure(1)
plot(sol.x, sol.y(1,:))
Npts = 50;
x = linspace(0,L,Npts);
dx = x(2)-x(1);
T0 = ones(Npts,1);
T = fsolve(@(x)fun(x,Npts,x,dx,epsilon,N),T0);
figure(2)
plot(x,T)
function res = fun(T,Npts,x,dx,epsilon,N)
res = zeros(size(T));
res(1) = (1+epsilon*T(1))*2*(T(2)-T(1))/dx^2 + epsilon*((T(2)-T(1))/dx)^2 - N^2*T(1);
res(2:Npts-1) = (1+epsilon*T(2:Npts-1)).*(T(3:Npts)-2*T(2:Npts-1)+T(1:Npts-2))/dx^2 + epsilon*((T(3:Npts)-T(1:Npts-2))/(2*dx)).^2 - N^2*T(2:Npts-1);
res(Npts) = T(Npts)-1;
end
0 Comments
See Also
Categories
Find more on Systems of Nonlinear Equations 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!