clear; user_input = input('Enter 1 for symmetry or 2 for none: '); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Initial Settings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% cell_size = 0.2; d = 12; h = 1; w = 1; contour_width = 1; contour_height = 0; voltage = 10; max_y = h + contour_height + 1; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Calculate the # of cells needed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% num_gridx = floor(d / cell_size)+1; num_gridy = floor(max_y / cell_size)+1; conductor_width = floor(w / cell_size); epsilon2_boundary = floor(h / cell_size); nodes_x = num_gridx - 2; nodes_y = num_gridy - 2; total_nodes = (nodes_x * nodes_y) - (conductor_width); nodeX_sym = round(nodes_x / 2); nodeY_sym = nodes_y; num_gridx_sym = round((num_gridx-1)/2); total_nodes_sym = nodeX_sym * nodeY_sym; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Calculate where the conductor is %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% voltage_x = floor((num_gridx / 2))+1; voltage_y = epsilon2_boundary; if (mod(conductor_width,2) == 1) voltage_right = voltage_x + floor(conductor_width / 2); voltage_left = voltage_x - floor(conductor_width / 2); end if (mod(conductor_width,2) == 0) voltage_left = voltage_x - floor(conductor_width / 2); voltage_right = voltage_x; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Set boundary to 0 V %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for i = 1:num_gridy micro(i,1,1) = 0; micro(i,num_gridx,1) = 0; end for j = 1:num_gridx-1 micro(1,j,1) = 0; micro(num_gridy,j,1) = 0; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Set Conductor to 10V %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for i = voltage_left: voltage_right micro(voltage_y,i,1) = voltage; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% 3D Array to set nodes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% node_number = 1; if(user_input == 2) for k = 2:(num_gridy - 1) for j = 2:(num_gridx - 1) test_node = micro(k,j,1); if (test_node ~= voltage) micro(k,j,2) = node_number; node_number = node_number + 1; end end end end if(user_input == 1) for k = 2:(num_gridy - 1) for j = 2:(round((num_gridx / 2))) micro(k,j,2) = node_number; node_number = node_number + 1; end end end for j = 1:num_gridx micro(1,j,2) = -1; micro(num_gridy,j,2) = -1; end for k = 1:num_gridy micro(k,1,2) = -1; micro(k,num_gridx,2) = -1; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Determine Size of Micro Array %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [y,x] = size(micro); x = x/2; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% First Matrix: Equal Arm Procedure %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if(user_input == 2) for g = 2:(num_gridy-1) for h = 2:(num_gridx-1) a = micro(g,h+1,2); b = micro(g,h-1,2); c = micro(g+1,h,2); d = micro(g-1,h,2); center = micro(g,h,2); voltage_a = micro(g,h+1,1); voltage_b = micro(g,h-1,1); voltage_c = micro(g+1,h,1); voltage_d = micro(g-1,h,1); voltage_center = micro(g,h,1); if ((a > 0) && (center ~= 0)) matrix(center,a) = 1; end if ((b > 0) && (center ~= 0)) matrix(center,b) = 1; end if ((c > 0) && (center ~= 0)) matrix(center,(center + nodes_x)) = 1; end if ((d > 0) && (center ~= 0) && (g ~= (voltage_y+1))) matrix(center,(center - nodes_x)) = 1; end if ((d > 0) && (center ~= 0) && (g == (voltage_y+1))) matrix(center,(center - (nodes_x-(conductor_width+1)))) = 1; end if (center > 0) matrix(center,center) = -4; end end end end if(user_input == 1) for k = 2:(nodeY_sym+1) for j = 2:(nodeX_sym+1) a = micro(k,j+1,2); b = micro(k,j-1,2); c = micro(k+1,j,2); d = micro(k-1,j,2); center = micro(k,j,2); if((j == (nodeX_sym+1))) if (b > 0) matrix_sym(center,b) = 2; end if (c > 0) matrix_sym(center,(center + nodeX_sym)) = 1; end if (d > 0) matrix_sym(center,(center - nodeX_sym)) = 1; end if (center > 0) matrix_sym(center,center) = -4; end end if((j < (nodeX_sym+1))) if (a > 0) matrix_sym(center,a) = 1; end if (b > 0) matrix_sym(center,b) = 1; end if (c > 0) matrix_sym(center,(center + nodeX_sym)) = 1; end if (d > 0) matrix_sym(center,(center - nodeX_sym)) = 1; end if (center > 0) matrix_sym(center,center) = -4; end end end end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Second Matrix Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if(user_input == 2) for i = 1:total_nodes matrix2(i,1) = i; end end if(user_input == 1) for i = 1:total_nodes_sym matrix2_sym(i,1) = i; end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Third Matrix Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if(user_input == 1) for k = 1:total_nodes_sym matrix3_sym(k,1) = 0; end end if(user_input == 2) for k = 1:total_nodes matrix3(k,1) = 0; end for m = voltage_left: voltage_right voltage_node = micro(voltage_y,m,2); voltage_one = micro(voltage_y,m+1,1); voltage_two = micro(voltage_y,m-1,1); voltage_three = micro(voltage_y+1,m,1); voltage_four = micro(voltage_y-1,m,1); voltage_center = micro(voltage_y,m,1); one = micro(voltage_y,m+1,2); two = micro(voltage_y,m-1,2); three = micro(voltage_y+1,m,2); four = micro(voltage_y-1,m,2); loc_center = micro(voltage_y,m,2); if ((voltage_one ~= voltage) && (one ~= -1)) matrix3(one,1) = -voltage; end if ((voltage_two ~= voltage) && (two ~= -1)) matrix3(two,1) = -voltage; end if ((voltage_three ~= voltage) && (three ~= -1)) matrix3(three,1) = -voltage; end if ((voltage_four ~= voltage) && (four ~= -1)) matrix3(four,1) = -voltage; end % if ((voltage_one == voltage) && (voltage_two == voltage)) % matrix3(m-1,1) = 2*voltage; % end % if (((voltage_one == voltage) && (voltage_two ~= voltage)) || ((voltage_one ~= voltage) && (voltage_two == voltage))) % matrix3(m-1,1) = 3*voltage; % end if (((voltage_center == voltage) && (voltage_one ~= voltage) && (voltage_two ~= voltage) && (voltage_three ~= voltage) && (voltage_four ~= voltage))) matrix(m-1,1) = 4*voltage; end % for n = 1:total_nodes % matrix(n,voltage_node) = 0; % end end end %if(user_input == 2) % a1 = 0; % a2 = 0; % a3 = 0; % a4 = 0; % a5 = 0; % for k = 2:num_gridy-1 % for j = 2:num_gridx-1 % a1 = micro(k,j+1,1); % a2 = micro(k,j-1,1); % a3 = micro(k+1,j,1); % a4 = micro(k-1,j,1); % a5 = micro(k,j,1); % value = micro(k,j,2); % if(a1 || a2 || a3 || a4 || a5 == voltage) % matrix3(value,1) = -voltage; % else % matrix3(value,1) = 0; % end % end % end %end %if(user_input == 1) % a1 = 0; % a2 = 0; % a3 = 0; % a4 = 0; % a5 = 0; % for k = 2:num_gridy-1 % for j = 2:(num_gridx_sym+1) % a1 = micro(k,j+1,1); % a2 = micro(k,j-1,1); % a3 = micro(k+1,j,1); % a4 = micro(k-1,j,1); % a5 = micro(k,j,1); % value = micro(k,j,2); % if((a1 & (j < num_gridx_sym)) || a2 || a3 || a4 || a5 == voltage) % matrix3_sym(value,1) = -voltage; % else % matrix3_sym(value,1) = 0; % end % end % end %end if(user_input == 2) final = inv(matrix)*matrix3; cond(matrix) end if(user_input == 1) final_sym = inv(matrix_sym) * matrix3_sym; cond(matrix_sym); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Contour Integration %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %if(user_input == 2) % starting_point_x = voltage_right + contour_width; % starting_point_y = voltage_y; % j = starting_point_x; % k = starting_point_y; % phi1_node = micro(k,j+1,2); % phi2_node = micro(k+1,j+1,2); % phi3_node = micro(k,j-1,2); % phi4_node = micro(k+1,j-1,2); % phi5_node = micro(k-1,j+1,2); % phi6_node = micro(k-1,j-1,2); % phi1 = final(phi1_node); % phi2 = final(phi2_node); % phi3 = final(phi3_node); % phi4 = final(phi4_node); % phi5 = final(phi5_node); % phi6 = final(phi6_node); %end