Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the utility functions in matlab

Shulou Source: shulou.com Published: 2022-06-01 08:12:37 09月26日 Update

This article will explain in detail what are the tool functions in matlab. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Function D=Distanse (a)%% calculate the distance between two cities, input a location coordinates of each city, output D the distance between two cities row=size (ascore 1); D=zeros (row,row); for i=1:rowfor j=i+1:rowD (iMague j) = ((a (iMagazine 1)-a (jjcent 1)) ^ 2 + (a (iMagol 2)-a (jjcent 2)) ^ 2) ^ 0.5 position D (jjinger I) = D (endend j);

Function DrawPath (Chrom,X)% draw path function% enter% Chrom path to be painted% X City coordinate location R = [Chrom (1Mague:) Chrom (1Magi 1)];% A random solution (individual) figure Hold onplot (X (:, 1), X (:, 2), hold onplot (X (:, 1), X (:, 2), plot (X (Chrom (1), 1), X (Chrom (1), 2), 'rv','MarkerSize',20) for i=1:size (X1) text (X (iMag1) + 0.05 rv','MarkerSize',20 X (I),' color', (1)); endA=X (RJE:); row=size (A1) For i=2:row [arrowx,arrowy] = dsxy2figxy (gca,A (imur1)), A (iMur1);% coordinate transformation annotation ('textarrow',arrowx,arrowy,'HeadWidth',8,'color', [0pc0pl]); endhold offxlabel (' Abscissa') ylabel ('ordinate') title ('trajectory') box on

Function p=OutputPath (R)%% output path function% input: r path R = [R _ Magi R (1)]; N=length (R); p=num2str (R (1)); for ionomer 2purn NP = [pJournal->', num2str (R (I))]; enddisp (p)

Function len=PathLength (DMagol Chrom)%% calculate the path length of each individual% input:% D distance between two cities% Chrom individual trajectory [row,col] = size (D); NIND=size (Chrom,1); len=zeros (NIND,1); for iMagne Chrom NINDp = [Chrom (1:end-1:) Chrom (iMagne1)]; i1mirp (1:end-1); i2plump (2:end); len (iMagne1) = sum (D ((i1-1) * col+i2)); end

Function S2=NewAnswer (S1)% input% S1: current solution%% output% S2: new solution N=length (S1); S2fuge S1 * (Nmuri 1) + 1);% generate two random positions to exchange W=S2 (a (1)); S2 (a (1)) = S2 (a (2)); S2 (a (2)) = W;% get a new route

Function [SMagol R] = Metropolis (S1Magol S2Magazine T)% input% S1: current solution% S2: new solution% D: distance matrix (distance between two cities)% T: current temperature% output% S: next current solution% R: next current solution% R1=PathLength (DMagne S1);% calculate route length N=length (S1);% get the number of cities

R2=PathLength (DMagazine S2);% calculate route length dC=R2-R1;% difference in computing ability if dC=rand% accept the new route with the probability of exp (- dC/T)

About "what are the tool functions in matlab" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.

Tags: City route input path function between output location coordinates article length tool individual new solution more ability trajectory good practical two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Tech Info Shulou Information Microsoft Redmi