材料力学剪力图弯矩图绘制(有详细的程序)
说明:
输入变量:
分段数组x
分段点一般在集中力,集中力偶作用出和分布载荷的起末端。
载荷数组MPQ
若梁上的外载荷总数为PN ,则用PN 行四列的数组MPQ 储存载荷,数组MPQ 第一列代表载荷的类型:1为集中力偶,2为集中力,3为分布载荷,第二列代表载荷的大小,第三列代表集中力,集中力偶或者分布载荷左端与简支梁左端的距离,第四列代表均匀载荷右端与简支梁左端的距离,当载荷为集中力或者集中力偶时,第四列为0.
符号规定
集中力和均匀载荷向下为正,向上为负,集中力偶顺时针为正,逆时针为负。
输出变量:
内力数组XQM
如果梁被分为NN-1段,则内力数组XQM 为NN 行,三列的数组,第一列代表梁的横截面的位置,第二列代表剪力,第三列代表弯矩。
剪力极值及位置QDX
QDX 是一个二行二列的数组,第一列代表极值所在的位置,第二列代表极值
弯矩极值及位置MDX
MDX 是一个二行二列的数组,第一列代表极值所在的位置,第二列代表极值
1. 子程序
1.1集中力偶对弯矩贡献的子函数QMM
1.2集中力对剪力和弯矩贡献的子函数QMP
1.3分布载荷对剪力和弯矩贡献的子函数QMQ
1.4求剪力和弯矩极值的子函数MAX_MIN
1.5绘制剪力图和弯矩图的子函数TU_QM
2. 计算分析程序
2.1简支梁QMDJ
2.2左端固定悬臂梁QMDXZ
2.3右端固定悬臂梁QMDXY
2.4左端外伸梁QMDWZ
2.5右端外伸梁QMDWY
2.6两端外伸梁QMDWL
1. 子程序
1.1集中力偶对弯矩贡献的子函数QMM
function MM=QMM(n,x1,a,M,MM)
for j=1:n
if x1(j)==a
n1=j;
end
end
MM(n1:n)=MM(n1:n)+M;
1.2集中力对剪力和弯矩贡献的子函数QMP function [QQ,MM]=QMP(n,x1,b,P,QQ,MM)
for j=1:n
if x1(j)==b;
n1=j;
end
end
QQ(n1:n)=QQ(n1:n)-P;
MM(n1:n)=MM(n1:n)-P*(x1(n1:n)-b);
1.3分布载荷对剪力和弯矩贡献的子函数QMQ function [QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM) for j=1:n
if x1(j)>c
QQ(j)=QQ(j)-q*(x1(j)-c);
MM(j)=MM(j)-0.5*q*(x1(j)-c)^2;
end
if x1(j)>d
QQ(j)=QQ(j)+q*(x1(j)-d);
MM(j)=MM(j)+0.5*q*(x1(j)-d)^2;
end
end
1.4求剪力和弯矩极值的子函数MAX_MIN
function [QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM) XQM=[x1',QQ',MM'];
[Qmax,i]=max(QQ);
Q1=[Qmax,x1(i)];
[Qmin,i]=min(QQ);
Q2=[Qmin,x1(i)];
[Mmax,i]=max(MM);
M1=[Mmax,x1(i)];
[Mmin,i]=min(MM);
M2=[Mmin,x1(i)];
disp('剪力极值及位置')
QDX=[Q1;Q2]
disp('弯矩极值及位置')
MDX=[M1;M2]
t1=findobj(0,'Tag','text31');
str=num2str(Q1(1));
set(t1,'String',str);
t2=findobj(0,'Tag','text39');
str=num2str(Q1(2));
set(t2,'String',str);
t3=findobj(0,'Tag','text32');
str=num2str(Q2(1));
set(t3,'String',str);
t4=findobj(0,'Tag','text40');
str=num2str(Q2(2));
set(t4,'String',str);
m1=findobj(0,'Tag','text33');
str=num2str(M1(1));
set(m1,'String',str);
m2=findobj(0,'Tag','text41');
str=num2str(M1(2));
set(m2,'String',str);
m3=findobj(0,'Tag','text34');
str=num2str(M2(1));
set(m3,'String',str);
m4=findobj(0,'Tag','text42');
str=num2str(M2(2));
set(m4,'String',str);
1.5绘制剪力图和弯矩图的子函数TU_QM
function TU_QM(x1,QQ,MM)
h1=findobj(0,'Tag','axes1');
axes(h1);
plot(x1,QQ);
grid;
title('剪力图');
h2=findobj(0,'Tag','axes2');
axes(h2);
plot(x1,MM);
grid;
title('弯矩图');
2. 计算分析程序
2.1简支梁QMDJ
function XQM=QMDJ(x,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)];
end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[m,t]=size(MPQ);
[t,n]=size(x1);
for i=1:m
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
RA=-M/L;
QQ=QQ+RA;
MM=MM+RA*x1;
if a>0 & a
MM=QMM(n,x1,a,M,MM);
end
if a==0
MM=MM+M;
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
RA=(L-b)*P/L;
if b>0 & b
QQ=QQ+RA;
MM=MM+RA*x1;
[QQ,MM]=QMP(n,x1,b,P,QQ,MM); end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
RA=(L-0.5*(c+d))*q*(d-c)/L;
QQ=QQ+RA;
MM=MM+RA*x1+MA;
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM); TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
2.2左端固定悬臂梁QMDXZ
function XQM=QMDXZ(x,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)];
end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[PN,t]=size(MPQ);
[t,n]=size(x1);
for i=1:PN
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
if a>0 & a
MM=MM-M;
MM=QMM(n,x1,a,M,MM);
end
if a==L
MM=MM-M;
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
RA=P;
MA=-P*b;
QQ=QQ+RA;
MM=MM+RA*x1+MA;
if b>0 & b
[QQ,MM]=QMP(n,x1,b,P,QQ,MM);
end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
RA=q*(d-c);
MA=-0.5*q*(d-c)*(d+c);
QQ=QQ+RA;
MM=MM+RA*x1+MA;
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM); TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
2.3右端固定悬臂梁QMDXY
function XQM=QMDXY(x,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)];
end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[PN,t]=size(MPQ);
[t,n]=size(x1);
for i=1:PN
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
if a==0
MM=MM+M;
end
if a>0 & a
MM=QMM(n,x1,a,M,MM);
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
if b==0
QQ=QQ-P
MM=MM-P*x1;
end
if b>0 & b
[QQ,MM]=QMP(n,x1,b,P,QQ,MM);
end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM); TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
2.4左端外伸梁QMDWZ
function XQM=QMDWZ(x,L1,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)]; end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[PN,t]=size(MPQ);
[t,n]=size(x1);
for i=1:PN
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
if a>0 & a
MM=QMM(n,x1,a,M,MM);
end
if a==0
MM=MM+M;
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
RA=P*(L-b)/(L-L1);
[QQ,MM]=QMP(n,x1,L1,-RA,QQ,MM);
if b>0 & b
[QQ,MM]=QMP(n,x1,b,P,QQ,MM);
end
if b==0
QQ=QQ-P;
MM=MM-P*x1;
end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
b=(c+d)*0.5;
P=(d-c)*q;
RA=P*(L-b)/(L-L1);
[QQ,MM]=QMP(n,x1,L1,-RA,QQ,MM);
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM);
TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
2.5右端外伸梁QMDWY
function XQM=QMDWY(x,L1,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)]; end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[PN,t]=size(MPQ);
[t,n]=size(x1);
for i=1:PN
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
RA=-M/L1;
RB=-RA;
QQ=QQ+RA;
MM=MM+x1*RA;
if a>0 & a
MM=QMM(n,x1,a,M,MM);
end
if a==0
MM=MM+M;
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
RA=P*(L1-b)/L1;
RB=P*b/L1;
QQ=QQ+RA;
MM=MM+x1*RA;
[QQ,MM]=QMP(n,x1,L1,-RB,QQ,MM);
if b>0 & b
[QQ,MM]=QMP(n,x1,b,P,QQ,MM);
end
if b==0
QQ=QQ-P;
MM=MM-P*x1;
end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
b=(c+d)*0.5;
P=(d-c)*q;
RA=P*(L1-b)/L1;
RB=P*b/L1;
QQ=QQ+RA;
MM=MM+x1*RA;
[QQ,MM]=QMP(n,x1,L1,-RB,QQ,MM);
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM);
TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
2.6两端外伸梁QMDWL
function XQM=QMDWL(x,L1,L2,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)]; end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[PN,t]=size(MPQ);
[t,n]=size(x1);
for i=1:PN
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
RA=-M/(L2-L1);
RB=-RA;
if a>0 & a
MM=QMM(n,x1,a,M,MM); end
if a==0
MM=MM+M;
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
LL=L2-L1;
bb=b-L1;
RA=P*(LL-bb)/LL;
RB=P*bb/LL;
[QQ,MM]=QMP(n,x1,L1,-RA,QQ,MM);
[QQ,MM]=QMP(n,x1,L2,-RB,QQ,MM); if b>0 & b
[QQ,MM]=QMP(n,x1,b,P,QQ,MM); end
if b==0
QQ=QQ-P;
MM=MM-P*x1;
end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
b=(c+d)*0.5;
P=(d-c)*q;
LL=L2-L1;
bb=b-L1;
RA=P*(LL-bb)/LL;
RB=P*bb/LL;
[QQ,MM]=QMP(n,x1,L1,-RA,QQ,MM);
[QQ,MM]=QMP(n,x1,L2,-RB,QQ,MM);
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM);
TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
untitled.m
function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments. %
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 03-Jun-2008 23:12:06
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x=str2num(get(handles.edit2,'string'));
MPQ=str2num(get(handles.edit3,'string'));
L=str2num(get(handles.edit4,'string'));
L1=L(1);
L2=L(2);
val=get(handles.popupmenu1,'Value');
str=get(handles.popupmenu1,'String');
switch str{val}
case '简支梁'
QMDJ(x,MPQ)
case '左端固定悬臂梁'
QMDXZ(x,MPQ)
case '右端固定悬臂梁'
QMDXY(x,MPQ)
case '左端外伸梁'
QMDWZ(x,L1,MPQ)
case '右端外伸梁'
QMDWY(x,L1,MPQ)
case '两端外伸梁'
QMDWL(x,L1,L2,MPQ)
end
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all
% --- Executes on key press over popupmenu1 with no controls selected. function popupmenu1_KeyPressFcn(hObject, eventdata, handles) % hObject
% eventdata
% handles
handle to popupmenu1 (see GCBO) reserved - to be defined in a future version of MATLAB structure with handles and user data (see GUIDATA)
材料力学剪力图弯矩图绘制(有详细的程序)
说明:
输入变量:
分段数组x
分段点一般在集中力,集中力偶作用出和分布载荷的起末端。
载荷数组MPQ
若梁上的外载荷总数为PN ,则用PN 行四列的数组MPQ 储存载荷,数组MPQ 第一列代表载荷的类型:1为集中力偶,2为集中力,3为分布载荷,第二列代表载荷的大小,第三列代表集中力,集中力偶或者分布载荷左端与简支梁左端的距离,第四列代表均匀载荷右端与简支梁左端的距离,当载荷为集中力或者集中力偶时,第四列为0.
符号规定
集中力和均匀载荷向下为正,向上为负,集中力偶顺时针为正,逆时针为负。
输出变量:
内力数组XQM
如果梁被分为NN-1段,则内力数组XQM 为NN 行,三列的数组,第一列代表梁的横截面的位置,第二列代表剪力,第三列代表弯矩。
剪力极值及位置QDX
QDX 是一个二行二列的数组,第一列代表极值所在的位置,第二列代表极值
弯矩极值及位置MDX
MDX 是一个二行二列的数组,第一列代表极值所在的位置,第二列代表极值
1. 子程序
1.1集中力偶对弯矩贡献的子函数QMM
1.2集中力对剪力和弯矩贡献的子函数QMP
1.3分布载荷对剪力和弯矩贡献的子函数QMQ
1.4求剪力和弯矩极值的子函数MAX_MIN
1.5绘制剪力图和弯矩图的子函数TU_QM
2. 计算分析程序
2.1简支梁QMDJ
2.2左端固定悬臂梁QMDXZ
2.3右端固定悬臂梁QMDXY
2.4左端外伸梁QMDWZ
2.5右端外伸梁QMDWY
2.6两端外伸梁QMDWL
1. 子程序
1.1集中力偶对弯矩贡献的子函数QMM
function MM=QMM(n,x1,a,M,MM)
for j=1:n
if x1(j)==a
n1=j;
end
end
MM(n1:n)=MM(n1:n)+M;
1.2集中力对剪力和弯矩贡献的子函数QMP function [QQ,MM]=QMP(n,x1,b,P,QQ,MM)
for j=1:n
if x1(j)==b;
n1=j;
end
end
QQ(n1:n)=QQ(n1:n)-P;
MM(n1:n)=MM(n1:n)-P*(x1(n1:n)-b);
1.3分布载荷对剪力和弯矩贡献的子函数QMQ function [QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM) for j=1:n
if x1(j)>c
QQ(j)=QQ(j)-q*(x1(j)-c);
MM(j)=MM(j)-0.5*q*(x1(j)-c)^2;
end
if x1(j)>d
QQ(j)=QQ(j)+q*(x1(j)-d);
MM(j)=MM(j)+0.5*q*(x1(j)-d)^2;
end
end
1.4求剪力和弯矩极值的子函数MAX_MIN
function [QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM) XQM=[x1',QQ',MM'];
[Qmax,i]=max(QQ);
Q1=[Qmax,x1(i)];
[Qmin,i]=min(QQ);
Q2=[Qmin,x1(i)];
[Mmax,i]=max(MM);
M1=[Mmax,x1(i)];
[Mmin,i]=min(MM);
M2=[Mmin,x1(i)];
disp('剪力极值及位置')
QDX=[Q1;Q2]
disp('弯矩极值及位置')
MDX=[M1;M2]
t1=findobj(0,'Tag','text31');
str=num2str(Q1(1));
set(t1,'String',str);
t2=findobj(0,'Tag','text39');
str=num2str(Q1(2));
set(t2,'String',str);
t3=findobj(0,'Tag','text32');
str=num2str(Q2(1));
set(t3,'String',str);
t4=findobj(0,'Tag','text40');
str=num2str(Q2(2));
set(t4,'String',str);
m1=findobj(0,'Tag','text33');
str=num2str(M1(1));
set(m1,'String',str);
m2=findobj(0,'Tag','text41');
str=num2str(M1(2));
set(m2,'String',str);
m3=findobj(0,'Tag','text34');
str=num2str(M2(1));
set(m3,'String',str);
m4=findobj(0,'Tag','text42');
str=num2str(M2(2));
set(m4,'String',str);
1.5绘制剪力图和弯矩图的子函数TU_QM
function TU_QM(x1,QQ,MM)
h1=findobj(0,'Tag','axes1');
axes(h1);
plot(x1,QQ);
grid;
title('剪力图');
h2=findobj(0,'Tag','axes2');
axes(h2);
plot(x1,MM);
grid;
title('弯矩图');
2. 计算分析程序
2.1简支梁QMDJ
function XQM=QMDJ(x,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)];
end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[m,t]=size(MPQ);
[t,n]=size(x1);
for i=1:m
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
RA=-M/L;
QQ=QQ+RA;
MM=MM+RA*x1;
if a>0 & a
MM=QMM(n,x1,a,M,MM);
end
if a==0
MM=MM+M;
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
RA=(L-b)*P/L;
if b>0 & b
QQ=QQ+RA;
MM=MM+RA*x1;
[QQ,MM]=QMP(n,x1,b,P,QQ,MM); end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
RA=(L-0.5*(c+d))*q*(d-c)/L;
QQ=QQ+RA;
MM=MM+RA*x1+MA;
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM); TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
2.2左端固定悬臂梁QMDXZ
function XQM=QMDXZ(x,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)];
end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[PN,t]=size(MPQ);
[t,n]=size(x1);
for i=1:PN
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
if a>0 & a
MM=MM-M;
MM=QMM(n,x1,a,M,MM);
end
if a==L
MM=MM-M;
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
RA=P;
MA=-P*b;
QQ=QQ+RA;
MM=MM+RA*x1+MA;
if b>0 & b
[QQ,MM]=QMP(n,x1,b,P,QQ,MM);
end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
RA=q*(d-c);
MA=-0.5*q*(d-c)*(d+c);
QQ=QQ+RA;
MM=MM+RA*x1+MA;
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM); TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
2.3右端固定悬臂梁QMDXY
function XQM=QMDXY(x,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)];
end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[PN,t]=size(MPQ);
[t,n]=size(x1);
for i=1:PN
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
if a==0
MM=MM+M;
end
if a>0 & a
MM=QMM(n,x1,a,M,MM);
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
if b==0
QQ=QQ-P
MM=MM-P*x1;
end
if b>0 & b
[QQ,MM]=QMP(n,x1,b,P,QQ,MM);
end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM); TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
2.4左端外伸梁QMDWZ
function XQM=QMDWZ(x,L1,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)]; end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[PN,t]=size(MPQ);
[t,n]=size(x1);
for i=1:PN
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
if a>0 & a
MM=QMM(n,x1,a,M,MM);
end
if a==0
MM=MM+M;
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
RA=P*(L-b)/(L-L1);
[QQ,MM]=QMP(n,x1,L1,-RA,QQ,MM);
if b>0 & b
[QQ,MM]=QMP(n,x1,b,P,QQ,MM);
end
if b==0
QQ=QQ-P;
MM=MM-P*x1;
end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
b=(c+d)*0.5;
P=(d-c)*q;
RA=P*(L-b)/(L-L1);
[QQ,MM]=QMP(n,x1,L1,-RA,QQ,MM);
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM);
TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
2.5右端外伸梁QMDWY
function XQM=QMDWY(x,L1,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)]; end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[PN,t]=size(MPQ);
[t,n]=size(x1);
for i=1:PN
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
RA=-M/L1;
RB=-RA;
QQ=QQ+RA;
MM=MM+x1*RA;
if a>0 & a
MM=QMM(n,x1,a,M,MM);
end
if a==0
MM=MM+M;
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
RA=P*(L1-b)/L1;
RB=P*b/L1;
QQ=QQ+RA;
MM=MM+x1*RA;
[QQ,MM]=QMP(n,x1,L1,-RB,QQ,MM);
if b>0 & b
[QQ,MM]=QMP(n,x1,b,P,QQ,MM);
end
if b==0
QQ=QQ-P;
MM=MM-P*x1;
end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
b=(c+d)*0.5;
P=(d-c)*q;
RA=P*(L1-b)/L1;
RB=P*b/L1;
QQ=QQ+RA;
MM=MM+x1*RA;
[QQ,MM]=QMP(n,x1,L1,-RB,QQ,MM);
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM);
TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
2.6两端外伸梁QMDWL
function XQM=QMDWL(x,L1,L2,MPQ)
[n,m]=size(x);
L=x(m);
x1=[];
for i=1:m-1
x1=[x1,linspace(x(i),x(i+1),50)]; end
MM=zeros(size(x1));
QQ=zeros(size(x1));
[PN,t]=size(MPQ);
[t,n]=size(x1);
for i=1:PN
switch MPQ(i,1)
case 1
M=MPQ(i,2);
a=MPQ(i,3);
RA=-M/(L2-L1);
RB=-RA;
if a>0 & a
MM=QMM(n,x1,a,M,MM); end
if a==0
MM=MM+M;
end
case 2
P=MPQ(i,2);
b=MPQ(i,3);
LL=L2-L1;
bb=b-L1;
RA=P*(LL-bb)/LL;
RB=P*bb/LL;
[QQ,MM]=QMP(n,x1,L1,-RA,QQ,MM);
[QQ,MM]=QMP(n,x1,L2,-RB,QQ,MM); if b>0 & b
[QQ,MM]=QMP(n,x1,b,P,QQ,MM); end
if b==0
QQ=QQ-P;
MM=MM-P*x1;
end
case 3
q=MPQ(i,2);
c=MPQ(i,3);
d=MPQ(i,4);
b=(c+d)*0.5;
P=(d-c)*q;
LL=L2-L1;
bb=b-L1;
RA=P*(LL-bb)/LL;
RB=P*bb/LL;
[QQ,MM]=QMP(n,x1,L1,-RA,QQ,MM);
[QQ,MM]=QMP(n,x1,L2,-RB,QQ,MM);
[QQ,MM]=QMQ(n,x1,c,d,q,QQ,MM);
end
end
[QDX,MDX,XQM]=MAX_MIN(x1,QQ,MM);
TU_QM(x1,QQ,MM);
disp('梁的有限元分析结果')
disp('位置-----------剪力----------弯矩')
untitled.m
function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments. %
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 03-Jun-2008 23:12:06
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x=str2num(get(handles.edit2,'string'));
MPQ=str2num(get(handles.edit3,'string'));
L=str2num(get(handles.edit4,'string'));
L1=L(1);
L2=L(2);
val=get(handles.popupmenu1,'Value');
str=get(handles.popupmenu1,'String');
switch str{val}
case '简支梁'
QMDJ(x,MPQ)
case '左端固定悬臂梁'
QMDXZ(x,MPQ)
case '右端固定悬臂梁'
QMDXY(x,MPQ)
case '左端外伸梁'
QMDWZ(x,L1,MPQ)
case '右端外伸梁'
QMDWY(x,L1,MPQ)
case '两端外伸梁'
QMDWL(x,L1,L2,MPQ)
end
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all
% --- Executes on key press over popupmenu1 with no controls selected. function popupmenu1_KeyPressFcn(hObject, eventdata, handles) % hObject
% eventdata
% handles
handle to popupmenu1 (see GCBO) reserved - to be defined in a future version of MATLAB structure with handles and user data (see GUIDATA)