필터 지우기
필터 지우기

I face a problem with the dimensions of Z as it should be a 2x2 matrix.

조회 수: 9 (최근 30일)
Mohd Babar
Mohd Babar 2024년 7월 30일
댓글: Walter Roberson 2024년 7월 30일
%------Creating a strain matrix-----------%
E = zeros(2*(size(K1,1)-1),2*(size(K1,1)-1));
for j = 1: (size(K1,1)-1)
for i = 1: (size(K1,1)-1)
v = [zpk1(j,i);zpk2(j,i);zpk1(j,i+1);zpk2(j,i+1);zpk1(j+1,i+1);zpk2(j+1,i+1);zpk1(j+1,i);zpk2(j+1,i)];
e1= strain1(v);
e2= strain2(v);
e3= strain3(v);
e4= strain4(v);
E((2*j-1),(2*i-1)) = e1(1);
E((2*j-1),2*i) = e2(1);
E(2*j,(2*i-1)) = e4(1);
E(2*j,2*i) = e3(1);
end
end
su = round(4*d/g)+1;
r = E((((su-1)- round(d/g)):-1:1),(su-1));
p = E((((su-1)- round(d/g)):-1:1),(su));
st = (p+r)./(1.5*(10)^(-4));
m = g*(size(r)-1);
H = 0:g:(m);
h = H./10;
writematrix(st)
type 'st.txt'
writematrix(h)
type 'h.txt'
plot(h,st)
xlim([0 1.5])
xlabel("X2/d",'fontsize',14)
ylabel("Normalised Strain along vertical path", 'fontsize',13)
legend("d/w = 0.5")
saveas(gcf,'plot.png')
contourf(st)
colorbar
saveas(gcf,'contour.png')
The final plot of the above code should resemble something like this:
I have double chekced, the formula is correct and the value of st at a given r and p match with the experimental results. However, I face a problem with the dimensions of Z as it should be a 2x2 matrix.
Thank you in advance.
  댓글 수: 3
Mohd Babar
Mohd Babar 2024년 7월 30일
편집: Walter Roberson 2024년 7월 30일
clc;
clear all;
%-----Geometry, Number of simulations------%
d = 10;
N = 1;
a11 = 250 * (d / 10);
a12 = 100 * (d / 10);
%-----Mesh grid boundary definition--------%
xms = a11 / 2 - 2 * d;
xmf = a11 / 2 + 2 * d;
yms = a12 / 2 - 2 * d;
ymf = a12 / 2 + 2 * d;
%----------------Grid size----------------%
g = 0.085;
xq1 = xms:g:xmf;
xq = xq1';
yq1 = yms:g:ymf;
yq = yq1';
%-----Mesh grid around the hole----------%
[K1, K2] = meshgrid(xq, yq);
a = size(xq1, 2);
b = size(yq1, 2);
for k = 1:b
for j = 1:a
e = ((k * g) - 2 * d)^2 + ((j * g) - 2 * d)^2 - (0.5 * d)^2;
if e < 0
K1(j, k) = NaN;
K2(j, k) = NaN;
end
end
end
zz1 = 0;
zz2 = 0;
%----Importing files from Abaqus---------%
for i = 1:N
fx = ['d:/babar/Abaqus/S2000/aax' num2str(i) '.txt'];
fy = ['d:/babar/Abaqus/S2000/aay' num2str(i) '.txt'];
fu = ['d:/babar/Abaqus/S2000/aau1' num2str(i) '.txt'];
fv = ['d:/babar/Abaqus/S2000/aau2' num2str(i) '.txt'];
x = textfile(fx);
y = textfile(fy);
z1 = textfile(fu);
z2 = textfile(fv);
U1 = griddata(x, y, z1, K1, K2);
U2 = griddata(x, y, z2, K1, K2);
zz1 = U1 + zz1;
zz2 = U2 + zz2;
end
%--------Averaging the displacements-------%
zpk1 = zz1 / N;
zpk2 = zz2 / N;
xlswrite('zpk1.xlsx', zpk1)
xlswrite('zpk2.xlsx', zpk2)
%------Creating a strain matrix-----------%
E = zeros(2 * (size(K1, 1) - 1), 2 * (size(K1, 1) - 1));
for j = 1:(size(K1, 1) - 1)
for i = 1:(size(K1, 1) - 1)
v = [zpk1(j, i); zpk2(j, i); zpk1(j, i + 1); zpk2(j, i + 1); zpk1(j + 1, i + 1); zpk2(j + 1, i + 1); zpk1(j + 1, i); zpk2(j + 1, i)];
e1 = strain1(v);
e2 = strain2(v);
e3 = strain3(v);
e4 = strain4(v);
E((2 * j - 1), (2 * i - 1)) = e1(1);
E((2 * j - 1), 2 * i) = e2(1);
E(2 * j, (2 * i - 1)) = e4(1);
E(2 * j, 2 * i) = e3(1);
end
end
su = round(4 * d / g) + 1;
r = E((((su - 1) - round(d / g)):-1:1), (su - 1));
p = E((((su - 1) - round(d / g)):-1:1), su);
st = (p + r) / (1.5 * 10^(-4));
m = g * (size(r, 1) - 1);
H = 0:g:m;
h = H / 10;
writematrix(st, 'st.txt')
writematrix(h, 'h.txt')
figure;
plot(h, st)
xlim([0 1.5])
xlabel("X2/d", 'fontsize', 14)
ylabel("Normalized Strain along vertical path", 'fontsize', 13)
legend("d/w = 0.5")
saveas(gcf, 'plot.png')
figure;
contourf(st)
colorbar
saveas(gcf, 'contour.png')
function E1 = strain1(v)
B1 = [1 0 0 0; 0 0 0 1; 0 1 1 0];
x1 = -1 / sqrt(3); eta1 = -1 / sqrt(3);
B21 = B2();
B31 = B3(x1, eta1);
B12 = B1 * B21;
B = B12 * B31;
E1 = B * v;
end
function E1 = strain2(v)
B1 = [1 0 0 0; 0 0 0 1; 0 1 1 0];
x1 = 1 / sqrt(3); eta1 = -1 / sqrt(3);
B21 = B2();
B31 = B3(x1, eta1);
B12 = B1 * B21;
B = B12 * B31;
E1 = B * v;
end
function E1 = strain3(v)
B1 = [1 0 0 0; 0 0 0 1; 0 1 1 0];
x1 = 1 / sqrt(3); eta1 = 1 / sqrt(3);
B21 = B2();
B31 = B3(x1, eta1);
B12 = B1 * B21;
B = B12 * B31;
E1 = B * v;
end
function E1 = strain4(v)
B1 = [1 0 0 0; 0 0 0 1; 0 1 1 0];
x1 = -1 / sqrt(3); eta1 = 1 / sqrt(3);
B21 = B2();
B31 = B3(x1, eta1);
B12 = B1 * B21;
B = B12 * B31;
E1 = B * v;
end
function B21 = B2()
B21 = [0.05 / 0.0025 0 0 0; 0 0.05 / 0.0025 0 0; 0 0 0.05 / 0.0025 0; 0 0 0 0.05 / 0.0025];
end
function B31 = B3(x1, eta1)
B31 = [...
-(1 - eta1) * 0.25 0 (1 - eta1) * 0.25 0 (1 + eta1) * 0.25 0 -(1 + eta1) * 0.25 0; ...
-(1 - x1) * 0.25 0 -(1 + x1) * 0.25 0 (1 + x1) * 0.25 0 (1 - x1) * 0.25 0; ...
0 -(1 - eta1) * 0.25 0 (1 - eta1) * 0.25 0 (1 + eta1) * 0.25 0 -(1 + eta1) * 0.25; ...
0 -(1 - x1) * 0.25 0 -(1 + x1) * 0.25 0 (1 + x1) * 0.25 0 (1 - x1) * 0.25];
end
function value = textfile(filename)
fileID = fopen(filename, 'r');
if fileID == -1
error('Failed to open file: %s', filename);
end
value = fscanf(fileID, '%f');
fclose(fileID);
end
%"These are the extract data from abaqus and
su = round(4 * d / g) + 1;
r = E((((su - 1) - round(d / g)):-1:1), (su - 1));
p = E((((su - 1) - round(d / g)):-1:1), su);
[r, p] = meshgrid(r,p);
st = (p + r) / (1.5 * 10^(-4));
m = g * (size(r, 1) - 1);
H = 0:g:m;
h = H / 10;
i have tried with meshgrid option, after using meshgrid i rid of the error but results are not correct."
Thanks in advance

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2024년 7월 30일
d = 10;
g = 0.085;
d and g are scalars
su = round(4 * d / g) + 1;
su is formed from scalar d and g, so su is scalar
r = E((((su - 1) - round(d / g)):-1:1), (su - 1));
p = E((((su - 1) - round(d / g)):-1:1), su);
su-1 and su are scalars, so you are extracting exactly one column from E into r and p, so r and p are vectors (not 2D)
st = (p + r) / (1.5 * 10^(-4));
vector plus vector (in the same direction) is vector, so st is a vector.
contourf(st)
You are trying to contourf() a vector.
  댓글 수: 5
Walter Roberson
Walter Roberson 2024년 7월 30일
편집: Walter Roberson 2024년 7월 30일
Using meshgrid like that is not going to work. You have
st = (p + r) / (1.5 * 10^(-4));
and making p and r into grids cannot possibly give you the kind of curved output that you hope for.
clc;
clear all;
%-----Geometry, Number of simulations------%
d = 10;
N = 1;
a11 = 250 * (d / 10);
a12 = 100 * (d / 10);
%-----Mesh grid boundary definition--------%
xms = a11 / 2 - 2 * d;
xmf = a11 / 2 + 2 * d;
yms = a12 / 2 - 2 * d;
ymf = a12 / 2 + 2 * d;
%----------------Grid size----------------%
g = 0.085;
xq1 = xms:g:xmf;
xq = xq1';
yq1 = yms:g:ymf;
yq = yq1';
%-----Mesh grid around the hole----------%
[K1, K2] = meshgrid(xq, yq);
a = size(xq1, 2);
b = size(yq1, 2);
for k = 1:b
for j = 1:a
e = ((k * g) - 2 * d)^2 + ((j * g) - 2 * d)^2 - (0.5 * d)^2;
if e < 0
K1(j, k) = NaN;
K2(j, k) = NaN;
end
end
end
zz1 = 0;
zz2 = 0;
%----Importing files from Abaqus---------%
for i = 1:N
fx = ['aax' num2str(i) '.txt'];
fy = ['aay' num2str(i) '.txt'];
fu = ['aau1' num2str(i) '.txt'];
fv = ['aau2' num2str(i) '.txt'];
x = textfile(fx);
y = textfile(fy);
z1 = textfile(fu);
z2 = textfile(fv);
U1 = griddata(x, y, z1, K1, K2);
U2 = griddata(x, y, z2, K1, K2);
zz1 = U1 + zz1;
zz2 = U2 + zz2;
end
%--------Averaging the displacements-------%
zpk1 = zz1 / N;
zpk2 = zz2 / N;
xlswrite('zpk1.xlsx', zpk1)
Warning: Unable to write to Excel format, attempting to write file to CSV format.
xlswrite('zpk2.xlsx', zpk2)
Warning: Unable to write to Excel format, attempting to write file to CSV format.
%------Creating a strain matrix-----------%
E = zeros(2 * (size(K1, 1) - 1), 2 * (size(K1, 1) - 1));
for j = 1:(size(K1, 1) - 1)
for i = 1:(size(K1, 1) - 1)
v = [zpk1(j, i); zpk2(j, i); zpk1(j, i + 1); zpk2(j, i + 1); zpk1(j + 1, i + 1); zpk2(j + 1, i + 1); zpk1(j + 1, i); zpk2(j + 1, i)];
e1 = strain1(v);
e2 = strain2(v);
e3 = strain3(v);
e4 = strain4(v);
E((2 * j - 1), (2 * i - 1)) = e1(1);
E((2 * j - 1), 2 * i) = e2(1);
E(2 * j, (2 * i - 1)) = e4(1);
E(2 * j, 2 * i) = e3(1);
end
end
su = round(4 * d / g) + 1;
r = E((((su - 1) - round(d / g)):-1:1), (su - 1));
p = E((((su - 1) - round(d / g)):-1:1), su);
[r, p] = meshgrid(r,p);
st = (p + r) / (1.5 * 10^(-4));
m = g * (size(r, 1) - 1);
H = 0:g:m;
h = H / 10;
writematrix(st, 'st.txt')
writematrix(h, 'h.txt')
figure;
plot(h, st)
xlim([0 1.5])
xlabel("X2/d", 'fontsize', 14)
ylabel("Normalized Strain along vertical path", 'fontsize', 13)
legend("d/w = 0.5")
saveas(gcf, 'plot.png')
figure;
contourf(st)
colorbar
saveas(gcf, 'contour.png')
function E1 = strain1(v)
B1 = [1 0 0 0; 0 0 0 1; 0 1 1 0];
x1 = -1 / sqrt(3); eta1 = -1 / sqrt(3);
B21 = B2();
B31 = B3(x1, eta1);
B12 = B1 * B21;
B = B12 * B31;
E1 = B * v;
end
function E1 = strain2(v)
B1 = [1 0 0 0; 0 0 0 1; 0 1 1 0];
x1 = 1 / sqrt(3); eta1 = -1 / sqrt(3);
B21 = B2();
B31 = B3(x1, eta1);
B12 = B1 * B21;
B = B12 * B31;
E1 = B * v;
end
function E1 = strain3(v)
B1 = [1 0 0 0; 0 0 0 1; 0 1 1 0];
x1 = 1 / sqrt(3); eta1 = 1 / sqrt(3);
B21 = B2();
B31 = B3(x1, eta1);
B12 = B1 * B21;
B = B12 * B31;
E1 = B * v;
end
function E1 = strain4(v)
B1 = [1 0 0 0; 0 0 0 1; 0 1 1 0];
x1 = -1 / sqrt(3); eta1 = 1 / sqrt(3);
B21 = B2();
B31 = B3(x1, eta1);
B12 = B1 * B21;
B = B12 * B31;
E1 = B * v;
end
function B21 = B2()
B21 = [0.05 / 0.0025 0 0 0; 0 0.05 / 0.0025 0 0; 0 0 0.05 / 0.0025 0; 0 0 0 0.05 / 0.0025];
end
function B31 = B3(x1, eta1)
B31 = [...
-(1 - eta1) * 0.25 0 (1 - eta1) * 0.25 0 (1 + eta1) * 0.25 0 -(1 + eta1) * 0.25 0; ...
-(1 - x1) * 0.25 0 -(1 + x1) * 0.25 0 (1 + x1) * 0.25 0 (1 - x1) * 0.25 0; ...
0 -(1 - eta1) * 0.25 0 (1 - eta1) * 0.25 0 (1 + eta1) * 0.25 0 -(1 + eta1) * 0.25; ...
0 -(1 - x1) * 0.25 0 -(1 + x1) * 0.25 0 (1 + x1) * 0.25 0 (1 - x1) * 0.25];
end
function value = textfile(filename)
fileID = fopen(filename, 'r');
if fileID == -1
error('Failed to open file: %s', filename);
end
value = fscanf(fileID, '%f');
fclose(fileID);
end
Walter Roberson
Walter Roberson 2024년 7월 30일
Maybe you want to use r and p and some other variable as x, y, z vectors together with scatteredInterpolant() or gridddata()

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by