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燈, 水草

請輸入看板名稱,例如:BuyTogether站內搜尋

TOP