Hi, I have written this code in Matlab which runs perfectly for me and gives me the plots I needed together with the solutions. I am working in Julia and want to rewrite my code from matlab to Julia but having challenges getting this work. Any help will be greatly appreciated please. Attached is my Matlab code which I want to write in Julia. Can anyone please look at this code and help me rewrite it in Julia. I need help please.
clear
clc
n=7
W=[4 3 5 6 7 6 5]
x=[33 15 2 5 39 17 11]
y=[41 11 4 45 3 26 4]
plot(x,y, 'ko')
hold on
x-y
c=W.*(x-y)
d = norm(c) % this is two norm
x0=sum(W.*x)/sum(W)
y0=sum(W.*y)/sum(W)
Xk=[x0,y0]
hold on
plot(x0,y0, 'kv')
for r=10:30:30
viscircles([x0,y0],r);
hold on
end
for j=1:n
Norm(j)=norm(Xk-[x(j),y(j)]);% calculate the distance from the initial point to all other points, 2-norm
Top(j)=W(j)*x(j)/Norm(j); % top of 2.5
Bottom(j)=W(j)/Norm(j);% bottom of 2.5
S(j)=W(j)/Norm(j); % 2.8
Gradx(j)=W(j)*(x0-x(j))/Norm(j); % gradiaent in x-direction
Grady(j)=W(j)*(y0-y(j))/Norm(j); % gradiaent in y-direction
end
Tx=sum(Top)/sum(Bottom); % Eqn 2.5
Gradx=sum(Gradx); %Eqn 2.6 x
Grady=sum(Grady); %Eqn 2.6 y
SatBarx=(sum(S))^(-1);
NewX=Xk-[SatBarx*Gradx, SatBarx*Grady]
count=0;
while (abs(NewX(1)-Xk(1))>0.0001 && abs(NewX(2)-Xk(2))>0.0001)
Xk=NewX;
for j=1:n
Norm(j)=norm(Xk-[x(j),y(j)]);
Top(j)=W(j)*x(j)/Norm(j);
Bottom(j)=W(j)/Norm(j);
S(j)=W(j)/Norm(j);
Gradx(j)=W(j)*(Xk(1)-x(j))/Norm(j);
Grady(j)=W(j)*(Xk(2)-y(j))/Norm(j);
end
Tx=sum(Top)/sum(Bottom); % Eqn 2.5
Gradx=sum(Gradx);
Grady=sum(Grady);
SatBarx=(sum(S))^(-1);
NewX=Xk-[SatBarx*Gradx, SatBarx*Grady]
count=count+1;
end
count+1
plot(NewX(1),NewX(2), 'r*')
for r=10:5:30
viscircles([NewX],r, 'LineStyle','--');
hold on
end