【问题标题】:Plotting cantilever and beam plots using Matlab使用 Matlab 绘制悬臂梁和梁图
【发布时间】:2017-11-23 16:49:45
【问题描述】:

问题

我必须使用 Matlab 绘制梁/悬臂梁。我的输入在哪里:

  • 梁的长度
  • 负载的位置(输入是矢量)
  • 负载力(输入为向量)
  • 是否为悬臂梁。因为我有不同的公式来计算位移。

我的解决方案

我已经想到了如何实际绘制悬臂梁,但我无法在 MATLAB 中将其表述为代码。我花了几个小时试图在 Matlab 上写一些东西,但我一无所获。 (我是 Matlab 新手)

我的解决方案如下:我有从起始位置位移的公式。

我可以使用循环为 x 坐标定义一个向量,直到给定 光束长度。因此, x=[0 ... L]

然后我想定义另一个计算差异的向量(这是我无法弄清楚Matlab的地方)

y = [h, h - y(x1), h - y(x2), .... h - y(L)]

其中 h 是起始高度,我认为将其定义为 (y(x1) - y(L)) + 1,这样图形就不会进入负轴。 y(x) 是计算梁的位移或下降的函数。

完成后,我可以简单地绘制(x,y),这将为我提供从 0 到光束长度的给定范围内偏转光束形状的图表。我已经在 excel 上测试了我的理论,它按照图表的方式工作,但我无法弄清楚在 Matlab 上的实现。

我的不完整代码

%Firstly we need the inputs

%Length of the beam
l = str2double(input('Insert the length of your beam: ', 's'));

%Now we need a vector for the positions of the load
a = [];
while 1
    a(end+1) = input('Input the coordinate for the position of your load: ');
    if length(a)>1; break; end
end

%Now we need a vector for the forces of the load
W = [];
while 1
    W(end+1) = input('Input the forces of your load: ');
    if length(W)>1; break; end
end

%
%
%
%Define the formula
y = ((W * (l - a) * x)/(6*E*I*l)) * (l^2 - x^2 - (l - a)^2);

%Where
E = 200*10^9;
I = 0.001;

%
%
%

%Now we try to plot
%Define a vector with the x values
vectx = [];
for i = 1:l
    vectx = [vectx i];
end

%Now I want to calculate displacement for each x value from vectx
vecty = [];
for i=1:l
    vecty=[10 - y(x(i)) i];
end

%Now I can plot all the information
plot(vectx, vecty)
hold on

%Now I plot the coordinate of the positions of the load
plot(load)
end

真的需要一些帮助/指导。如果有人可以帮助我或给我一个提示,我将不胜感激:)

我已经用更多细节编辑了问题

【问题讨论】:

  • 首先,不要使用函数名length作为变量。此外,您可以通过vectx=1:n 直接定义vectx(假设您将第一行更改为n=str2double ...)。写y(x1) 时,您的意思是x 的第一个条目还是什么?
  • 您的问题是关于情节,还是关于计算光束偏转?
  • @Zep 问题是关于情节的,因为我有偏转公式。
  • @Irreducible 是的。很抱歉造成混乱。我有 vectx=[x1, x2, x3 .. L] 并且我希望它们用于计算 y =[h - y(x1), h - y(x2) ... h - y(L)] .
  • 我唯一想不通的是如何使用循环来计算多个 x 值的函数的输出?

标签: matlab plot


【解决方案1】:

在您的示例中有几件事不起作用。 例如,参数应该在使用之前定义,所以 E 和 I 应该在挠度方程之前定义。你应该定义 x。 如果你在length(a)>1; 停止它,我不明白你为什么把你的输入放在一个while 循环中。您可以删除循环。 你不需要循环来计算位移,你可以在向量之间使用减法,比如displacement = 10 - y。但是,我不明白您的示例中的 H 是什么;由于您的光束最初位于位置 0,因此您的位移仅为-y。 最后,你计算变形形状的方程是错误的;它只占光束的第一部分。

在这里,试试这段代码是否有效:

%Length of the beam
l = input('Insert the length of your beam: ');

%Now we need a vector for the positions of the load
a = input('Input the coordinate for the position of your load: ');

%Now we need a vector for the forces of the load
W = input('Input the forces of your load: ');


%Define the formula
E = 200*10^9;
I = 0.001;
% x Position along the beam
x = linspace(0,l,100);

b = l - a;
% Deflection before the load position
pos = x <= a;
y(pos) = ((W * b .* x(pos))/(6*E*I*l)) .* (l^2 - x(pos).^2 - b^2);

% Cantilever option
% y(pos) = W*x(pos).^2/(6*E*I).*(3*a-x(pos));


% Deflection after the load position
pos = x > a;
y(pos) = ((W * b )/(6*E*I*l)) .* (l/b*(x(pos)-a).^3 + (l^2 - b^2)*x(pos) - x(pos).^3);
% Cantilever option
% y(pos) = W*a^2/(6*E*I).*(3*x(pos)-a);

displacement = 10 - y;  % ???


% Plot beam
figure
plot(x , x .* 0 , 'k-')
hold on;

% Plot deflection
plot(x , y , '--')

% Plot load position
% Normalize arrow size as 1/10 of the beam length
quiver(a , 0 , 0 , sign(W) .* max(abs(y))/2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-12
    • 1970-01-01
    • 2012-06-28
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多