From 6defe4294857d38017322261026bdcc49c82c4c8 Mon Sep 17 00:00:00 2001 From: lelavaho <51997984+lelavaho@users.noreply.github.com> Date: Thu, 5 Sep 2019 03:30:46 +0400 Subject: [PATCH] Update NewFunctionTemplate.m --- Functions/NewFunctionTemplate.m | 49 ++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/Functions/NewFunctionTemplate.m b/Functions/NewFunctionTemplate.m index 328365b..7d2e6e0 100644 --- a/Functions/NewFunctionTemplate.m +++ b/Functions/NewFunctionTemplate.m @@ -1,30 +1,41 @@ -function [ outVal, outGr, outHes ] = NewFunctionTemplate( x, VGH ) + function [ outVal, outGr, outHes ] = POWER(x0, VGH ) % ================================================================ % Template for adding new multidimensional function to Vilin. % To add new function modify this file and save to 'Functions/MultiDimensional/'. % To add starting point for new function check 'Util/StartingPointGenerator.m'. % ================================================================ - n = length(x); - outVal = 0; - outGr = 0; - outHes = 0; + n = length(x0); + + outVal = 0; - if VGH(1) == 1 - % compute function value, replace line below with actual code - throw (MException('NumOpt:implementationError', 'Computing value for %s not implemented.', mfilename)); - end + outHes = zeros(n,n); + if VGH(1) > 0 - if VGH(2) == 1 - outGr = zeros(n, 1); - % compute gradient, replace line below with actual code - throw (MException('NumOpt:implementationError', 'Computing gradient for %s not implemented.', mfilename)); - end + for i=1:n - if VGH(3) == 1 - outHes = zeros(n, n); - % compute hessian, replace line below with actual code - throw (MException('NumOpt:implementationError', 'Computing hessian for %s not implemented.', mfilename)); + outVal = outVal + (x0(i)*i)^2; + end + end -end + if VGH(2) > 0 + + for i=1:n + outGr = zeros(n,1); + outGr(i) = outGr(i) + 2*x0(i)*i; + end + end + + if VGH(3) > 0 + + for i=1:n + + outHes = outHes + 2*i; + + end + else + + outHes = 0; + + end