I am writing a Schwefel function with three variables x1
, x2
and x3
with x (-400,400), I am trying to find the global minimum of a Schwefel function. Can anybody tell me what's wrong with the function code.
function output = objective_function(in)
x1 = in(1);
x2 = in(2);
x3 = in(3);
output=(-x1.*sin(sqrt(mod(x1)))+(-x2.*sin(sqrt(mod(x2)))+(-x3.*sin(sqrt(mod(x3)));
ouput=[F1 F2];
Current Problems:
1: Mismatched delimiters in line:
2: Modulus requires a second argument. The second argument inputted into the
mod()
function needs to be the divisor. The modulus can only return the remainder if it knows the number being divided (dividend) and the number that is dividing (divisor). Calling themod()
function can follow the form:Aside:
mod()
is often used accidentally in replace ofabs()
Modulus →
mod()
: Returns the remainder after division.Example:
mod(10,3) = 1
→ 10/3 = 3 with remainder 1Absolute →
abs()
: Returns the absolute/magnitude of the number.Example:
abs(-10) = 10
orabs(1 + 1i) = 1.4142
3: Variables
F1
andF2
are not defined or initialized before being used. The variable calledouput
may be a typo.Playground Script:
Not sure what the function is supposed to exactly do but here is a script that you can modify to meet your needs. This gets rid of the errors but might need to be reconfigured to suit your exact functionality and output equation.
Ran using MATLAB R2019b