필터 지우기
필터 지우기

optimizing vector variables with N vector

조회 수: 1 (최근 30일)
Soumili Sen
Soumili Sen 2021년 3월 22일
댓글: Mathieu NOE 2021년 3월 25일
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.

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 3월 23일
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
Soumili Sen
Soumili Sen 2021년 3월 25일
Thanks. Now the code is showing perfect result.
Mathieu NOE
Mathieu NOE 2021년 3월 25일
you're welcome !

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by