w11 matlab graphics, Techniczne
[ Pobierz całość w formacie PDF ]
Adam Szustalewicz Matematyka obliczeniowa 2004/2005 W.11 15.12.2004 Wykład 11: Grafika dwuwymiarowa, parametry funkcyjne ... 1. Wielomian Narysujemy wykres wielomianu 8-go stopnia stosuj¡c arytmetyk¦ z ustalon¡ liczb¡ cyfr znacz¡cych. Do dyspozycji s¡ funkcje: zaokr – zaokr¡glaj¡ca liczby oraz wiel8 – korzystaj¡ca z funkcji poprzedniej przy obliczaniu warto±ci wielomianu. Matlab generuje automatycznie kilka obiektów: function y=zaokr(x,n) a=num2str(x,n); y=str2num(a); %-------------------- function y=wiel8(x,fa,nc); % fa = np. funkcja zaokr(x,nc) % nc - liczba cyfr znaczacych % wywolanie: y = wiel8(1.00123, ’zaokr’, 5); % asz 2004.12.13 a=[-8 28 -56 70 -56 28 -8 1]; for k=1:length(x) x(k)=feval(fa,x(k),nc); >> h=findobj h = 1.0e+002 * 0 0.01000000000000 1.12004272460937 1.07007324218750 1.04008544921875 1.00008056640625 1.13002929687500 1.08006347656250 1.05008789062500 1.01008178710938 end y=ones(1,length(x)); for i=1:length(a) for k=1:length(x) y(k)=feval(fa, feval(fa,x(k)*y(k),nc) + a(i), nc); end % y=feval(fa, feval(fa,s.*x,nc)+a(i), nc); end %---------------------------------------- % skrypt testowy swiel.m clc, clear, close all, x=linspace(0.98, 1.02, 101); figure(1) set(gcf,’color’,’w’); for nr=1:4 subplot(2,2,nr) y1=wiel8(x,’zaokr’,1+3*nr); plot(x,y1,’k’); axis([0.98 1.02 min(y1)*1.025 max(y1)*1.025]) at(nr)=title([’ y=(x-1)^8 lc=’,num2str(1+3*nr)],’FontSize’,10); if floor(nr/2)*2 ~= nr ay(nr)=ylabel(’y’,’fontsize’,16,’rotation’,0,... ’horizontalalignment’,... ’center’,’verticalalignment’,’bottom’,’fontangle’,’italic’); >> get(h,’type’) ans = ’root’ ’figure’ ’axes’ ’axes’ ’axes’ ’axes’ ’line’ ’line’ ’line’ ’line’ end if nr > 2 ax(nr)=xlabel(’ x’,’fontsize’,16,’horizontalalignment’,... ’left’,’verticalalignment’,’middle’,’fontangle’,’italic’); end end %----------------------------------------------------------------- 2. Wygodniejszy dost¦p do opisu osi mo»na uzyska¢ za pomoc ¡ obiektów: ay = 1.0e+002 * 1.03008911132813 0 1.10005371093750 ax = 1.0e+002 * 0 0 1.11004394531250 1.15004028320312 (jak wida¢ – itniej¡: ay (1), ay (3), ax (3)i ax (4).) 1 Adam Szustalewicz Matematyka obliczeniowa 2004/2005 W.11 15.12.2004 y=(x−1) 8 lc=4 x 10 −5 y=(x−1) 8 lc=7 0.01 1.5 0.005 1 y 0 0.5 0 −0.005 −0.5 −0.01 −1 −0.015 −1.5 0.98 0.99 1 1.01 1.02 0.98 0.99 1 1.01 1.02 x 10 −8 y=(x−1) 8 lc=10 1.5 x 10 −11 y=(x−1) 8 lc=13 1.5 1 1 0.5 0.5 y 0 0 −0.5 −0.5 −1 −1 −1.5 −1.5 0.98 0.99 1 1.01 1.02 0.98 0.99 1 1.01 1.02 x x 3. Mo»liwo±ci opisu osi OY: ay (1) >> set(ay(1)) BackgroundColor Color EdgeColor EraseMode: [ {normal} | background | xor | none ] Editing: [ on | off ] FontAngle: [ {normal} | italic | oblique ] FontName FontSize FontUnits: [ inches | centimeters | normalized | {points} | pixels ] FontWeight: [ light | {normal} | demi | bold ] HorizontalAlignment: [ {left} | center | right ] LineStyle: [ {-} | -- | : | -. | none ] LineWidth Margin Position Rotation String Units: [ inches | centimeters | normalized | points | pixels | characters | {data} ] Interpreter: [ {tex} | none ] 2 Adam Szustalewicz Matematyka obliczeniowa 2004/2005 W.11 15.12.2004 VerticalAlignment: [ top | cap | {middle} | baseline | bottom ] ButtonDownFcn: string -or- function handle -or- cell array Children Clipping: [ {on} | off ] CreateFcn: string -or- function handle -or- cell array DeleteFcn: string -or- function handle -or- cell array BusyAction: [ {queue} | cancel ] HandleVisibility: [ {on} | callback | off ] HitTest: [ {on} | off ] Interruptible: [ {on} | off ] Parent Selected: [ on | off ] SelectionHighlight: [ {on} | off ] Tag UIContextMenu UserData Visible: [ {on} | off ] 4. Aktualne warto±ci opisu osi OY: ay (1) >> get(ay(1)) BackgroundColor = none Color = [0 0 0] EdgeColor = none EraseMode = normal Editing = off Extent = [0.968261 -0.0024501 0.00282609 0.00525648] FontAngle = italic FontName = Helvetica FontSize = [16] FontUnits = points FontWeight = normal HorizontalAlignment = center LineStyle = - LineWidth = [0.5] Margin = [2] Position = [0.969836 -0.00204786 1.00011] Rotation = [0] String = y Units = data Interpreter = tex VerticalAlignment = bottom BeingDeleted = off ButtonDownFcn = Children = [] Clipping = off CreateFcn = DeleteFcn = BusyAction = queue HandleVisibility = off HitTest = on Interruptible = on Parent = [100.008] 3 Adam Szustalewicz Matematyka obliczeniowa 2004/2005 W.11 15.12.2004 Selected = off SelectionHighlight = on Tag = Type = text UIContextMenu = [] UserData = [] Visible = on 5. Mo»emy co± zmieni¢: ay (1) (warto obejrze¢ skutek) >> set(ay(1),’BackgroundColor’,[0.75,0.95,0]) >> set(ay(1),’Position’, [0.969136 -0.01204786 1.00011]) 6. Du»o trudniej jest dotrze¢ tam poprzez drzewo strukturalne: >> get(h(6)) ... YLabel = [103.009] ... >> get(h(6),’ylabel’) ans = 1.030089111328125e+002 >> get(1.030089111328125e+002) BackgroundColor = [0.75 0.95 0] Position = [0.969136 -0.0120479 1.00011] 7. Cz¦sto warto zmieni¢ opis siatki na posta¢ ła«cuchow¡ (Wykorzystamy równie» funkcj¦ axes ) clear, clc, close all figure(1) set(gcf,’color’,’w’); a2=axes(’position’,[0.1 0.1 0.3 0.4]); l1=line([0,1],[100,20]); l2=line([0,10],[10,-20]); hold on plot([1,2,3,4,5,6,7],[-10,0,20,100,60,30,0],’r:’) a1=axes(’position’,[0.3 0.3 0.6 0.6]); %h=findobj; %get(h,’type’) %hold on %subplot(2,1,1) l1=line([0,1],[100,20]); l2=line([0,10],[10,-20]); get(a2) disp(’--------------’) set(a2) %pause x=0:pi/16:4*pi; plot(x,sin(x)); axis([0 4*pi -1 1]) set(gca,’xtick’,[0:pi/2:4*pi]) axes(a2) %pause set(a1,’XTickLabel’,[’0|pi/2|pi|3pi/2|2pi|5pi/2|3pi|7pi/2|4pi’]) axes(a1) set(a1,’XTickLabel’,... str2mat(’0’,’pi/2’,’pi’,’3pi/2’,’2pi’,’5pi/2’,’3pi’,’7pi/2’,’4pi’)) set(a1,’XTickLabel’,... [’ 0 ’;’ pi/2 ’;’ pi ’;’3pi/2 ’;’ 2pi ’;’5pi/2 ’;’ 3pi ’;... ’7pi/2 ’;’ 4pi ’]) 4 Adam Szustalewicz Matematyka obliczeniowa 2004/2005 W.11 15.12.2004 8. Obrazki: 1 0.8 0.6 0.4 0.2 0 −0.2 100 −0.4 80 −0.6 60 −0.8 40 −1 0 1.5708 3.1416 4.7124 6.2832 7.854 9.4248 10.9956 12.5664 20 0 −20 0 2 4 6 8 10 1 0.8 0.6 0.4 0.2 0 −0.2 100 −0.4 80 −0.6 60 −0.8 40 0 pi/2 pi 3pi/2 2pi 5pi/2 3pi 7pi/2 4pi 20 0 −20 0 2 4 6 8 10 * * * 5 −1 [ Pobierz całość w formacie PDF ] |