% 假设 S1,S2,S3 分别为三个列向量 S = [S1(:), S2(:), S3(:)]; n = size(S, 1); % 获取网格点数 seq = zeros(n, 1); taumax = zeros(n, 1); for i = 1:n [~, D] = eig(reshape(S(i,:), 3, 3)); % 将 S 转换成方阵形式,并计算 eig sigma1 = D(3, 3); sigma2 = D(2, 2); sigma3 = D(1, 1); seq(i) = sqrt((sigma1 - sigma2)^2 + (sigma2 - sigma3)^2 + (sigma3 - sigma1)^2) / sqrt(2); taumax(i) = max(abs(sigma1 - sigma2), abs(sigma2 - sigma3), abs(sigma3 - sigma1)); end % 绘制 Mises 应力和 Tresca 应力在 pi 平面上的投影 figure; scatter(seq, taumax, 10, 'filled'); xlabel('Equivalent Stress \sigma_{eq}'); ylabel('Maximum Shear Stress \tau_{max}'); title('Mises and Tresca in Principal Stress Space'); grid on; % 绘制主应力坐标轴 hold on; plot([0 1], [0 0], '-k', 'LineWidth', 1); plot([0 0], [0 1], '-k', 'LineWidth', 1);这段代码提示错误使用reshape
时间: 2023-08-23 19:05:54 浏览: 181
这段代码中的错误可能是由于reshape函数的使用不正确导致的。在这段代码中,reshape函数被用来将一个行向量转换成一个3x3的矩阵,但是reshape函数的第一个参数应该是一个矩阵或向量,而不是一个行向量。因此,需要将S(i,:)改为reshape(S(i,:),[3,3])。修改后的代码如下:
```matlab
S1 = [1 2 3]';
S2 = [4 5 6]';
S3 = [7 8 9]';
S = [S1(:), S2(:), S3(:)];
n = size(S, 1);
seq = zeros(n, 1);
taumax = zeros(n, 1);
for i = 1:n
[~, D] = eig(reshape(S(i,:), [3,3]));
sigma1 = D(3, 3);
sigma2 = D(2, 2);
sigma3 = D(1, 1);
seq(i) = sqrt((sigma1 - sigma2)^2 + (sigma2 - sigma3)^2 + (sigma3 - sigma1)^2) / sqrt(2);
taumax(i) = max(abs(sigma1 - sigma2), abs(sigma2 - sigma3), abs(sigma3 - sigma1));
end
figure;
scatter(seq, taumax, 10, 'filled');
xlabel('Equivalent Stress \sigma_{eq}');
ylabel('Maximum Shear Stress \tau_{max}');
title('Mises and Tresca in Principal Stress Space');
grid on;
hold on;
plot([0 1], [0 0], '-k', 'LineWidth', 1);
plot([0 0], [0 1], '-k', 'LineWidth', 1);
```
阅读全文