MATLAB 板


LINE

程式有点长 请直接往下跳问题3Q function Conic_Sections clc format short t=linspace(0,2*pi,50); B=0; clc fprintf('Please enter the coefficients for the equation Ax^2 + Cy^2 +Dx + Ey + F = 0, element by element\n') A=input('A= '); C=input('C= '); D=input('D= '); E=input('E= '); F=input('F= '); if A==C if B==0 a=-(.5*D/A); b=-(.5*E/A); r=sqrt((F*-1)/A+a^2+b^2); if r<=0 fprintf('This is a point located at (%.02f,%.02f)\n',a,b) else x=a+r*cos(t); y=b+r*sin(t); plotgui axis equal grid on fprintf('The Conic Section is a Circle.\n') fprintf('The center of the circle is (%.2f,%.2f)\n',a,b) fprintf('The radius of the circle is %.02f\n',r) end end elseif B^2-4*A*C<0 fprintf('The Conic Section is an Ellipse.\n') ellipse(A,B,C,D,E,F) elseif B^2-4*A*C==0 fprintf('The Conic Section is a Parabola.\n') parabola(A,B,C,D,E,F) elseif B^2-4*A*C>0 fprintf('The Conic Section is a Hyperbola.\n') hyperbola(A,B,C,D,E,F) end function ellipse(A,B,C,D,E,F) t=linspace(-pi,pi,100); q=(F*-1)+(((.5*(D/A))^2)*A)+(((.5*(E/C))^2)*C); a=sqrt(abs(q/A)); b=sqrt(abs(q/C)); h=-(.5*D/A); k=-(.5*E/C); x=h+a*cos(t); y=k+b*sin(t); plotgui axis equal grid on fprintf('The center is at(%.2f,%.2f)\n',h,k) fprintf('The major axis is %0.0f units long\n',2*a) fprintf('The minor axis is %0.0f units long\n',2*b) end function hyperbola(A,B,C,D,E,F) e=.1; t=linspace(-pi/2+e,pi/2-e); t=[t,linspace(pi/2+.1,3*pi*2-e)]; q=(F*-1)+(((.5*(D/A))^2)*A)+(((.5*(E/C))^2)*C); a=sqrt(abs(q/A)); b=sqrt(abs(q/C)); h=-(.5*D/A); k=-(.5*E/C); if A>C x=a*sec(t)+h; y=b*tan(t)+k; else x=a*tan(t)+h; y=b*sec(t)+k; end plotgui xmin=h-2*a; xmax=h+2*a; ymin=k-2*b; ymax=k+2*b; axis([xmin,xmax,ymin,ymax]) axis equal fprintf('The center is at(%.2f,%.2f)\n',h,k) end function parabola(A,B,C,D,E,F) if C==0 d=D/-E; f=F/-E; s=A/-E; m=A/abs(E); h=-(.5*(d/s)); k=(f-(h^2*s)); xmin=h-5; xmax=h+5; x=linspace(xmin,xmax); y=m*(x-h).^2+k; fprintf('The vertex is (%.2f.%.2f).\n',h,k) elseif A==0 m=C/-D; n=E/-D; p=F/-D; q=C/abs(D); k=-(.5*(n/m)); h=(p-(k^2*m)); ymin=k-5; ymax=k+5; y=linspace(ymin,ymax); x=q*(y-k).^2+h; fprintf('The vertex is (%.2f,%.2f).\n',h,k) end plotgui axis equal grid on end function plotgui close all figure_color=[0.4,0.4,0.5]; panel_color=[0.4,0.4,0.6]; buttongroup_color=[0.6,0.6,0.7]; hfigure=figure('Units','pixels','position',[300 200 675 525],... 'color',figure_color, 'Toolbar','none','Numbertitle','off','MenuBar','none','Name','Conic Sections'); hAxes=axes('Parent',hfigure,'Units','Pixels',... 'Position',[50 50 425 425],'XGrid','On','YGrid','On'); hPanel=uipanel('Parent',hfigure,'Units','Pixels',... 'Position',[500 50 150 425],'BackgroundColor',panel_color); popup_group=uibuttongroup('Parent',hPanel,'Units','Pixels','Position',[10 200 130 215],... 'Backgroundcolor',buttongroup_color,'SelectionChangeFcn', @slider_callback); s1=uicontrol('Style','slider','Parent',popup_group,'Units','Pixels','Position',[5 30 115 20],... 'BackgroundColor',buttongroup_color,... 'Tag','GreenSlider', 'Min',0,'Max',1,'Callback', @slider_callback); s1b=uicontrol('Style','text','Parent',popup_group,'Units','Pixels','Position',[5 50 115 20],... 'String','Green','HorizontalAlignment','Left','BackgroundColor',buttongroup_color); s2=uicontrol('Style','slider','Parent',popup_group,'Units','Pixels','Position',[5 80 115 20],... 'Tag','RedSlider','BackgroundColor',buttongroup_color,... 'Min',0,'Max',1,'Callback', @slider_callback); s2b=uicontrol('Style','text','Parent',popup_group,'Units','Pixels','Position',[5 100 115 20],... 'String','Red','HorizontalAlignment','Left','BackgroundColor',buttongroup_color); s3=uicontrol('Style','slider','Parent',popup_group,'Units','Pixels','Position',[5 130 115 20],... 'Tag','BlueSlider','BackgroundColor',buttongroup_color,... 'Min',0,'Max',1,'Callback', @slider_callback); s3b=uicontrol('Style','text','Parent',popup_group,'Units','Pixels','Position',[5 150 115 20],... 'String','Blue','HorizontalAlignment','Left','BackgroundColor',buttongroup_color); r1b=uicontrol('Style','text','Parent',popup_group,'Units','Pixels','Position',[5 180 115 20],... 'String','Color','BackgroundColor',buttongroup_color); radiobuttongroup=uibuttongroup('Parent',hPanel,'Units','Pixels','Position',[10 10 130 180],... 'Backgroundcolor',buttongroup_color,'SelectionChangeFcn',@Linestyle_callback); r2=uicontrol('Style','Radio','Parent',radiobuttongroup,'Units','Pixels','Position',[5 140 115 20],... 'String','Solid','BackgroundColor',buttongroup_color); r3=uicontrol('Style','radio','Parent',radiobuttongroup,'Units','Pixels','Position',[5 110 115 20],... 'String','Dash/Dot','BackgroundColor',buttongroup_color); r4=uicontrol('Style','radio','Parent',radiobuttongroup,'Units','Pixels','Position',[5 80 115 20],... 'String','Dotted','BackgroundColor',buttongroup_color); r5=uicontrol('Style','radio','Parent',radiobuttongroup,'Units','Pixels','Position',[5 50 115 20],... 'String','Dashed','BackgroundColor',buttongroup_color); r6=uicontrol('Style','radio','Parent',radiobuttongroup,'Units','Pixels','Position',[5 20 115 20],... 'String','None','BackgroundColor',buttongroup_color); hline=plot(x,y,'color','k'); xlabel('X-Axis') ylabel('Y-Axis') title('Conic Sections') function Linestyle_callback(hObject,eventdata) linestyle=get(eventdata.NewValue,'String'); switch linestyle case 'Dashed' set(hline,'Linestyle','--') case 'Dash/Dot' set(hline,'Linestyle','-.') case 'Dotted' set(hline,'Linestyle',':') case 'Solid' set(hline,'Linestyle','-') case 'None' set(hline,'Linestyle','none') end end function slider_callback(hObject,eventdata) linecolor=get(hline,'Color'); slidertag=get(hObject,'Tag'); switch slidertag case 'RedSlider' linecolor(1)=get(hObject,'Value'); set(hline,'Color',linecolor) case 'GreenSlider' linecolor(2)=get(hObject,'Value'); set(hline,'Color',linecolor) case 'BlueSlider' linecolor(3)=get(hObject,'Value'); set(hline,'Color',linecolor) end end end end 这个程式下面有一个可以更改线条模式的 有四种 我想问一下如果我要增加的话 我需要修改哪边的程式 因为我直接改CASE的部分 最後没有出现 所以我想问一下要从那个部分新增! 3Q --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.211.30.228







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:iOS站内搜寻

TOP