绘制y=sin(x)/x的图形
来源:互联网 发布:竞品分析ppt模板 知乎 编辑:程序博客网 时间:2024/05/29 11:31
用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)所示:
3)设置3个按钮的名称、标识
三个按钮:comet、limit、close,如表(1)所示
修改按钮的属性,这里以【comet】按钮为例。双击按钮comet, 弹出Property Inspector对话框,修改String属性为:comet,Tag属性为: comet_pushButton,点击Callback属性 —>OK,如图(2)所示:
4)添加1个一级菜单,3个二级菜单
一级菜单:File,二级菜单:comet、limit、close,如表(2)所示:
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 EDITgui_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});endif 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 jiXianhandles.output = hObject;% Update handles structureguidata(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 structurevarargout{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)
效果如下:
由上图,可知,
1 0
- 绘制y=sin(x)/x的图形
- 绘制出y = sin x 和 y = cos x 同时显现的图像
- cos x 和sin x图形绘制
- 利用MATLAB绘制隐函数f(x,y)=x^2 * sin(x+y^2)+y^2 * exp(x+y)+5 * cos(x^2+y)=0的曲线
- 3绘制曲线y=x*x的图形与圆的图形叠加显示
- 绘制二元函数z=f(x,y)=(x^2-2*x)*exp(-x^2-y^2-x*y)的曲线及其三视图和三维表面图形
- R-求y=sin(X) 0-PI 面积代码
- bp网络算法对y=0.4sin(2*PI*x)+0.5的拟合
- bp网络算法对y=0.4sin(2*PI*x)+0.5的拟合
- 【狂人C】学习笔记之求封闭曲线y=sin(x)的面积
- 实现函数y=x*x的图形与圆的图形迭加显示
- sin(x)的实现
- x+=y与x=x+y的区别
- x+=y与x=x+y的区别
- 为什么x==y而cos(x) != cos(y)(或者sin,tan,log等其他浮点运算)?
- Cocos2d-x 图形绘制
- Cocos2d-x 绘制图形
- Cocos2d-x 图形绘制
- Windows下 python快速安装numpy、matplotlib、scikit-learn等库方法总结
- 白手起家学习数据科学 ——线性代数之“Vectors篇”(二)
- 【LEETCODE】206-Reverse Linked List
- 使用iOS 9 SDK添加Touch ID指纹识别功能
- PDP Context 激活流程(UE发起)
- 绘制y=sin(x)/x的图形
- volatile关键字作用
- IOS 观察者模式
- LightOJ 1036 - A Refining Company(DP)
- 最小圆覆盖——模板题
- python文件头--文件编码指定
- Oracle logminer使用方法总结
- Metronic V4.5.2 Responsive Admin Dashboard Template build with Twitter Bootstrap 3.3.5
- Android之ThreadPoolExecutor