필터 지우기
필터 지우기

Optimization of a matrix variable

조회 수: 2 (최근 30일)
Soumili Sen
Soumili Sen 2022년 3월 24일
댓글: Soumili Sen 2022년 3월 24일
Hello all,
I am writting a code for optimization where I have a optimizing variable as a matrix of N*L.How I can declare this matrix variables within a function as an objective function?
I am trying like that,
N=2;
L=10;
z = rand(N,L);
r= mainfcn(z,N)
function r= mainfcn(z,N)
a=z(N:L);
r = a.^2- 1;
end
here I am getting 'a'= as a vector not a matrix. How I can make 'a' as a matrix of N*L?
Thanks in advance.

채택된 답변

Jan
Jan 2022년 3월 24일
By:
a = z; % instead of z(N:L)
? This looks trivial, so do I oversee a detail?
  댓글 수: 2
Soumili Sen
Soumili Sen 2022년 3월 24일
Now it's working. Thanks a lot.
Soumili Sen
Soumili Sen 2022년 3월 24일
Hey, sorry for bothering you,
If,
z = rand(3,2);
r= mainfcn(z)
function r= mainfcn(z)
a=z(1:L); ----> want only first row(1*2 vector)
b= z(2:end); -----> want 2nd row and 3rd row(2*2 matrix)
r = a.^2+b.^2- 1;
end
How I can correct this code?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by