Home /
Expert Answers /
Electrical Engineering /
trying-to-figure-this-error-error-using-horzcat-dimensions-of-arrays-being-concatenated-are-not-co-pa349

trying to figure this error:

Error using horzcat

Dimensions of arrays being concatenated are not consistent.

$%$ Constants mu0 $=4_{⋆}pi_{⋆}10_{∧}−7;$ ㅇacuum permeability \% Geometry and dimensions t0 $=0.02;$ Thickness of Omegal $b0=0.02;%$ Width of Omegal $ts=0.01;÷$ Thickness of Omega2 $g=0.001;÷$ Air-gap thickness $cD=0.05;$ Distance from Omega2 to Gamma2 $10=0.05;÷$ Length of the domain $c0=0.05;$ Distance from Omegal to Gammal \% Material properties mu1 $=1000;$ o Relative permeability of Omegal mu2 $=1;%$ Relative permeability of Omega 2 $%$ Boundary conditions $A1=0;$ o Magnetic vector potential at Gammal A2 $=1e−3⋆mu;$ 응 Magnetic vector potential at Gamma2 $%$ Mesh generation $nx=50;$ Number of elements along $x$-axis $ny=50;$ Number of elements along $y$-axis $hx=10/nx;$ Element size along $x$-axis $hy=(b0+2_{⋆}g)/$ ny; $%$ Element size along $y$-axis
\% Node and element numbering nodeNum $=(i,j)(j−1)⋆(nn+1)+i;$ elemNum $=(i,j)(j−1)_{⋆}nx+i$ i \% Create nodes and elements nodes $=zeros((nx+1)⋆(ny+1),2)$; elements $=zeros(nx_{⋆}ny,4)$; for $j=1:ny+1$ for $i=1:nx+1$ nodes $(nodeNum(i,j),:)=[(i−1)⋆hx,(j−1)⋆hy];$ end -end for $j=1:ny$ for $i=1:nx$ elements (elemNum $(i,j),:)=[nodeNum(i,j),nodeNum(i+1,j),nodeNum(i+1,j+1),nodeNum(i,j+1)]i$ end -end \% Assemble global stiffness matrix and load vector numNodes $=(nx+1)⋆(ny+1);$
numElements $=nx_{⋆}ny;$ $K=$ sparse (numNodes, numNodes); $F=zeros$ (numNodes, 1); for $e=1$ :numElements nodesInElem = elements $(e,:)$; $x=$ nodes (nodesInElem, 1 ); $y=$ nodes (nodesInElem, 2); area $=(x(2)−x(1))$ * $(y(3)−y(2))$; $Ke=(mu1_{⋆}mu0_{⋆}gradN_{′}_{∗}gradN+mu2_{⋆}mu0_{∗}gradN_{′∗}gradN)$ *area $/2$; $K$ (nodesInElem, nodesInElem) $=K$ (nodesInElem, nodesInElem) $+Ke$; end \% Apply boundary conditions $A=zeros$ (numNodes, 1); $A(1:nx+1)=A1;÷$ Left boundary (Gamma1) $A((ny_{⋆}nx+1):(ny_{⋆}nx+nx+1))=A2;÷$ Right boundary (Gamma2) ° Solve the linear system $A=K\F$; \% Plot magnetic vector potential field lines figure;
contourf(reshape(nodes $(:,1)$, ny+1, $nx+1)$, reshape(nodes $(:,2),ny+1,nx+1)$, reshape(A, ny+1, nx+1), 'LineColor', 'non hold on: quiver (reshape (nodes $(:,1)$, $ny+1,nx+1)$, reshape (nodes $(:,2),ny+1,nx+1)$, reshape (A, $ny+1$, $nx+1)$, zeros (ny+1, $nx+1)$, $xlabel(xx(m)_{′})$ $ylabel(iy(m)_{′})$ title('Magnetic Vector Potential Field Lines'); colorbar; axis equal; ° Compute total magnetic energy in the air-gap energy $=0$; for $e=1:$ numElements nodesInElem = elements $(e,:)$; $x=nodes($ nodesInElem, 1 ); $y=$ nodes (nodesInElem, 2); area $=(x(2)−x(1))∗(y(3)−y(2))$; energy = energy + Ae; end

The error message "Error using horzcat " : Dimensions of arrays being concatenated are not consistent" occurs when you are trying to concatenate arrays horizontally (using the `horzcat` function or the