www.gusucode.com > 概率统计实验源程序 > 概率统计实验源程序/概率统计实验源程序(2007.8.9)/xiezhh6.m

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

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help xiezhh6

% Last Modified by GUIDE v2.5 07-Sep-2006 21:21:08

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

% Choose default command line output for xiezhh6
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = xiezhh6_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

edit_handle1=findobj(gcf,'tag','edit1');
n1=get(edit_handle1,'string');
n1=str2num(n1);
edit_handle2=findobj(gcf,'tag','edit2');
n2=get(edit_handle2,'string');
n2=str2num(n2);

if ~isempty(n1)&~isempty(n2)
    if n1<0|round(n1)~=n1|n2<=0|n2>=1
        warndlg('请输入正确的参数');
    else
        mu=n1*n2;
        sigma=sqrt(n1*n2*(1-n2));
        x=binoinv(0.001,n1,n2):binoinv(0.999,n1,n2);
        y=binopdf(x,n1,n2);
        stem(x,y,'fill','b')
        hold on
        x=binoinv(0.8,n1,n2);
        text(x+0.5,binopdf(x,n1,n2),['n=',num2str(n1),',','p=',num2str(n2),'二项分布(蓝)'])
        x=mu-3.2*sigma:6.4*sigma/100:mu+3.2*sigma;
        y=normpdf(x,mu,sigma);
        plot(x,y,'r')
        xlabel('X')
        ylabel('f(x)/P(x)')
        text(mu+0.5*sigma,0.95*normpdf(mu,mu,sigma),['\mu=',num2str(mu),',','\sigma=',num2str(sigma),'正态分布(红)'])               
    end
else
    warndlg('参数不能为空');
end

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

cla

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

close 棣莫弗—拉普拉斯中心极限定理
xiezhh4


function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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

edit1_handle=findobj(gcf,'tag','edit1');
set(edit1_handle,'string','')
edit2_handle=findobj(gcf,'tag','edit2');
set(edit2_handle,'string','')


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