I am trying to set up a variable matrix, where I have a variable x that goes from 0 to 2 and a variable z that goes from 0 to 2. I have two other variables m and n that depend on both x and z. How should I go about setting up a variable matrix?
So I typed it up in matlab, how would I transfer the code in Mathematica? a is a constant
%Defining vatiables
x=[-2*a:.01*3*a:2*a];
z=[0:.005*3*a:2*a];
%Creates variable matrix
for i=1:length(z);
for j=1:length(x);
xx(i, j)=x(j);
zz(i, j)=z(i);
end
end
%A loop to find the stresses, where the stress (sz,sx,sy, and txy) is dependent on both m and n
for i=1:length(x);
for j=1:length(z);
m(j, i)=(0.5*(((a^2-xx(j, i)^2+zz(j, i)^2).^2+4.*xx(j, i)^2.*zz(j, i)^2).^0.5+(a.^2.-xx(j, i)^2+zz(j, i)^2))).^0.5;
n(j, i)=(0.5*(((a^2-xx(j, i)^2+zz(j, i)^2).^2+4.*xx(j, i)^2.*zz(j, i)^2).^0.5-(a.^2.-xx(j, i)^2+zz(j, i)^2))).^0.5;
if x(i) < 0
n(j, i)=-n(j, i);
end
sx(j, i)=(-Ph/a)*(m(j, i)*((1+((zz(j, i)^2+n(j, i)^2)/(m(j, i)^2+n(j, i)^2))))-2.*zz(j, i));
sz(j, i)=(-Ph/a)*m(j, i)*((1-((zz(j, i)^2+n(j, i)^2)/(m(j, i)^2+n(j, i)^2))));
sy(j, i)=v1*(sx(j, i)+sz(j, i));
txz(j, i)=(-Ph/a).*n(j, i)*((m(j, i)^2-zz(j, i)^2)./(m(j, i)^2+n(j, i)^2));
tmax(j, i)=0.5*abs(sx(j, i)-sz(j, i));
end
end