【发布时间】: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 值的函数的输出?