summaryrefslogtreecommitdiff
path: root/code/fminsearch
diff options
context:
space:
mode:
Diffstat (limited to 'code/fminsearch')
-rw-r--r--code/fminsearch/MinOilCost.sce81
-rw-r--r--code/fminsearch/PowellsBadlyScaledFunction.sci48
2 files changed, 129 insertions, 0 deletions
diff --git a/code/fminsearch/MinOilCost.sce b/code/fminsearch/MinOilCost.sce
new file mode 100644
index 0000000..8ba1c94
--- /dev/null
+++ b/code/fminsearch/MinOilCost.sce
@@ -0,0 +1,81 @@
+//Reference: Edgar, Himmelblau and Lasdon,"Optimization of Chemical Processes",2nd Ed,McGraw-Hill Chemical Engineering Series,chapter 6
+
+//The cost of refined oil when shipped via the Malacca Straits to Japan in dollars per kiloliter was given as the linear sum of the crude oil cost, the insurance, customs, freight cost for the oil, loading and unloading cost, sea berth cost, submarine pipe cost, storage cost, tank areacost, refining cost, and freight cost of products. Compute the minimum cost of oil and the optimum tanker size t and refinery size.
+
+//======================================================================
+// 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;
+
+function f = ObjectiveFunction(X)
+ t = X(1); q = X(2);
+ Cc = 12.5; // Crude oil price ($/kL)
+ Ci = 0.5; // insurance cost ($/kL)
+ Cx = 0.9; // customs cost ($/kL)
+ a = 0.2; // anual fixed charges,fraction
+ p = 7000; // land prices ($/square meter)
+ n = 2; // number of ports
+ i = 0.1; // interest rate
+ Term1 = (52.47*q*360);
+ Term2 = (n*t+1.2*q);
+ f = Cc + Ci + Cx + (2.09 *10^4*t^-0.3017)/360 +...
+ (1.064*10^6*a*t^0.4925)/Term1+...
+ (4.242*10^4*a*t^0.7952 + 1.813*i*p*Term2^0.861)/Term1...
+ +(4.25*10^3*a*Term2)/Term1 + (5.042*10^3*q^-0.1899)/360 +...
+ (0.1049*q^0.671)/360;
+endfunction
+
+
+function stop=outfun(x, optimValues, state)
+ subplot(1,2,1)
+ plot(optimValues.iteration,optimValues.fval,'rp');
+ xlabel('Iteration');ylabel('fval')
+
+ subplot(1,2,2)
+ plot(optimValues.iteration,x(1),'b*');
+ plot(optimValues.iteration,x(2),'g*');
+ legend(['Tanker size','Refinery size'])
+ set(gca(),"auto_clear","off")
+ xlabel('Iteration');ylabel('variable values')
+
+ stop = %f
+endfunction
+designParameters = {"Tanker size","Refinery size"}
+X0 = [15000 20000];
+designParameter = {'Tanker size(kL)','Refinery capacity(bbl/day)'};
+intGuess = [designParameter;string(X0)];
+disp(intGuess,"Initial guess given to the solver")
+input('Press enter to proceed: ')
+Parameter.X_Tol = 0;
+Parameter.F_Tol = 0;
+Parameter.maxFE = 1000;
+Parameter.maxIt = 100;
+opt = optimset ("TolX",Parameter.X_Tol,"TolFun",Parameter.F_Tol,"MaxFunEvals",Parameter.maxFE,"MaxIter",Parameter.maxIt,"OutputFcn",outfun);
+
+[x,fval,exitflag,output] = fminsearch(ObjectiveFunction,X0,opt)
+
+clc;
+select exitflag
+case -1
+ mprintf('The maximum number of iterations has been reached \n')
+ mprintf('Function Count: %d ',output.funcCount)
+case 0
+ mprintf('The maximum number of function evaluations has been reached \n')
+ mprintf(' Iteration Count: %d ',output.iterations)
+
+case 1
+ mprintf('The tolerance on the simplex size and function value delta has been reached \n')
+ mprintf('Function Count: %d ',output.funcCount)
+ mprintf('Iteration Count: %d ',output.iterations)
+end
+optSol = [designParameter;string(x)];
+disp(optSol,"The optimum solution obtained")
+disp(fval,"The minimum cost of the oil is")
diff --git a/code/fminsearch/PowellsBadlyScaledFunction.sci b/code/fminsearch/PowellsBadlyScaledFunction.sci
new file mode 100644
index 0000000..531ac2d
--- /dev/null
+++ b/code/fminsearch/PowellsBadlyScaledFunction.sci
@@ -0,0 +1,48 @@
+// This is an example for unconstrained multivariable problem
+// Name of the function : Powell's Badly Scaled function
+// f(x1,x2) = (10000 x1.x2 - 1)^2 + [exp(-x1) + exp(-x2) - 1.0001]^2
+
+// Reference: M.J.D Powell, A hybrid method for non-linear equations, pp.87-114 in numerical methods for non-linear algebraic equations,P.Rabinowitz,Ed.,Gorden and Breach,Newyork,1970
+//=====================================================================
+// 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;
+
+function f = PowellsBadlyScaled(X)
+ f = (10000*X(1)*X(2) -1)^2 + (exp(-X(1)) + exp(-X(2)) - 1.0001)^2;
+endfunction
+
+X0 = [0 0];
+Parameter.X_Tol = 1.e-16;
+Parameter.F_Tol = 1.e-16;
+Parameter.maxFE = 1000;
+Parameter.maxIt = 400;
+mprintf("The values set for the configurable options are as below")
+disp(Parameter);
+input("Press enter to proceed ")
+
+opt = optimset ("TolX",Parameter.X_Tol,"TolFun",Parameter.F_Tol,"MaxFunEvals",Parameter.maxFE,"MaxIter",Parameter.maxIt,"PlotFcns" , optimplotfval);
+
+[x,fval,exitflag,output] = fminsearch(PowellsBadlyScaled,X0,opt)
+
+clc
+select exitflag
+case -1
+ mprintf('The maximum number of iterations has been reached \n')
+case 0
+ mprintf('The maximum number of function evaluations has been reached \n')
+case 1
+ mprintf('The tolerance on the simplex size and function value delta has been reached \n')
+end
+
+disp(x,"The optimal solution is")
+disp(fval,"The optimum value of the objective function is")
+disp(output)