0% found this document useful (0 votes)
65 views11 pages

Matlab Code: Question No: 4 (A)

The MATLAB code defines the components of multiple systems of equations and uses fsolve to find the solutions. For each part, it defines the system, provides initial guesses, and outputs the optimized solutions within 3 sentences or less of the key information.

Uploaded by

ihsan yaseen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views11 pages

Matlab Code: Question No: 4 (A)

The MATLAB code defines the components of multiple systems of equations and uses fsolve to find the solutions. For each part, it defines the system, provides initial guesses, and outputs the optimized solutions within 3 sentences or less of the key information.

Uploaded by

ihsan yaseen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

MATLAB Code

Question No: 4 (a)


M-File
% Components are defined as x1= x(1), x2= x(2), v= x(3)
function F=kktsystem(x)
F=[8*x(1)-5*x(2)+x(3);
6*x(2)-5*x(1)+x(3); x(1)+x(2)-4];

Command Window

x0=[1; 1; 1];

x=fsolve(@kktsystem,x0)

Optimization terminated: first-order optimality is less than options.TolFun.

x=

1.8333= x1

2.1667= x2

-3.8333=v
MATLAB Code
Question No: 4 (b)
M-File
% Components are defined as x1= x(1), x2= x(2), u= x(3), s= x(4).
function F=kktsystem(x)
F=[-8*x(1)+5*x(2)+x(3); -6*x(2)+5*x(1)+x(3); x(1)+x(2)-+x(4)^2;
x(3)*x(4)];

Command Window

x0=[1; 1; 1; 1];
x=fsolve(@kktsystem,x0,options)

Norm of First-order Trust-region


Iteration Func-count f(x) step optimality radius
0 5 6 15 1
1 10 1.78583 1 1.64 1
2 15 0.299003 1.26213 1.88 2.5
3 20 0.000755861 0.230928 0.0743 2.5
4 25 8.07169e-009 0.0145175 0.000209 2.5
5 30 9.43088e-019 5.07879e-005 2.04e-009 2.5
Optimization terminated: first-order optimality is less than options.TolFun.

x=
-0.0000 % x1=0
-0.0000 % x2=0
-0.0000 % u=0
2.0000 % s=2
MATLAB Code
Question No: 4 (c)
M-File
% Components are defined as x1= x(1), x2= x(2), u= x(3),v=x(4), s= x(5).
function F=kktsystem(x)
F=[2*x(1)-2+x(4)-x(3); 2*x(2)-2-x(4)-x(3); x(1)-x(2)-2;
-x(1)-x(2)+4+x(5)^2; x(3)*x(5)];

Command Window

x0=[1; 1; 1; 1; 1];
x=fsolve(@kktsystem,x0,options)

Norm of First-order Trust-region


Iteration Func-count f(x) step optimality radius
0 6 18 7 1
1 12 6.8469 1 1.62 1
2 18 1.0395 2.5 0.892 2.5
3 24 0.0880206 1.10067 0.438 6.25
4 30 0.000797499 0.248816 0.0451 6.25
5 36 5.4134e-008 0.0234821 0.000384 6.25
6 42 2.44176e-016 0.000187524 2.52e-008 6.25
Optimization terminated: first-order optimality is less than options.TolFun.

x=
3.0000 % x1=3
1.0000 % x2=1
2.0000 % u=2
-2.0000 % v=-2
-0.0000 % s=0
MATLAB Code
Question No: 4 (d)
M-File
% Components are defined as x1= x(1), x2= x(2), u1= x(3),u2= x(4),u3= x(5),
% u4= x(6),s1= x(7), s2= x(8)
% s3= x(9), s4= x(10).
function F=kktsystem(x)
F=[2-3*x(1)^2+x(3)+5*x(4)-x(5); 3-4*x(2)+3*x(3)+2*x(4)-x(6);
x(1)+3*x(2)-6+x(7)^2; 5*x(1)+2*x(2)-10+x(8)^2; -x(1)+x(9)^2;
-x(2)+x(10)^2; x(3)*x(7); x(4)*x(8); x(5)*x(9);
x(6)*x(10)];

Command Window

x0=[1; 1; 1; 1; 1; 1; 1; 1; 1; 1];
x=fsolve(@kktsystem,x0,options)

Norm of First-order Trust-region


Iteration Func-count f(x) step optimality radius
0 11 34 35 1
1 22 2.34874 1 7.99 1
2 33 1.38511 1.60405 5.96 2.5
3 44 0.0157318 0.521935 0.878 2.5
4 55 0.000111537 0.128481 0.0493 2.5
5 66 1.76914e-009 0.00806946 0.000246 2.5
6 77 5.86725e-019 3.04028e-005 4.32e-009 2.5
Optimization terminated: first-order optimality is less than options.TolFun.

x=
1.3846 % x1= 1.3846
1.5385 % x2= 1.5385
0.6359 % u1= 0.6359
0.6231 % u2= 0.6231
-0.0000 % u3= 0
-0.0000 % u4= 0
0.0000 % s1= 0
0.0000 % s2= 0
1.1767 % s3= 1.1767
1.2403 % s4= 1.2403
MATLAB Code
Question No: 4 (e)
M-File
% Components are defined as x1= x(1), x2= x(2), u1= x(3),u2= x(4),s1= x(5),
% s2= x(6)
function F=kktsystem(x)
F=[2*x(1)-2+x(3)-x(4); 2*x(2)-2+x(3);
x(1)+x(2)-4+x(5)^2; 2-x(1)+x(6)^2; x(3)*x(5);
x(4)*x(6)];

Command Window

x0=[1; 1; 1; 1; 1; 1;];
x=fsolve(@kktsystem,x0,options)

Norm of First-order Trust-region


Iteration Func-count f(x) step optimality radius
0 7 8 5 1
1 14 1.85451 1 2.06 1
2 21 0.210186 1.25844 0.803 2.5
3 28 0.00527746 0.308487 0.0674 2.5
4 35 7.22585e-006 0.144236 0.00489 2.5
5 42 3.2801e-012 0.00163868 1.73e-006 2.5
6 49 2.83186e-024 3.49115e-006 2.56e-012 2.5
Optimization terminated: first-order optimality is less than options.TolFun.

x=
2.0000 % x1= 2
1.0000 % x2= 1
0.0000 % u1= 0
2.0000 % u2= 2
1.0000 % s1= 1
-0.0000 % s2= 0
MATLAB Code
Question No: 4 (f)
M-File
% Components are defined as x1= x(1), x2= x(2), u1= x(3),u2= x(4),u3= x(5),
% u4= x(6),s1= x(7), s2= x(8)
% s3= x(9), s4= x(10).
function F=kktsystem(x)
F=[2*x(1)+320*x(2)+x(3)/(60*x(2))-(x(4)*(2*x(1)-x(2)))/3600-x(5);
320*x(1)-(x(3)*x(1))/(60*x(2)^2)+(x(4)*x(1))/3600-x(6);
x(1)/(60*x(2))-1+x(7)^2; 1-(x(1)*(x(1)-x(2)))/3600+x(8)^2; -x(1)+x(9)^2;
-x(2)+x(10)^2; x(3)*x(7); x(4)*x(8); x(5)*x(9);
x(6)*x(10)];

Command Window

x0=[1; 1; 1; 1; 1; 1; 1; 1; 1; 1];
x=fsolve(@kktsystem,x0,options)

Norm of First-order Trust-region


Iteration Func-count f(x) step optimality radius
0 11 204810 1.03e+005 1
1 22 17313.8 1 2.99e+004 1
2 33 1.25686 1.77634 17.6 2.5
3 44 1.25261 4.44086 11.8 4.44
4 55 1.2513 11.1022 7.71 11.1
5 66 1.25067 11.1022 4.16 11.1
6 77 1.25036 27.7554 4.67 27.8
7 88 1.25012 3.86434e-005 1.81 27.8
8 99 1.25 6.15853e-005 3.04 27.8
9 110 1.24991 2.24145e-005 0.804 27.8
10 121 1.24986 4.47644e-005 2.09 27.8
11 132 1.24983 1.34936e-005 0.375 27.8
12 143 1.2498 3.70258e-005 1.77 27.8
13 154 1.24978 1.04105e-005 0.375 27.8
14 165 1.24976 3.74766e-005 1.85 27.8
15 176 1.24973 1.0347e-005 0.375 27.8
16 187 1.24971 4.21088e-005 1.99 27.8
17 198 1.24969 1.08812e-005 0.375 27.8
18 209 1.24966 4.90174e-005 2.16 27.8
19 220 1.24963 1.16447e-005 0.375 27.8
20 231 1.2496 5.92905e-005 2.4 27.8
21 242 1.24956 1.27103e-005 0.375 27.8
22 253 1.24952 7.67175e-005 2.76 27.8
23 264 1.24947 1.43409e-005 0.375 27.8
24 275 1.24941 0.000114149 3.41 27.8
25 286 1.24935 1.73279e-005 0.375 27.8
26 297 1.2492 0.000259619 5.25 27.8
27 308 1.24905 2.57834e-005 0.374 27.8
28 319 1.24625 0.0043351 15.7 27.8
29 330 1.24425 0.00010922 0.687 27.8
30 341 1.24424 7.31223e-006 0.369 27.8
31 352 1.24423 1.08223e-005 0.71 27.8
32 363 1.24423 7.26614e-006 0.369 27.8
33 374 1.24422 1.10167e-005 0.732 27.8
34 385 1.24421 7.24973e-006 0.369 27.8
35 396 1.2442 1.12438e-005 0.752 27.8
36 407 1.2442 7.25029e-006 0.369 27.8
37 418 1.24419 1.1495e-005 0.771 27.8
38 429 1.24418 7.26162e-006 0.369 27.8
39 440 1.24417 1.17664e-005 0.789 27.8
40 451 1.24417 7.28069e-006 0.369 27.8
41 462 1.24416 1.20571e-005 0.808 27.8
42 473 1.24415 7.306e-006 0.369 27.8
43 484 1.24414 1.23673e-005 0.826 27.8
44 495 1.24414 7.33686e-006 0.369 27.8
45 506 1.24413 1.26978e-005 0.845 27.8
46 517 1.24412 7.37296e-006 0.369 27.8
47 528 1.24411 1.30502e-005 0.864 27.8
48 539 1.2441 7.41425e-006 0.369 27.8
49 550 1.24409 1.34263e-005 0.884 27.8
50 561 1.24409 7.46082e-006 0.369 27.8
51 572 1.24408 1.38284e-005 0.904 27.8
52 583 1.24407 7.51286e-006 0.368 27.8
53 594 1.24406 1.42591e-005 0.926 27.8
54 605 1.24405 7.57064e-006 0.368 27.8
55 616 1.24404 1.47214e-005 0.948 27.8
56 627 1.24403 7.63453e-006 0.368 27.8
57 638 1.24402 1.5219e-005 0.971 27.8
58 649 1.24401 7.70497e-006 0.368 27.8
59 660 1.244 1.5756e-005 0.996 27.8
60 671 1.24399 7.78248e-006 0.368 27.8
61 682 1.24398 1.63376e-005 1.02 27.8
62 693 1.24397 7.86768e-006 0.368 27.8
63 704 1.24396 1.69695e-005 1.05 27.8
64 715 1.24395 7.96133e-006 0.368 27.8
65 726 1.24394 1.76588e-005 1.08 27.8
66 737 1.24393 8.06432e-006 0.368 27.8
67 748 1.24392 1.84141e-005 1.11 27.8
68 759 1.24391 8.17772e-006 0.368 27.8
69 770 1.2439 1.92459e-005 1.14 27.8
70 781 1.24389 8.3028e-006 0.368 27.8
71 792 1.24388 2.01668e-005 1.18 27.8
72 803 1.24386 8.44115e-006 0.368 27.8
73 814 1.24385 2.11932e-005 1.21 27.8
74 825 1.24384 8.59469e-006 0.368 27.8
75 836 1.24383 2.23452e-005 1.26 27.8
76 847 1.24381 8.76582e-006 0.368 27.8
77 858 1.2438 2.36492e-005 1.3 27.8
78 869 1.24378 8.95758e-006 0.368 27.8
79 880 1.24377 2.51396e-005 1.35 27.8
80 891 1.24376 9.17386e-006 0.368 27.8
81 902 1.24374 2.68628e-005 1.41 27.8
82 913 1.24372 9.41979e-006 0.368 27.8
83 924 1.24371 2.88825e-005 1.47 27.8
84 935 1.24369 9.70218e-006 0.368 27.8
85 946 1.24367 3.12894e-005 1.54 27.8
86 957 1.24365 1.00305e-005 0.368 27.8
87 968 1.24363 3.42169e-005 1.62 27.8
88 979 1.24362 1.04181e-005 0.368 27.8
89 990 1.24359 3.7871e-005 1.72 27.8
90 1001 1.24357 1.08848e-005 0.368 27.8
Maximum number of function evaluations reached:
increase options.MaxFunEvals.

x=

0.0022
0.0012
0.0079
55.4006
0.4990
0.4991
0.9914
0.0000
0.4971
0.4969
MATLAB Code
Question No: 3 (a)
M-File
% Components are defined as x1= x(1), x2= x(2), v= x(3)
function F=kktsystem(x)
F=[8*x(1)-5*x(2)-8+x(3);
6*x(2)-5*x(1)+x(3); x(1)+x(2)-4];

Command Window

x0=[1; 1; 1];
x=fsolve(@kktsystem,x0)
Optimization terminated: first-order optimality is less than options.TolFun.

x=

2.1667= x1
1.8333= x2
-0.1667= v
MATLAB Code
Question No: 3 (b)
M-File
% Components are defined as x1= x(1), x2= x(2), v= x(3)
function F=kktsystem(x)
F=[2*x(1)-4+2*x(3);
2*x(2)+2+3*x(3); 2*x(1)+3*x(2)-4];

Command Window

x0=[1; 1; 1];
x=fsolve(@kktsystem,x0)
Optimization terminated: first-order optimality is less than options.TolFun.

x=

2.4615= x1
-0.3077= x2
-0.4615= v
MATLAB Code
Question No: 3 (c)
M-File
% Components are defined as x1= x(1), x2= x(2), x3=x(3) v1= x(4), v2=x(5)
function F=kktsystem(x)
F=[2*x(1)-2+2*x(4)+x(5);
2*x(2)+4+3*x(4)+x(5);
2*x(3)-4+2*x(5);
2*x(1)+3*x(2)-1;
x(1)+x(2)+2*x(3)-4];

Command Window

x0=[1; 1; 1; 1; 1];
x=fsolve(@kktsystem,x0)
Optimization terminated: first-order optimality is less than options.TolFun.

x=

1.7170= x1
-0.8113= x2
1.5472= x3
-0.9434= v1
0.4528= v2

You might also like