




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、上爆电力嗲陂高级程序设计(c ) 课程设计报告gui编程探讨n精度院 系 专业年级学生姓名指导教师计算机科学与技术学院信息安全2012级涂桂花学号:20123333魏为民2015年3月30円目录一、刻佥1二、实验内容和步骤11. 操作环境12. 系统配置13. 操作步骤14. 程序源代码4三、实验结果4测试数据4测试结果截图50.魏轉8附i 19上海电力学院实验报告课程名称慢a实验项目g.vl華潭坪:呼/.篼赛姓名涂桂花学号20123333 班级2012252 专业信息安全«響同组人姓名无指导教师魏为民 实验日期 2015.3.30一、实验目的1. 了解gui图形编辑窗口;2. 学会
2、使用gut图形编辑窗口实现函数图形的绘制;3. 通过gui图形编辑分析探讨pi的精度问题。二、实验内容和步骤如操作环境、系统配置、操作步骤、程序源代码等。1. 操作环境操作系统 windows 7旗舰版64位sp1 ( directx 11 )2. 系统配置处理器 amd el-2100 apu with radeon hd graphics 双核3. 操作步骤3. 1.打开 matlab,在 “command window” 窗口里输入 “guide”,冋车。如图 3. 1. 1 和图 3. 1. 2。图 3. 1. 1guide quick startcreate new guiopen
3、existing guiguide templates冰 gui with uicontrolsgui with axes and menu modal question dialogpreviewblankfi save new figure as: | e:matlab-newr2ollcibinmy3333pr | browse.okcancelhelp图 3. 1.23.2.点击图3. 1. 2的“ok”,打开空白的gui界面,如图3. 2. 1,建立如图3. 2. 2样式的gui界面图 3. 2. 1xrl pil234.figo图 3.2.23. 3. calc控件和exit控件分
4、别用gut界面的push buttonl來建立,建立好后,分别双击打开属性界 面,如图3. 3.1,设置相关属性值:calc和exit的string属性分别设置为calc和exit, calc和exit的tag 属性分别没置为pbtcalc和pbtexito图 3. 3. 1 fioff3. 4.点击gui界面的按钮建立n值的输入,默认输入100,双击修改相应的属性值,如图3.4.1.stringe ioostyleedittagedtlteration图 3.4.13. 5.点击gui界面的按钮建立公式的选择项盒,双击按图3.5.1和图3.5.2修改相应属性值。点击图 3.5.1中的u修改s
5、tring值。stringi string国 formulalstylelistboxtagibmethod阉 3.5.1ok cancel阁 3.5.2formulal £ormula2 formula3 formula tillnon*3.6. 选择gui界而的d按钮来建立4个静态文本输入框,string属性是 3.14159265358979323846264338327950288419716939937510582097494459230781640628,forcgroundco 1 or 颜色为红色;string 属性是 3.141592653589793, foreg
6、roundcolor 颜色为蓝色,tag 属性值为 txtmypi;string 属性是“公式选择”;string属性是“n值”。位置如图3.2.2所示位置。3.7. 选择gui界而的&按钮建立2个阁形绘制表格,如阁3.2.2。各个string属性设置分别为axresult 和 axformulao3.8. 石键点击exit选择view callbackscallback.,这时会跳岀问保存gui图形编辑界而的的位置,冈为 开始的时候没有建立新的工作路径和新的文件,所以我在这一步建立新的工作文件夹为“mypihomework2pi”, 此文件夹保存在e:matlab-newr2011a
7、bin目录下,然后在mypihomework2pi文件屮建立文件名为“pil234” 的.fig类型的gui图形文件。逮立好之后,就会自动打开文件名为pil234.m的edit编辑框,在该编辑框里编辑 要为上述控件添加的函数,函数的位置和具体a容根据程序源代码添加。3.9. callback函数编辑好后,有些控件还需要建立createfcn ,右键点击相应的控件选择view callbacks->createfcn,并添加函数,函数的位置和具体内容根据程序源代码添加。3.10. 将4 个求 pi 的函数公式阁像如阁 3.10.1 加载在 e:matlab-newr2011 abinmyp
8、ihomework2pi 目录下。/r. 111* 屋 + .mb . . . |4357<2-2 4.4r一繡,篇 a1i<a3j4l592653j|2 i.j j.3 5m?1,| f1耆,禱,1formulalformula2formula3formula4pi图 3.10.14. 程序源代码 见附件1。三、实验结果1. 测试数据求pt的公式:公式:公式:712x2 4x4 6x6=xxx 21x33x55x7公式:v.7- = l + (i) + (ix-) + (-x-x 233 53 5公式:f = (1+t>(1+$x(1+士)x."2. 测试结果截图
9、图1运行程序初始截图sle>3.141592653597932384624238327950288419716939937510520574944592307816406233.151493401070991406953680780134163796901702880859375公式乏孥formuial >formula2 formula 3 formula4 allinoncwo20406080100iteration1111h357图2执行公式的结果图3执行公式的结果3.1415926535979323e4243383279s028s4197169399375105820974
10、944592307816-i06283.1415926535897932384626433832795028s4197169399375105s20974w459230781640628620899862803482534211706798214806651328230664709334460955 公式遼驽aa 4,押< a mmm , am 外,錢錢钂我費我豢 mm mm m<3.31» formula-332 -12080100nffiformulal formula2formula3formula4allmone100gj4060iteration/t, 1、12
11、123、=i + () + ( x ) + ( x x ) +2335357pil23432图4执行公式的结果31415926535b979323352643383279502sa41s71939937510520974944592307816406283.133787490628161975791954318992793560028076171875sle>formula-4formula 1 >formula2formulasformulfl4asnonen001exit204060iteration80100712= (1 +)x(l + )x(l + ?-?)x.图5执行公
12、式的结果3.141592653s8979323s462433s32795o23s4l971693993751o582o974345923o7816io628pil234公式选戋anle>2.83.151493401070991406953680780134163796901702880859375nia6 4 2 禱3 3 33formula!formula2formulasformula4>allinone020406080100iteration= 3.1415926535calc图6把所有公式结合后比较不同公式n的精度的结果四.实验小结此次试验幵始的时候看着非常尖疼,不知道从
13、和下手,对matlab的阁形编辑界而的不熟悉使得试验过程 中遇到很多问题。但是耐心的分析老师给的模板和相应的程序后,经过自己的不断试验和测试终于弄明白每条语 句以及gui图形编辑每个控件的作用。最后终于顺利完成了试验。但是试验过程中也遇到了不少问题。以下就简 要列出试验屮我遇到的一些问题,和最后的解决方法。问题1、在第一次为exit空间添加退出窗口的提示的时候,不知道该添加在什么位賈。解决方法:exit确认見否退出提示的程序添加在exit的callback函数功能下而,exit的createan函数体在callback之后的任意位置即可。经过验证不添加createean也可以。问题2、在给ca
14、lc控件添加函数的时候,不知道该控件的函数是添加在exit控件函数之后还是之前,前后的不同是否会影响试验。同样,在给listbox选项控件添加函数的时候也遇到了位置选择的问题。解决方法:经过验证得知,calc控件以及listbox控件函数功能实现的程序添加位置与exit控件程序位置前后无关,不会影响实验的成功。同时calc控件和listbox控件的程序前后位罝也互不相互影响实验结果。 问题3、在txtmypi静态文本屮tag的属性值和函数体的名字不一致会导致无法得到公式计算后的pi值和绘图结果。同时listbox的属性style值被写成text也会出错即只显示第一个公式的二维图形。解决方法:遇
15、到该问题的时候,在执行程序过程中无法得到公式的閔形绘制结果,经过执行的阅读错误提示明白是在为txtmypi设賈tag属性值的时候将txtmypi写成了 txtmypi,导致无法得到公式图形,改正后运行问 题得到解决。同样,将listbox的style属性值改成listbox后,就不会只显示公式的图形结來了。在自己汄真耐心的坚持下以及同学的帮助下终于将此次试验成功完成。从屮收获了不少东西,并发现用matlab的gut绘制图形的便利。在以后的学j中应该多掌握熟练该方面的技能,运用到其他领域中将是个不错 的方法。附件1function varargout = untitled(varargin)%
16、untitled matlab code 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(1 callback 1,hobject,eventdata,handles, .) calls the local%function named callback
17、 in untitled.m with the given input arguments.%untitled(1 property 1, 1 value 1, .) creates a new untitled or raises the%existing singleton*. starting from the left, property value pairs are%applied to the gui before untitled_openingfcn gets called. an%unrecognized property name or invalid value mak
18、es property application%stop. all inputs are passed to untitled_openingfcn via varargin.%*see gui options on guide1s tools menu. choose ngui allows only one%instance to run (singleton)n.% see also: guide, guidata, guihandles % edit the above text to modify the response to help untitled % last modifi
19、ed by guide v2.5 30-mar-2015 19:24:35% begin initialization code - do not editguisingleton = 1;gui一state = struct(1gui_name1,mfilename,1gui_singleton1, gui_singleton,* gui_openingfcn1, untitled_openingfcn, 1gui一outputfcn1, untitled_outputfcn, 1gui_layoutfcn1, ,1gui_callback',);if nargin &&am
20、p; ischar (varargin1)gui_state.gui_callback = str2func (varargin1);end if nargoutvarargout1:nargout = gui_mainfcn(gui_state, varargin:); elsegui_mainfcn(gui_state, varargin:);enddo not edit% end initialization code% executes just before untitled is made visible.function untitled_openingfcn(hobject,
21、eventdata, handles, varargin) % this function has no output args, see outputfcn.% hobjecthandle to figure% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see gu工data) % varargin command line arguments to untitled (see varargin)% choose
22、 default command line output for untitledhandles.output = hobject;% update handles structureguidata(hobject, handles);% uiwait makes untitled wait for user response (see uiresume) % uiwait(handles.figurel);% outputs from this function are returned to the command line.function varargout = untitled_ou
23、tputfcn(hobject, eventdata, handles)% varargout cell array for returning output args (see varargout); % hobjecthandle 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 s
24、tructurevarargout1 = handles.output;% executes on selection change in lbmethod.function lbmethod一callback(hobject, eventdata, handles)% hobjecthandle to lbmethod (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles structure with handles and user data (see guidata)%
25、hints : contents = cellstr (get (hob ject, string 1 ) ) returns lbmethod contents as cell array %contentsget (hobject, 1 value 1) returns selected item from lbmethodimethod=round(get(handles.lbmethod, 1 value 丨);switch imethod case 1imformula=imread(1formulal.png 1); case 2imformula=imread(1formula2
26、.png 1); case 3imformula=imread(1formula3.png 1);case 4imformula=imread(1formula4.png 1); case 5imformula=imread(1 pi.png 1); otherwisereturn;endaxes(handles.axformula);clc;image(imformula);axis off;% executes during object creation, after setting all properties.function lbmethod一createfcn(hobject,
27、eventdata, handles)% hobjecthandle to lbmethod (see gcbo)% eventdata reserved - to be defined in a future version of matlab % handles empty - handles not created until after all createfcns called% hint: listbox controls usually have a white background on windows.%see ispc and computer.if ispc &&
28、amp; isequal(get(hobject,1backgroundcolor1)zget(0, 1defaultuicontrolbackgroundcolor1 ) set(hobject, 1backgroundcolor*, 1 white 1);end% executes on button press in pbtcalc.function pbtcalc_callback(hobject, eventdata, handles)% hob ject handle to pbtcalc (see gcbo)% eventdata reserved - to be defined
29、 in a future version of matlab % handles structure with handles and user data (see gu工data)% for i=l:100% mypi = formula3(i);%set(handles.txtmypi, 1 string,char(mypi);% endimethod=round(get(handles.lbmethod, 1 value 丨);n=round(str2num(get(handles.edtiteration, 1 string 1);% mypi = zeros(n, 1);switch
30、 imethod case 1for i=l:nmypi(i) = formulal(i);endslegend=1 formula-11; case 2for i=l:nmypi(i) = formula2(i);endslegend=1 formula-2 1;case 3for i=l:nmypi (i) = formula3(i);endslegend=1 formula-3 1; case 4for i=l:nmypi (i) = formula4(i);endf)slegend=1 formula-4 1; case 5h = waitbar(0, 1 please wait-.
31、for i=l:nmy pi (1,i) = formulal(i) my pi (2,i) = formula2(i) mypi(3,i) = formula3(i) mypi(4,i) = formula4(i) waitbar(i/n,h);end close(h);slegend=1 formula-1 1, 1 formula-2 1, 1 formula-3 1, 1 formula-4 1; otherwisedisp ( 1 unknown method. 1); return;end set(handles.txtmypi, 1 string 1,char(mypi(1,n)
32、;axes (handles.axresult);clc;plot(1:n,mypi);legend(slegend);xlabel(1 iteration );ylabel('value');line(1,n, pi,pi , 1 color , r, linestyle% executes on button press in pbtexit.function pbtexit_callback(hobject, eventdata, handles)% hobject handle to pbtexit (see gcbo)% eventdata reserved - to
33、 be defined in a future version of matlab % handles structure with handles and user data (see gu工data) q = questdlg(1 are you sure to exit ?丨,1figpi, 1 yes丨,丨no丨,no 1); if strcmp(q, 1 no 1)return;enddelete% clear temp filedelete(handles.figpi);%formulal%function mypi=formulal(n) p=l;a=l;b=l;item=l;f
34、=1; for i=l:nb=b+2;f=-f;item=f*(a/b); p=p+item;enddigits(256);p=vpa(p*4);mypi=p;%formula2%digits(10000);function mypi=formula2(n)%n=10000;p=l;%方法0for i=l:n a=i*2;p=p* ( (a*a)/ ( (2*i-l)* (2*i + l); enddigits(256);p=vpa(p*2);mypi=p;%formula3%digits(10000);function mypi=formula3(n)n=l;%方法1s=3;p=l;for
35、i=l:na=n;n=(i/(s+(i-l)*2)*a; p=n+p;enddigits(256); p=vpa(p*2); mypi=p;%formula4%digits(10000); function mypi=formu1a4(n)p=4/3;%方法 2for i=2:na= 2*i-l;p = p* (1 + 1/ (a* (a+2);enddigits(256);p=vpa(p*2);mypi=p;% executes during object creation, after setting all properties.function axresultcreatefcn(ho
36、bject, eventdata, handles)% hobject handle to axresult (see gcbo)% eventdata reserved - to be defined in a future version of matlab% handles empty - handles not created until after all createfcns called% hint: place code in openingfcn to populate axresultif ispc && isequal(get(hobject, 1backgroundcolor1 ),get(0,1defaultuicontrolbackgroundcolor1) set (hobject, 1backgroundcolor1, 1 white 1);end% executes during object creation, after setting al
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年模具设计工程师考试试题及答案
- 2025年家庭教育指导师考试题及答案
- 2025年货币政策与宏观经济管理能力的考试题及答案
- 2025年电子信息工程师考试试卷及答案
- 2025年公共卫生安全管理考试试题及答案
- 2025年甘肃省天水市秦安县中医医院招聘编外人员34人笔试参考题库及参考答案详解1套
- 物资采购公司管理制度
- 物资集散中心管理制度
- 特殊人员羁押管理制度
- 特殊工种人员管理制度
- 上海高一数学教材电子版
- 数字通信系统课件
- 内功四经内功真经真本全书
- 2021年度中国一线城市出行平台调研报告
- 贵州省毕节市各县区乡镇行政村村庄村名明细居民村民委员会
- 幼儿园小班社会:《红绿灯》 课件
- isa-381g站用变接地保护测控装置技术使用说明书南网版v3
- 六年级劳动教育7.青椒炒肉丝(课件)
- 油气藏类型、典型的相图特征和识别实例
- 《议程设置理论》
- 取力器的设计设计说明书
评论
0/150
提交评论