diff options
Diffstat (limited to 'code/fminunc')
-rw-r--r-- | code/fminunc/SStemperature.sce | 53 | ||||
-rw-r--r-- | code/fminunc/ThreeHump-backCamel.sci | 69 |
2 files changed, 122 insertions, 0 deletions
diff --git a/code/fminunc/SStemperature.sce b/code/fminunc/SStemperature.sce new file mode 100644 index 0000000..cdbd08d --- /dev/null +++ b/code/fminunc/SStemperature.sce @@ -0,0 +1,53 @@ +//Reference: S.S. Rao,Engineering Optimization Theory and Practice, 3rd enlarged edition, New age international publishers,2011,chapter 6 +// The steady state temperature (t1 and t2) at two points (mid point and the free end) of the one dimensional fin correspond to the minimum of the function. +// f(t1,t2) = 0.6382*t(1)^2 + 0.3191*t(2)^2 - 0.2809*t(1)*t(2) - 67.906*t(1) - 14.29*t(2) +//===================================================================== +// Copyright (C) 2018 - IIT Bombay - FOSSEE +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Author: Remya Kommadath +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in +//===================================================================== + +clc; +// Objective function +function f = ObjectiveFunction(t) + f = 0.6382*t(1)^2 + 0.3191*t(2)^2 - 0.2809*t(1)*t(2) - 67.906*t(1) - 14.29*t(2); +endfunction +// Initial guess +x0 = [100 200]; +disp(x0, "Initial guess given to the solver is ") +input("Press enter to proceed: ") +[xopt,fopt,exitflag,output,gradient,hessian] = fminunc(ObjectiveFunction,x0) +// Result representation +clc +select exitflag +case 0 + disp("Optimal Solution Found") + disp(xopt', "The steady state temperature at the points are") + disp(fopt, "The optimum objective function value is") +case 1 + disp("Maximum Number of Iterations Exceeded. Output may not be optimal.") + disp(xopt', "The temperature at the points are") + disp(fopt, "The objective function value is") +case 2 + disp("Maximum CPU Time exceeded. Output may not be optimal.") + disp(xopt', "The temperature at the points are") + disp(fopt, "The objective function value is") +case 3 + disp("Stop at Tiny Step.") + disp(xopt', "The temperature at the points are") + disp(fopt, "The objective function value is") +case 4 + disp("Solved To Acceptable Level.") + disp(xopt', "The temperature at the points are") + disp(fopt, "The objective function value is") +case 5 + disp("Converged to a point of local infeasibility.") +end + +disp(output) diff --git a/code/fminunc/ThreeHump-backCamel.sci b/code/fminunc/ThreeHump-backCamel.sci new file mode 100644 index 0000000..f1f2b38 --- /dev/null +++ b/code/fminunc/ThreeHump-backCamel.sci @@ -0,0 +1,69 @@ +// Reference: Urmila Diwekar, "Introduction to Aplied Optimization", 2nd Ed, Springer Science + Business Media,2008, Chapter 3 + +// Three hump-back camel function : An unconstrained problem +// F(X) = 2*X(1)^2 - 1.05*X(1)^4 + (1/6)*X(1)^6 + X(1)*X(2) + X(2)^2 +// Dimension of the problem: 2 +// The global optima for the function: F*(X) = 0 and X* = [0 0]; +//===================================================================== +// Copyright (C) 2018 - IIT Bombay - FOSSEE +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Author: Remya Kommadath +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in +//===================================================================== + +clc; +// Objective function +function f = ObjectiveFunction(X) + f = 2*X(1)^2 - 1.05*X(1)^4 + (1/6)*X(1)^6 + X(1)*X(2) + X(2)^2; +endfunction +// Gradient of the function +function gf = GradientFunction(X) + gf = [4*X(1) - 4.2*X(1)^3 + X(1)^5 + X(2), X(1) + 2*X(2)]; +endfunction +// Hessian matrix of the function +function hf = HessianFunction(X) + hf = [4 - 12.6*X(1)^2 + 5*X(1)^4, 1; 1 2] +endfunction + +// Initial guess +x0 = [0,-1]; +disp(x0, "The initial guess given to the solver is") +input("Press enter to proceed: ") +// User specified parameter values +options=list("gradobj", GradientFunction,"hessian",HessianFunction); +// Calling the solver +[xopt,fopt,exitflag,output,gradient,hessian] = fminunc(ObjectiveFunction,x0,options) + +// Result representation +clc +select exitflag +case 0 + disp("Optimal Solution Found") + disp(xopt', "The optimum solution obtained is") + disp(fopt, "The optimum objective function value is") +case 1 + disp("Maximum Number of Iterations Exceeded. Output may not be optimal.") + disp(xopt', "The solution obtained is") + disp(fopt, "The objective function value is") +case 2 + disp("Maximum CPU Time exceeded. Output may not be optimal.") + disp(xopt', "The solution obtained is") + disp(fopt, "The objective function value is") +case 3 + disp("Stop at Tiny Step.") + disp(xopt', "The solution obtained is") + disp(fopt, "The objective function value is") +case 4 + disp("Solved To Acceptable Level.") + disp(xopt', "The solution obtained is") + disp(fopt, "The objective function value is") +case 5 + disp("Converged to a point of local infeasibility.") +end + +disp(output) |