How to update a symmetric matrix?
이전 댓글 표시
I want to update a symmetric matrix values using Particle Swarm Optimization, I mean the final updated matrix should be kept symmertic and maintaind the zero values as it is without changing it?
This is the matrix that I want to update without changing the zero values and keep it symmetric:
M= [1 0 1 1 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0 0 0
1 1 1 1 1 1 0 0 0 0 0 0
1 1 1 1 1 1 0 0 0 0 0 0
0 0 1 1 1 1 1 1 0 0 0 0
0 0 1 1 1 1 1 1 0 0 0 0
0 0 0 0 1 1 1 0 1 1 0 0
0 0 0 0 1 1 0 1 1 1 0 0
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1]
And this is the part of the code that I can put the constraints on the updating values on variable min and variable max, the range I want from 1 to 100,
% Project Code: YPEA102
% Project Title: Implementation of Particle Swarm Optimization in MATLAB
% Publisher: Yarpiz (www.yarpiz.com)
% Developer: S. Mostapha Kalami Heris (Member of Yarpiz Team)
% Contact Info: sm.kalami@gmail.com, info@yarpiz.com
function [x,err,B1]=pso(CostFunction)
% CostFunction= Cost Function
% nVar= Number of Decision Variables
B1=[];
nVar = 12;
VarSize=[nVar 12]; % Size of Decision Variables Matrix
VarMin= 1; % Lower Bound of Variables
VarMax= 100; % Upper Bound of Variables
댓글 수: 9
James Tursa
2023년 5월 2일
We need more detail. I don't see M anywhere in your code. Do you have current code that is making M not symmetric? Then show us what this is.
M
2023년 5월 2일
Torsten
2023년 5월 2일
I don't know exactly what you intend to do. I thought you get an input matrix M and want to return a randomly modified symmetric matrix as described above.
So generate a matrix of zeros of the same size as M, put random integers between VarMin and VarMax at the nonzero locations on and below the main diagonal and use this link
to copy the lower part of the matrix to the upper part.
M
2023년 5월 2일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Particle Swarm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!