简体   繁体   English

使用Matlab绘制悬臂和梁图

[英]Plotting cantilever and beam plots using Matlab

Problem 问题

I have to plot a beam/cantilever using Matlab. 我必须使用Matlab绘制梁/悬臂。 Where my inputs are: 我的输入是:

  • Length of the beam 横梁长度
  • Position of the loads (input is a vector) 负载的位置(输入是向量)
  • Forces of the load (input is a vector) 负载力(输入为矢量)
  • Whether is it a cantilever or not. 它是否是悬臂的。 Because I have different equations for calculating the displacement. 因为我有不同的方程式来计算位移。

My Solution 我的解决方案

I have come to an idea on how I can actually plot the cantilever, but I can not formulate it into a code in MATLAB. 我对如何绘制悬臂图有了一个想法,但是我无法将其公式化为MATLAB中的代码。 I have spent hours trying to write something on Matlab but I have gotten nowhere. 我花了数小时试图在Matlab上写东西,但是却一无所获。 (I am a novice to Matlab) (我是Matlab的新手)

My solution is as follow: I have the formula for the displacement from starting position. 我的解决方案如下:我有从起始位置开始的位移公式。

I can define a vector using loop for x coordinates until the given beam length . 我可以使用x坐标的循环定义矢量,直到给定的光束长度 Hence, x=[0 ... L] 因此,x = [0 ... L]

Then I want to define another vector where the difference is calculated (this is where I can't figure out Matlab) 然后我想定义另一个矢量,在该矢量上计算差值(这是我无法弄清楚Matlab的位置)

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

where h is the starting height, which I have thought to be defined as (y(x1) - y(L)) + 1, so that the graph then doesn't go into the negative axes. 其中h是起始高度,我认为应将其定义为(y(x1)-y(L))+ 1,这样图形就不会进入负轴了。 y(x) is the function which will calculate the displacement or fall of the beam. y(x)是将计算梁的位移或下降的函数。

Once that is done, then I can simply plot(x,y) and that would give me a graph of a shape of deflected beam for the given range from 0 to beam length. 一旦完成,然后我可以简单地绘制(x,y),这将为我提供从0到光束长度的给定范围的偏转光束形状的图形。 I have tested my theory on excel and it works as per the graph is concerned but I can not figure out implementation on Matlab. 我已经在excel上测试了我的理论,并且可以按照图表进行操作,但是我无法弄清楚在Matlab上的实现。

My incomplete code 我的代码不完整

%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

Really need some help/guidance. 确实需要一些帮助/指导。 Would be truly grateful if someone can help me out or give me a hint :) 如果有人可以帮助我或给我一个提示,将不胜感激:)

I have edited the question with further details 我已详细编辑了问题

There are several things that do not work in your example. 在您的示例中,有些事情不起作用。 For instance, parameters should be defined BEFORE you use them, so E and I should be defined before the deflection equation. 例如,应在使用参数之前对其进行定义,因此应在挠曲方程之前定义E和I。 And you should define x. 并且您应该定义x。 I do not understand why you put your inputs whithin a while loop, if you stop it at length(a)>1; 我不明白为什么要以length(a)>1;停止输入,而又将其放入while循环中length(a)>1; . You can remove the loop. 您可以删除循环。 You do not need a loop to calculate displacements, you can just use a substraction between vectors, like displacement = 10 - y . 您不需要循环来计算位移,只需在向量之间使用减法即可,例如displacement = 10 - y However, I do not understand what is H in your example; 但是,我不理解您的示例中的H是什么。 since your beam is initially at position 0, your displacement is just -y . 由于光束最初位于位置0,因此位移为-y Finally, your equation to calculate the deformed shape is wrong; 最后,您计算变形形状的方程式是错误的; it only accounts for the first part of the beam. 它仅占光束的第一部分。

Here, try if this code works: 在这里,请尝试此代码是否有效:

%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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM