0

I want to run Swarm optimization with a function written in the same script.

rng default  % For reproducibility
nvars = 2;
x = particleswarm(fun,nvars)

function val = fun(x)
val=x(1)*exp(x(2));
end

When I run this script the promp windows shows me an error. How could I fix this?

JuanMuñoz
  • 165
  • 2
  • 11

1 Answers1

0

Just at and @ at the begininf of fun ie:

rng default  % For reproducibility
nvars = 2;
x = particleswarm(@fun,nvars)

function val = fun(x)
val=x(1)*exp(x(2));
end
JuanMuñoz
  • 165
  • 2
  • 11