курсачи / matlab
.docxh = input('Введите h '); %шаг сетки
m = input('Введите размер сетки '); %размер
r=input('Введите значение радиуса разбиваемой области '); %задание области
if m<=r || h<=0 || m<=0 || r<=0 || m/h<1.6
disp('Некорректный ввод')
else
[X,Y] = meshgrid(-m:h:m); %формирование массива
Z = X*0;
surf(X,Y,Z); %построение сетки
xlabel('x');
ylabel('y');
alpha 0
hold on
x=-r:0.0001:r;
y1=sqrt(r^2-x.^2);
y2=-sqrt(r^2-x.^2);
plot(x,y1,x,y2);
max_i=floor(m*2/h+1); %округление в меньшую сторону
max_j=floor(m*2/h+1);
rasst_do_uzlov=zeros(1000,1000);
coord_uzlov=zeros(1000,1000);
coord_toch_okr=zeros(1000,1000);
h_mezhdu_uzlami=zeros(1000,1000);
irregular_nodes=zeros(1000,1000);
for i=1:1:max_i
for j=1:1:max_j
rasst_do_uzlov(i,j)=sqrt((X(i,j)).^2+(Y(i,j)).^2);
end
end
o=1;count=1;
for i=1:1:max_i %цикл для формирования массива с координатами нерегулярных узлов
for j=1:1:max_j
if rasst_do_uzlov(i,j)<r && (rasst_do_uzlov(i,j-1)>=r || rasst_do_uzlov(i,j+1)>=r || rasst_do_uzlov(i+1,j)>=r || rasst_do_uzlov(i-1,j)>=r)
coord_uzlov(o,1)=X(i,j);
coord_uzlov(o,2)=Y(i,j);
irregular_nodes(o,1)=count;
irregular_nodes(o,2)=X(i,j);
irregular_nodes(o,3)=Y(i,j);
o=o+1;
stem(X(i,j),Y(i,j),'fill', 'b');
end
count=count+1; %счётчик узлов
end
end
o_max=o;
for o=1:1:o_max-1 %цикл для формирования массива с координатами точек на окружности, которым соответствуют нерегулярные узлы
coord_toch_okr(o,1)=sqrt(r^2-(coord_uzlov(o,2)).^2);
coord_toch_okr(o,2)=sqrt(r^2-(coord_uzlov(o,1)).^2);
end
for o=1:1:o_max-1 %цикл для формирования массива с расстояниями от точек на окружности до узлов
h_mezhdu_uzlami(o,1)=abs(abs(coord_uzlov(o,1))-abs(coord_toch_okr(o,1)));
h_mezhdu_uzlami(o,2)=abs(abs(coord_uzlov(o,2))-abs(coord_toch_okr(o,2)));
end
for o=1:1:o_max-1
if coord_uzlov(o,1)<0 && coord_uzlov(o,2)<0 %x<0;y<0
irregular_nodes(o,4)=h_mezhdu_uzlami(o,1);
irregular_nodes(o,5)=h_mezhdu_uzlami(o,2);
irregular_nodes(o,6)=h;
irregular_nodes(o,7)=h;
if irregular_nodes(o,4)>h
irregular_nodes(o,4)=h;
end
if irregular_nodes(o,5)>h
irregular_nodes(o,5)=h;
end
end
if coord_uzlov(o,1)<0 && coord_uzlov(o,2)>0 %x<0;y>0
irregular_nodes(o,4)=h_mezhdu_uzlami(o,1);
irregular_nodes(o,5)=h;
irregular_nodes(o,6)=h;
irregular_nodes(o,7)=h_mezhdu_uzlami(o,2);
if irregular_nodes(o,4)>h
irregular_nodes(o,4)=h;
end
if irregular_nodes(o,7)>h
irregular_nodes(o,7)=h;
end
end
if coord_uzlov(o,1)>0 && coord_uzlov(o,2)>0 %x>0;y>0
irregular_nodes(o,4)=h;
irregular_nodes(o,5)=h;
irregular_nodes(o,6)=h_mezhdu_uzlami(o,1);
irregular_nodes(o,7)=h_mezhdu_uzlami(o,2);
if irregular_nodes(o,6)>h
irregular_nodes(o,6)=h;
end
if irregular_nodes(o,7)>h
irregular_nodes(o,7)=h;
end
end
if coord_uzlov(o,1)>0 && coord_uzlov(o,2)<0 %x>0;y<0
irregular_nodes(o,4)=h;
irregular_nodes(o,5)=h_mezhdu_uzlami(o,2);
irregular_nodes(o,6)=h_mezhdu_uzlami(o,1);
irregular_nodes(o,7)=h;
if irregular_nodes(o,5)>h
irregular_nodes(o,5)=h;
end
if irregular_nodes(o,6)>h
irregular_nodes(o,6)=h;
end
end
if coord_uzlov(o,1)==0 && coord_uzlov(o,2)<0 %x=0;y<0
irregular_nodes(o,4)=h_mezhdu_uzlami(o,1);
irregular_nodes(o,5)=h_mezhdu_uzlami(o,2);
irregular_nodes(o,6)=h_mezhdu_uzlami(o,1);
irregular_nodes(o,7)=h;
if irregular_nodes(o,4)>h
irregular_nodes(o,4)=h;
end
if irregular_nodes(o,5)>h
irregular_nodes(o,5)=h;
end
if irregular_nodes(o,6)>h
irregular_nodes(o,6)=h;
end
end
if coord_uzlov(o,1)<0 && coord_uzlov(o,2)==0 %x<0;y=0
irregular_nodes(o,4)=h_mezhdu_uzlami(o,1);
irregular_nodes(o,5)=h_mezhdu_uzlami(o,2);
irregular_nodes(o,6)=h;
irregular_nodes(o,7)=h_mezhdu_uzlami(o,2);
if irregular_nodes(o,4)>h
irregular_nodes(o,4)=h;
end
if irregular_nodes(o,5)>h
irregular_nodes(o,5)=h;
end
if irregular_nodes(o,7)>h
irregular_nodes(o,7)=h;
end
end
if coord_uzlov(o,1)>0 && coord_uzlov(o,2)==0 %x>0;y=0
irregular_nodes(o,4)=h;
irregular_nodes(o,5)=h_mezhdu_uzlami(o,2);
irregular_nodes(o,6)=h_mezhdu_uzlami(o,1);
irregular_nodes(o,7)=h_mezhdu_uzlami(o,2);
if irregular_nodes(o,5)>h
irregular_nodes(o,5)=h;
end
if irregular_nodes(o,6)>h
irregular_nodes(o,6)=h;
end
if irregular_nodes(o,7)>h
irregular_nodes(o,7)=h;
end
end
if coord_uzlov(o,1)==0 && coord_uzlov(o,2)>0 %x=0;y>0
irregular_nodes(o,4)=h_mezhdu_uzlami(o,1);
irregular_nodes(o,5)=h;
irregular_nodes(o,6)=h_mezhdu_uzlami(o,1);
irregular_nodes(o,7)=h_mezhdu_uzlami(o,2);
if irregular_nodes(o,4)>h
irregular_nodes(o,4)=h;
end
if irregular_nodes(o,6)>h
irregular_nodes(o,6)=h;
end
if irregular_nodes(o,7)>h
irregular_nodes(o,7)=h;
end
end
if r<h
irregular_nodes(o,4)=r;
irregular_nodes(o,5)=r;
irregular_nodes(o,6)=r;
irregular_nodes(o,7)=r;
end
end
g=1; max_g=2*r/0.0001+1; %начало проверки
coord_toch_okr_proof=zeros(1000,1000);
for o=1:1:o_max-1
for g=1:1:max_g
if coord_uzlov(o,1)==x(1,g)
coord_toch_okr_proof(o,2)=abs(y2(1,g));
coord_toch_okr_proof(o,1)=abs(x(1,g));
end
end
end
h_mezhdu_uzlami_proof=zeros(1000,1000);
for o=1:1:o_max-1 %цикл для формирования массива с расстояниями от точек на окружности до узлов
h_mezhdu_uzlami_proof(o,1)=pdist2(abs(coord_uzlov(o,1)),abs(coord_toch_okr(o,1)));
h_mezhdu_uzlami_proof(o,2)=pdist2(abs(coord_uzlov(o,2)),abs(coord_toch_okr(o,2)));
coord_toch_okr_proof(o,1)=coord_toch_okr_proof(o,1)+h_mezhdu_uzlami_proof(o,1);
end
irregular_nodes_proof=zeros(1000,1000);
rasst_do_uzlov_proof=zeros(1000,1000);
for i=1:1:max_i
for j=1:1:max_j
rasst_do_uzlov_proof(i,j)=sqrt((X(i,j)).^2+(Y(i,j)).^2);
end
end
o=1;count=1;
for i=1:1:max_i %цикл для формирования массива с координатами нерегулярных узлов
for j=1:1:max_j
if rasst_do_uzlov_proof(i,j)<r && (rasst_do_uzlov_proof(i,j-1)>=r || rasst_do_uzlov_proof(i,j+1)>=r || rasst_do_uzlov_proof(i+1,j)>=r || rasst_do_uzlov_proof(i-1,j)>=r)
coord_uzlov(o,1)=X(i,j);
coord_uzlov(o,2)=Y(i,j);
irregular_nodes_proof(o,1)=count;
irregular_nodes_proof(o,2)=X(i,j);
irregular_nodes_proof(o,3)=Y(i,j);
o=o+1;
stem(X(i,j),Y(i,j),'fill', 'b');
end
count=count+1; %счётчик узлов
end
end
o=1;
for o=1:1:o_max-1
if coord_uzlov(o,1)<0 && coord_uzlov(o,2)<0 %x<0;y<0
irregular_nodes_proof(o,4)=h_mezhdu_uzlami_proof(o,1);
irregular_nodes_proof(o,5)=h_mezhdu_uzlami_proof(o,2);
irregular_nodes_proof(o,6)=h;
irregular_nodes_proof(o,7)=h;
if irregular_nodes_proof(o,4)>h
irregular_nodes_proof(o,4)=h;
end
if irregular_nodes_proof(o,5)>h
irregular_nodes_proof(o,5)=h;
end
end
if coord_uzlov(o,1)<0 && coord_uzlov(o,2)>0 %x<0;y>0
irregular_nodes_proof(o,4)=h_mezhdu_uzlami_proof(o,1);
irregular_nodes_proof(o,5)=h;
irregular_nodes_proof(o,6)=h;
irregular_nodes_proof(o,7)=h_mezhdu_uzlami_proof(o,2);
if irregular_nodes_proof(o,4)>h
irregular_nodes_proof(o,4)=h;
end
if irregular_nodes_proof(o,7)>h
irregular_nodes_proof(o,7)=h;
end
end
if coord_uzlov(o,1)>0 && coord_uzlov(o,2)>0 %x>0;y>0
irregular_nodes_proof(o,4)=h;
irregular_nodes_proof(o,5)=h;
irregular_nodes_proof(o,6)=h_mezhdu_uzlami_proof(o,1);
irregular_nodes_proof(o,7)=h_mezhdu_uzlami_proof(o,2);
if irregular_nodes_proof(o,6)>h
irregular_nodes_proof(o,6)=h;
end
if irregular_nodes_proof(o,7)>h
irregular_nodes_proof(o,7)=h;
end
end
if coord_uzlov(o,1)>0 && coord_uzlov(o,2)<0 %x>0;y<0
irregular_nodes_proof(o,4)=h;
irregular_nodes_proof(o,5)=h_mezhdu_uzlami_proof(o,2);
irregular_nodes_proof(o,6)=h_mezhdu_uzlami_proof(o,1);
irregular_nodes_proof(o,7)=h;
if irregular_nodes_proof(o,5)>h
irregular_nodes_proof(o,5)=h;
end
if irregular_nodes_proof(o,6)>h
irregular_nodes_proof(o,6)=h;
end
end
if coord_uzlov(o,1)==0 && coord_uzlov(o,2)<0 %x=0;y<0
irregular_nodes_proof(o,4)=h_mezhdu_uzlami_proof(o,1);
irregular_nodes_proof(o,5)=h_mezhdu_uzlami_proof(o,2);
irregular_nodes_proof(o,6)=h_mezhdu_uzlami_proof(o,1);
irregular_nodes_proof(o,7)=h;
if irregular_nodes_proof(o,4)>h
irregular_nodes_proof(o,4)=h;
end
if irregular_nodes_proof(o,5)>h
irregular_nodes_proof(o,5)=h;
end
if irregular_nodes_proof(o,6)>h
irregular_nodes_proof(o,6)=h;
end
end
if coord_uzlov(o,1)<0 && coord_uzlov(o,2)==0 %x<0;y=0
irregular_nodes_proof(o,4)=h_mezhdu_uzlami_proof(o,1);
irregular_nodes_proof(o,5)=h_mezhdu_uzlami_proof(o,2);
irregular_nodes_proof(o,6)=h;
irregular_nodes_proof(o,7)=h_mezhdu_uzlami_proof(o,2);
if irregular_nodes_proof(o,4)>h
irregular_nodes_proof(o,4)=h;
end
if irregular_nodes_proof(o,5)>h
irregular_nodes_proof(o,5)=h;
end
if irregular_nodes_proof(o,7)>h
irregular_nodes_proof(o,7)=h;
end
end
if coord_uzlov(o,1)>0 && coord_uzlov(o,2)==0 %x>0;y=0
irregular_nodes_proof(o,4)=h;
irregular_nodes_proof(o,5)=h_mezhdu_uzlami_proof(o,2);
irregular_nodes_proof(o,6)=h_mezhdu_uzlami_proof(o,1);
irregular_nodes_proof(o,7)=h_mezhdu_uzlami_proof(o,2);
if irregular_nodes_proof(o,5)>h
irregular_nodes_proof(o,5)=h;
end
if irregular_nodes_proof(o,6)>h
irregular_nodes_proof(o,6)=h;
end
if irregular_nodes_proof(o,7)>h
irregular_nodes_proof(o,7)=h;
end
end
if coord_uzlov(o,1)==0 && coord_uzlov(o,2)>0 %x=0;y>0
irregular_nodes_proof(o,4)=h_mezhdu_uzlami_proof(o,1);
irregular_nodes_proof(o,5)=h;
irregular_nodes_proof(o,6)=h_mezhdu_uzlami_proof(o,1);
irregular_nodes_proof(o,7)=h_mezhdu_uzlami_proof(o,2);
if irregular_nodes_proof(o,4)>h
irregular_nodes_proof(o,4)=h;
end
if irregular_nodes_proof(o,6)>h
irregular_nodes_proof(o,6)=h;
end
if irregular_nodes_proof(o,7)>h
irregular_nodes_proof(o,7)=h;
end
end
if r<h
irregular_nodes_proof(o,4)=r;
irregular_nodes_proof(o,5)=r;
irregular_nodes_proof(o,6)=r;
irregular_nodes_proof(o,7)=r;
end
end
end