MATLAB 程序yieldstress = 333.8624; %% Drucker-Prager parameter a1 = -0.1039; %% 坐标轴范围 limitxy = 500; %% vmc = @(x, y) sqrt(x.^2 - x.*y + y.^2)-yieldstress.*(1+a1*(-sqrt(3)/3)); % trc = @(x, y) 0.5 * max(cat(3, abs(x - y), abs(x), abs(y))-1, [], 3); xx = linspace(-limitxy, limitxy, 1000); yy = linspace(-limitxy, limitxy, 1000); [X, Y] = ndgrid(xx, yy); [C,h] = contour(X, Y, vmc(X, Y), [1 1]); % xlim([-limitxy, limitxy]); % ylim([-limitxy, limitxy]); w = h.LineWidth; h.LineWidth = 1; % h.LineStyle = ":"; h.EdgeColor = "b"; h.FaceColor = "r";,设定yieldstress为矩阵,并将程序简化
时间: 2024-02-26 17:55:34 浏览: 138
抱歉,您的代码中将 yieldstress 定义为标量而非矩阵。以下是将程序简化后的代码:
yieldstress = 333.8624;
a1 = -0.1039;
limitxy = 500;
vmc = @(x, y) sqrt(x.^2 - x.*y + y.^2) - yieldstress.*(1+a1*(-sqrt(3)/3));
xx = linspace(-limitxy, limitxy, 1000);
yy = linspace(-limitxy, limitxy, 1000);
[X, Y] = ndgrid(xx, yy);
[C, h] = contour(X, Y, vmc(X, Y), [1 1]);
h.LineWidth = 1;
h.EdgeColor = "b";
h.FaceColor = "r";
% xlim([-limitxy, limitxy]);
% ylim([-limitxy, limitxy]);
相关问题
%% constitutive model Drucker-Prager屈服函数 %% = (A+B(1+C*EXP(nε))*(1+b1*η) %% constitutive model Modified-Drucker-Prager屈服函数 ... %% = (A+B(1+C*EXP(nε))*(a1+a2*exp(a3η)) %% constitutive model parameter A=1; B=2; C=3; n=1; %% Drucker-Prager Parameter b1 = 0.1; %% Modified-Drucker-Prager Parameter a1 = 1; a2 = 2; a3 = 3; %% plastic strain ss = 1; %% stress state tria = sqrt(3)/3; %% Drucker-Prager屈服函数 f1 = (A+B(1+C*EXP(n*ss)))*(1+b1*tria); %% Modified-Drucker-Prager屈服函数 f2 = (A+B(1+C*EXP(n*ss)))*(a1+a2*exp(a3*tria)); 将这段程序改成,输入矩阵ss,求出f1和f2的值
可以将原有的程序改成以下形式:
```matlab
% constitutive model parameters
A = 1;
B = 2;
C = 3;
n = 1;
b1 = 0.1;
a1 = 1;
a2 = 2;
a3 = 3;
% input matrix ss
ss = [1 2 3; 4 5 6; 7 8 9];
% stress state tria
tria = sqrt(3)/3;
% calculate f1 and f2
f1 = (A + B.*(1+C.*exp(n.*ss))).*(1+b1.*tria);
f2 = (A + B.*(1+C.*exp(n.*ss))).*(a1+a2.*exp(a3.*tria));
```
这样,输入矩阵 `ss` 就可以是任意大小的矩阵,`f1` 和 `f2` 的值也会相应地计算出来,并以大小与 `ss` 相同的矩阵形式返回。
%% Drucker-Prager 参数 a=-0.1039; %% Modified Drucker-Prager 参数 a1=0.9954; a2=0.0046; a3=-5.65469; %% 二维Mises vmc = @(x, y) sqrt(x.^2 - x.y + y.^2)-1; %% 二维 Tresca trc = @(x, y) 0.5 * max(cat(3, abs(x - y), abs(x), abs(y))-1, [], 3); %% Drucker-Prager和Modified Drucker-Prager DruPra = @(x, y) sqrt(x.^2 - x.y + y.^2)(1+a(x+y)/2/ sqrt(x.^2 - x.*y + y.^2))-1; xx = linspace(-6, 6, 1000); yy = linspace(-6, 6, 1000); [X, Y] = ndgrid(xx, yy);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% contour(X, Y, vmc(X, Y), [1 1]) hold on contour(X, Y, trc(X, Y), [1 1]); hold on contour(X, Y, DruPra(X, Y), [1 1]); hold on % contour(X, Y, ModiDruPra(X, Y), [1 1]); title('Mises Yield Surface in 2D Principal Stress Space'); hold on,,给这段程序改成有求解容差的程序
可以将程序改写为以下形式,增加了一个函数 `DruPra_f` 用于计算 Drucker-Prager 函数值,同时在调用 `fminsearch` 函数时添加了选项 `options`,其中设定了求解容差。
```
% Drucker-Prager 参数
a = -0.1039;
% Modified Drucker-Prager 参数
a1 = 0.9954;
a2 = 0.0046;
a3 = -5.65469;
% 二维Mises
vmc = @(x, y) sqrt(x.^2 - x.*y + y.^2) - 1;
% 二维 Tresca
trc = @(x, y) 0.5 * max(cat(3, abs(x - y), abs(x), abs(y)) - 1, [], 3);
% Drucker-Prager函数
DruPra_f = @(x, y) sqrt(x.^2 - x.*y + y.^2) .* (1 + a * (x + y) / 2 / sqrt(x.^2 - x.*y + y.^2)) - 1;
% 设定求解容差
options = optimset('TolFun', 1e-6, 'TolX', 1e-6);
% 生成坐标网格
xx = linspace(-6, 6, 1000);
yy = linspace(-6, 6, 1000);
[X, Y] = ndgrid(xx, yy);
% 绘制等值线图
contour(X, Y, vmc(X, Y), [1 1])
hold on
contour(X, Y, trc(X, Y), [1 1])
hold on
contour(X, Y, DruPra(X, Y), [1 1])
hold on
% contour(X, Y, ModiDruPra(X, Y), [1 1]);
title('Mises Yield Surface in 2D Principal Stress Space')
hold on
% 求解 Drucker-Prager 函数值
x0 = [0, 0];
fminsearch(@(x) DruPra_f(x(1), x(2)), x0, options);
```
注意,在 `DruPra_f` 函数的定义中,需要将 `x.y` 改为 `x.*y`,否则会出现错误。
阅读全文