creating multiple holes in a flatwire PDE Modeler
Hi,
Matlab suggested me to create a more efficient code: what i am trying to do is to create 12 holes vertically in a strip of wire and repeat it 7x times over a 0.2 distance: i started with this code:
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
pderect([rectx rect_width recty,rect_height] )
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
pdecirc(x_center, y_center,radius)
hold on;
end
end
axis equal;
hold off;
better code as matlab suggested: but get stuck with an error:
Error in TestSkript2 (line 38)
ns(idx+1)=[‘C’,num2str(idx)];
please advise.
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
R1=[3,4,rectx, rectx+rect_width,rectx+rect_width,rectx,recty,recty,recty+rect_height,recty+rect_height]’;
%preallocating the arrays(more efficient for matlab CHAT GPT)
num_circles = num_holes_y * num_rep_x;
gd = zeros(10, 1 + num_circles);
gd(:, 1) = R1;
ns = cell(1+num_circles,1);
ns{ones}=’R1′;
sf=’R1′;
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
C=[1,x_center, y_center,radius]’;
idx=j*num_holes_y+i+1;
gd(1:4,idx+1)=C;
ns{idx+1}=[‘C’,num2str(idx)];
sf=[sf,’C’,num2str(idx)];
end
end
ns=char(ns);
g=decsg(gd,sf,ns);
axis equal;
hold off;Hi,
Matlab suggested me to create a more efficient code: what i am trying to do is to create 12 holes vertically in a strip of wire and repeat it 7x times over a 0.2 distance: i started with this code:
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
pderect([rectx rect_width recty,rect_height] )
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
pdecirc(x_center, y_center,radius)
hold on;
end
end
axis equal;
hold off;
better code as matlab suggested: but get stuck with an error:
Error in TestSkript2 (line 38)
ns(idx+1)=[‘C’,num2str(idx)];
please advise.
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
R1=[3,4,rectx, rectx+rect_width,rectx+rect_width,rectx,recty,recty,recty+rect_height,recty+rect_height]’;
%preallocating the arrays(more efficient for matlab CHAT GPT)
num_circles = num_holes_y * num_rep_x;
gd = zeros(10, 1 + num_circles);
gd(:, 1) = R1;
ns = cell(1+num_circles,1);
ns{ones}=’R1′;
sf=’R1′;
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
C=[1,x_center, y_center,radius]’;
idx=j*num_holes_y+i+1;
gd(1:4,idx+1)=C;
ns{idx+1}=[‘C’,num2str(idx)];
sf=[sf,’C’,num2str(idx)];
end
end
ns=char(ns);
g=decsg(gd,sf,ns);
axis equal;
hold off; Hi,
Matlab suggested me to create a more efficient code: what i am trying to do is to create 12 holes vertically in a strip of wire and repeat it 7x times over a 0.2 distance: i started with this code:
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
pderect([rectx rect_width recty,rect_height] )
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
pdecirc(x_center, y_center,radius)
hold on;
end
end
axis equal;
hold off;
better code as matlab suggested: but get stuck with an error:
Error in TestSkript2 (line 38)
ns(idx+1)=[‘C’,num2str(idx)];
please advise.
model = createpde;
%Define a circle in a rectangle, place these in one matrix, and create a set formula that subtracts the circle from the rectangle.
rectx=0;
recty=0;
rect_width=1.38;
rect_height=0.2;
x_start=0.1;%starting position x circle
y_start=0.2;%starting position y circle
radius=0.005;%radius holes
num_holes_y=12;%number of repitition in the y
num_rep_x=7;%number of repitition in the x
y_interval=0.0183; %distance between the holes in the y;
x_interval=0.2; % distance between the holes in the x;
R1=[3,4,rectx, rectx+rect_width,rectx+rect_width,rectx,recty,recty,recty+rect_height,recty+rect_height]’;
%preallocating the arrays(more efficient for matlab CHAT GPT)
num_circles = num_holes_y * num_rep_x;
gd = zeros(10, 1 + num_circles);
gd(:, 1) = R1;
ns = cell(1+num_circles,1);
ns{ones}=’R1′;
sf=’R1′;
%create multiple holes in a strip and draw it into the pde modeler
for j=0:(num_rep_x-1)
for i=0:(num_holes_y-1)
%calculate the x and y position for the current hole
x_center=x_start+j*x_interval;
y_center=y_start-i*y_interval;
C=[1,x_center, y_center,radius]’;
idx=j*num_holes_y+i+1;
gd(1:4,idx+1)=C;
ns{idx+1}=[‘C’,num2str(idx)];
sf=[sf,’C’,num2str(idx)];
end
end
ns=char(ns);
g=decsg(gd,sf,ns);
axis equal;
hold off; pde modeler script. MATLAB Answers — New Questions