Borrar filtros
Borrar filtros

optimizing vector variables with N vector

1 visualización (últimos 30 días)
Soumili Sen
Soumili Sen el 22 de Mzo. de 2021
Comentada: Mathieu NOE el 25 de Mzo. de 2021
Hello all,
I am writting a code for optimization where I have two optimizing vector variables with N vector like a(1,N) and b(1,N).How I can declare these variables within a function for objective function?
I am trying like that, but it's not getting the ans.
N=10;
function r= mainfcn(z,N)
a=z(1,N);
b=z(N+1,2*N);
r = a.^2 + b.^2 - 1;
end
Thanks in advance.

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 23 de Mzo. de 2021
hello
I suspect this is the intention (corrected code) :
N=10;
z = rand(1,2*N); % dummy data (length must be >= 2N
r= mainfcn(z,N)
function r= mainfcn(z,N)
a=z(1:N); % here (1:N) and not (1,N)
b=z(N+1:2*N); % same fix
r = a.^2 + b.^2 - 1;
end
  2 comentarios
Soumili Sen
Soumili Sen el 25 de Mzo. de 2021
Thanks. Now the code is showing perfect result.
Mathieu NOE
Mathieu NOE el 25 de Mzo. de 2021
you're welcome !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Problem-Based Optimization Setup en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by