绘制y=sin(x)/x的图形

  用Matlab里的GUI工具,可以绘制从函数y = sin(x)/x 在x∈【-100,100】,y∈【-0.24,1.1】下的曲线,并观察和推断当x –>+∞,x–>-∞,x–>∞, x –> 0-, x–> 0+, x –> 0时,函数的变化趋势。
  1)打开Matlab7.0,点击工具栏上的【File】–》 New –》GUI,命名为:jiXian.gif
  2)在jiXian.gif面板里,拖曳2个坐标系,3个按钮,如图(1)所示:

绘制y=sin(x)/x的图形_第1张图片 图(1) 用鼠标右键拖曳按钮,即为复制按钮,
  3)设置3个按钮的名称、标识
  三个按钮:comet、limit、close,如表(1)所示
   表(1) 3个按钮

名称 标识
按钮1 comet comet_pushButton
按钮2 limit limit_pushButton
按钮3 close close_pushButton

  修改按钮的属性,这里以【comet】按钮为例。双击按钮comet, 弹出Property Inspector对话框,修改String属性为:comet,Tag属性为: comet_pushButton,点击Callback属性 —>OK,如图(2)所示:
  

绘制y=sin(x)/x的图形_第2张图片 图(2) 修改按钮的String、Tag和Callback属性
  4)添加1个一级菜单,3个二级菜单
  一级菜单:File,二级菜单:comet、limit、close,如表(2)所示:
表(2) 4个菜单

名称 标识
一级菜单 File File_menu
二级菜单 comet comet_menu
二级菜单 limit limit_menu
二级菜单 close close_menu

  5)编写3个按钮和4个菜单的响应函数或脚本
  打开jiXian.m文件,编写按钮和菜单对应的函数
  代码如下:
  %%jiXian.m

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

% Last Modified by GUIDE v2.5 24-Nov-2015 18:30:05

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = jiXian_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 comet_pushButton.
function comet_pushButton_Callback(hObject, eventdata, handles)
% hObject    handle to comet_pushButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes1); 
x=-700:0.1:700;
box on;
hold on;
axis([-700 700 -0.24 1.1]);
comet(x,sin(x)./x);


% --- Executes on button press in limit_pushButton.
function limit_pushButton_Callback(hObject, eventdata, handles)
% hObject    handle to limit_pushButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
axes(handles.axes2); 
fplot('sin(x)./x',[-100 100 -0.24 1.1]);
text(30,0.5,'sin(x)/x');


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



% --------------------------------------------------------------------
function comet_menu_Callback(hObject, eventdata, handles)
% hObject    handle to comet_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
comet_pushButton_Callback(hObject, eventdata, handles)

% --------------------------------------------------------------------
function limit_menu_Callback(hObject, eventdata, handles)
% hObject    handle to limit_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
limit_pushButton_Callback(hObject, eventdata, handles)

% --------------------------------------------------------------------
function close_menu_Callback(hObject, eventdata, handles)
% hObject    handle to close_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close

% --------------------------------------------------------------------
function File_menu_Callback(hObject, eventdata, handles)
% hObject    handle to File_menu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

  效果如下:

绘制y=sin(x)/x的图形_第3张图片 图(3) 绘制y = sin(x)/x ,x∈【-100,100】
  由上图,可知,
   limx0sinxx=1 ,
   limx0+sinxx=1
   limx0sinxx=1
   limxsinxx=0 ,
   limx+sinxx=0 ,
   limxsinxx=0

你可能感兴趣的:(matlab,图形,极限,sinx)