用Matlab绘制悬臂梁图
问题 我必须使用Matlab绘制一个梁/悬臂。我的输入是:用Matlab绘制悬臂梁图,matlab,plot,Matlab,Plot,问题 我必须使用Matlab绘制一个梁/悬臂。我的输入是: 梁的长度 荷载位置(输入为矢量) 荷载力(输入为矢量) 不管它是不是悬臂。因为我有不同的方程来计算位移 我的解决方案 我已经有了一个如何绘制悬臂梁的想法,但我无法在MATLAB中将其表述为代码。我花了几个小时试图在Matlab上写些东西,但我一无所获。(我是Matlab的新手) 我的解决方案如下:我有从起始位置的位移公式 我可以使用x坐标的循环定义一个向量,直到给定的波束长度。因此,, x=[0…L] 然后我想定义另一个向量,在这里
- 梁的长度
- 荷载位置(输入为矢量)
- 荷载力(输入为矢量)
- 不管它是不是悬臂。因为我有不同的方程来计算位移
我对问题进行了编辑,并提供了更多详细信息在您的示例中,有几点不起作用。 例如,参数应该在使用之前定义,所以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)
%梁的长度
l=输入('插入光束长度:');
%现在我们需要一个向量来表示负载的位置
a=输入('输入负载位置的坐标:');
%现在我们需要一个载荷的矢量
W=输入(“输入负载的力:”);
%定义公式
E=200*10^9;
I=0.001;
%沿梁的x位置
x=linspace(0,l,100);
b=l-a;
%荷载位置前的挠度
pos=xa;
y(pos)=((W*b)/(6*E*I*l)).*(l/b*(x(pos)-a.^3+(l^2-b^2)*x(pos)-x(pos)。^3;
%悬臂式期权
%y(pos)=W*a^2/(6*E*I)。*(3*x(pos)-a);
位移=10-y;%???
%图束
图形
绘图(x,x.*0,'k-')
等等
%绘图偏差
绘图(x,y,'-')
%绘图加载位置
%将箭头大小规格化为光束长度的1/10
颤动(a,0,0,符号(W)。*最大值(绝对值(y))/2)
在您的示例中,有几点不起作用。
例如,参数应该在使用之前定义,所以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)
%梁的长度
l=输入('插入光束长度:');
%现在我们需要一个向量来表示负载的位置
a=输入('输入负载位置的坐标:');
%现在我们需要一个载荷的矢量
W=输入(“输入负载的力:”);
%定义公式
E=200*10^9;
I=0.001;
%沿梁的x位置
x=linspace(0,l,100);
b=l-a;
%荷载位置前的挠度
pos=xa;
y(pos)=((W*b)/(6*E*I*l)).*(l/b*(x(pos)-a.^3+(l^2-b^2)*x(pos)-x(pos)。^3;
%悬臂式期权
%y(pos)=W*a^2/(6*E*I)。*(3*x(pos)-a);
位移=10-y;%???
%图束
图形
绘图(x,x.*0,'k-')
等等
%绘图偏差
绘图(x,y,'-')
%绘图加载位置
%将箭头大小规格化为光束长度的1/10
颤动(a,0,0,符号(W)。*最大值(绝对值(y))/2)
首先,不应将函数名length
用作变量。此外,您可以通过vectx=1:n
直接定义vectx
(假设您将第一行更改为n=str2double…
)。写y(x1)
时,您是指x
的第一个条目还是什么?您的问题是关于绘图,还是关于计算光束偏转?@Zep问题是关于绘图,因为我有偏转公式。@不可约的是,完全正确。抱歉搞混了。我有vectx=[x1,x2,x3..L],我想用它们来计算y=[h-y(x1),h-y(x2)…h-y(L)]。我唯一搞不清楚的是,我如何使用循环来计算函数的多个x值的输出?首先,你不应该使用函数名length
作为变量。此外,您可以通过vectx=1:n
(assum)直接定义vectx