码迷,mamicode.com
首页 > 其他好文 > 详细

【气动学】基于matlab GUI外弹道仿真系统【含Matlab源码 1044期】

时间:2021-06-21 20:59:08      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:eval   efault   turned   ble   梯度   strong   output   fir   pre   

一、简介

1 设计要求及条件
技术图片
2 设计分析
技术图片

二、源代码

function varargout = simulation_GUI(varargin)
% SIMULATION_GUI M-file for simulation_GUI.fig
%      SIMULATION_GUI, by itself, creates a new SIMULATION_GUI or raises the existing
%      singleton*.
%
%      H = SIMULATION_GUI returns the handle to a new SIMULATION_GUI or the handle to
%      the existing singleton*.
%
%      SIMULATION_GUI(‘CALLBACK‘,hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SIMULATION_GUI.M with the given input arguments.
%
%      SIMULATION_GUI(‘Property‘,‘Value‘,...) creates a new SIMULATION_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before simulation_GUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to simulation_GUI_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 simulation_GUI

% Last Modified by GUIDE v2.5 09-Jun-2021 11:01:14

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct(‘gui_Name‘,       mfilename, ...
                   ‘gui_Singleton‘,  gui_Singleton, ...
                   ‘gui_OpeningFcn‘, @simulation_GUI_OpeningFcn, ...
                   ‘gui_OutputFcn‘,  @simulation_GUI_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 simulation_GUI is made visible.
function simulation_GUI_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 simulation_GUI (see VARARGIN)

% Choose default command line output for simulation_GUI
handles.output = hObject;
set(handles.hon,‘String‘,‘标准大气压hon=760mmHg‘);
set(handles.taoon,‘String‘,‘标准虚温τon=288.4℃‘);
set(handles.R,‘String‘,‘标准气体常数R=29.27‘);
set(handles.G,‘String‘,‘温度梯度G=5.6828e-3‘);
set(handles.eon,‘String‘,‘标准水蒸气分压eon=8.4mmHg‘);
set(handles.q,‘String‘,‘弹重q=216.5kg‘);
set(handles.d,‘String‘,‘弹径d=0.299m‘);
set(handles.L,‘String‘,‘弹长L=2.11m‘);
set(handles.gon,‘String‘,‘重力加速度g=760mmHg‘);
set(handles.Cxo,‘String‘,‘空气阻力系数Cxo=0.16‘);
set(handles.S,‘String‘,‘标准下落时间S=21.12秒‘);
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes simulation_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = simulation_GUI_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;


% --- Executes on button press in draw_2d.
function draw_2d_Callback(hObject, eventdata, handles)
% hObject    handle to draw_2d (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.z_inform,‘Visible‘,‘off‘);

set(handles.xend,‘String‘,0);
guidata(hObject, handles);
set(handles.yend,‘String‘,2000);
guidata(hObject, handles);
set(handles.zend,‘String‘,0);
guidata(hObject, handles);

u0 = str2num(get(handles.u0,‘String‘));
p0 = str2num(get(handles.p0,‘String‘));
x0 = str2num(get(handles.x0,‘String‘));
y0 = str2num(get(handles.y0,‘String‘));
fu=@(y,u,p)(-0.081931*(1-1.9705*10^(-5)*y)^6.0119/(288.4+5.6828*10^(-3)*(2000-y))*u^2);
fp=@(u)(9.806/u);
fx=@(u)(u);
fy=@(u,p)(u*p);

h=0.025;
N=1000;

T=zeros(1,N+1);
U=zeros(1,N+1);
P=zeros(1,N+1);
X=zeros(1,N+1);
Y=zeros(1,N+1);

U(1)=u0;
P(1)=p0;
X(1)=x0;
Y(1)=y0-y0;

for i=1:N
    fu1=feval(fu,Y(i),U(i),P(i));
    fp1=feval(fp,U(i));
    fx1=feval(fx,U(i));
    fy1=feval(fy,U(i),P(i));
    
    fu2=feval(fu,Y(i)+h/2*fy1,U(i)+h/2*fu1,P(i)+h/2*fp1);
    fp2=feval(fp,U(i)+h/2*fu1);
    fx2=feval(fx,U(i)+h/2*fu1);
    fy2=feval(fy,U(i)+h/2*fu1,P(i)+h/2*fp1);
    
    fu3=feval(fu,Y(i)+h/2*fy2,U(i)+h/2*fu2,P(i)+h/2*fp2);
    fp3=feval(fp,U(i)+h/2*fu2);
    fx3=feval(fx,U(i)+h/2*fu2);
    fy3=feval(fy,U(i)+h/2*fu2,P(i)+h/2*fp2);
    
    fu4=feval(fu,Y(i)+h*fy3,U(i)+h*fu3,P(i)+h*fp3);
    fp4=feval(fp,U(i)+h*fu3);
    fx4=feval(fx,U(i)+h*fu3);
    fy4=feval(fy,U(i)+h*fu3,P(i)+h*fp3);
    
    U(i+1)=U(i)+h*(fu1+2*fu2+2*fu3+fu4)/6;
    P(i+1)=P(i)+h*(fp1+2*fp2+2*fp3+fp4)/6;
    X(i+1)=X(i)+h*(fx1+2*fx2+2*fx3+fx4)/6;
    Y(i+1)=Y(i)+h*(fy1+2*fy2+2*fy3+fy4)/6;
    set(handles.xend,‘String‘,num2str(X(i)));
    guidata(hObject, handles);
    
    
end

l=find(Y>y0);
l=l(1);
U=U(1:l);
P=P(1:l);
X=X(1:l);
Y=Y(1:l);
U;
P;
X;
Y=y0-Y;

imge_2d=plot(X,Y,‘r‘);
labelx_2d=xlabel(‘X:Firing Range‘);
labely_2d=ylabel(‘Y:Firing Altitude‘);
handles.img_2d = imge_2d;%保存句柄
handles.img_2d = labelx_2d;
handles.img_2d = labely_2d;
str=get(handles.code_2d,‘String‘);
eval(str);
guidata(hObject,handles); 
xl = num2str(X(l));
set(handles.xend,‘String‘,xl);
guidata(hObject, handles);
set(handles.yend,‘String‘,0.000);
guidata(hObject, handles);



% --- Executes on button press in draw_3d.
function draw_3d_Callback(hObject, eventdata, handles)
% hObject    handle to draw_3d (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.xend,‘String‘,0);
guidata(hObject, handles);
set(handles.yend,‘String‘,2000);
guidata(hObject, handles);
set(handles.zend,‘String‘,0);
guidata(hObject, handles);

u0 = str2num(get(handles.u0,‘String‘));
p0 = str2num(get(handles.p0,‘String‘));
x0 = str2num(get(handles.x0,‘String‘));
y0 = str2num(get(handles.y0,‘String‘));
z0 = str2num(get(handles.z0,‘String‘));
fu=@(y,u,p)(-0.081931*(1-1.9705*10^(-5)*y)^6.0119/(288.4+5.6828*10^(-3)*(2000-y))*u^2);
fp=@(u)(9.806/u);
fx=@(u)(u);
fy=@(u,p)(u*p);
fz=@()(z0);

三、运行结果

技术图片
技术图片

四、备注

版本:2014a
完整代码或代写加1564658423

【气动学】基于matlab GUI外弹道仿真系统【含Matlab源码 1044期】

标签:eval   efault   turned   ble   梯度   strong   output   fir   pre   

原文地址:https://www.cnblogs.com/homeofmatlab/p/14914027.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!