%Harjoitus4, läpilasku ja kommentteja >> %Kokeillaan (i) ja (ii) >> 2*rand(5,1)-1 ans = 0.9150 0.9298 -0.6848 0.9412 0.9143 >> 2*randn(5,1)-1 ans = -1.1261 0.4295 -1.4099 -1.2483 1.9794 >> %Ok, vastaukset ovat tällaisia. >> %Matriisin sarakkeiden keskiarvot antaa mean ja vektorin lukujen keskiarvon saa myös komennolla mean >> a=2*rand(2,2)-1 a = 0.5844 0.3115 0.9190 -0.9286 >> b=mean(a) b = 0.7517 -0.3085 >> c=mean(b) c = 0.2216 >> %Miten hyvin odotusarvo 0 pitää paikkansa? >> a=2*rand(10000)-1; %<- Kirjoitetaan ";", jotta arvot eivät tulostu >> mean(mean(a)) ans = -7.7689e-05 >> %Odotusarvo näyttää tosiaan olevan 0 >> a=2*randn(10000)-1; >> mean(mean(a)) ans = -1.0003 >> %(ii)-tapauksessa odotusarvo on -1, ok >> %Onko hajonta tosissaan 2? >> %Luetaan hajonnan(=varianssi?) määritelmä Wikipediasta: http://fi.wikipedia.org/wiki/Hajontaluku >> b=(a-1).^2; >> mean(mean(b)) ans = 8.0005 >> b=(a+1).^2; >> mean(mean(b)) ans = 3.9992 >> sqrt(mean(mean(b))) ans = 1.9998 >> %Ok, hajonta on 2 >> %Kokeillaan komentoja norm, norm(ma,1) ja norm(ma,inf) >> a=2*rand(2,2)-1 a = -0.6899 0.8111 -0.5360 -0.0147 >> norm(a) ans = 1.1247 >> norm(a,1) ans = 1.2259 >> norm(a,inf) ans = 1.5010 >> a=2*rand(100)-1; >> norm(a) ans = 11.3535 >> norm(a,1) ans = 57.7862 >> norm(a,inf) ans = 57.1286 >> a=2*rand(10000)-1; >> norm(a) EI HYVÄ! 10000 OLI LIIAN ISO LUKU! Matlab piti sammuttaa väkisin 30s jälkeen komennolla Ctrl+Alt+Del jne. Edes Ctrl+c ei auttanut, sillä Matlabin saa usein lopettamaan laskut x=linspace(-1,2);y=x.^3-4*x-1; plot(x,y) >> print -djpeg 'kuva_(a)' >> print -djpeg 'kuva_(a).jpg'' print -djpeg 'kuva_(a).jpg'' | Error: A MATLAB string constant is not terminated properly. >> print -djpeg 'kuva_a.jpg' >> t=linspace(0,2*pi); plot(cos(t),sin(t)) >> print -djpeg 'kuva_b.jpg' >> hold on >> x=linspace(-1,2);y=x.^3-4*x-1; plot(x,y) >> print -djpeg 'kuva_a&b1.jpg' >> %Säädellään kuvaa hieman >> axis equal >> axis([-2 1 -2 2]) >> xlabel('x-akseli')' ans = 175.0012 >> ylabel('y-akseli'); >> title('Käyrä ja yksikköympyrä samassa kuvassa') >> %Haluan saada tekstiä alkamaan pisteestä, jonka koordinaatit ovat -1.5,-1.5 >> [a,b]=ginput a = -1.4932 b = -1.5045 >> %"ammuin" hiirellä ja painoin Enteriä >> %Luen juuri ohjeita sivulta: http://www.mathworks.se/help/matlab/ref/text.html >> %Käytän komentoa text(x,y,'string') >> text(a,b,'Juha-Matin kuva') >> %Tallennetaan kuva .eps muodossa ja .jpg muodossa >> print -depsc 'kuva_a&b2.eps' >> print -djpeg 'kuva_a&b2.jpg' >> %Nyt kuva on helppo lähettää sähköpostilla jpg-muodossa ja lisätä Latex-dokumenttiin eps-muodossa >> %Latexilla voi tehdä lisää taikoja: http://tex.stackexchange.com/questions/17455/replacing-labels-in-eps-file-by-latex-text-not-where-it-should-be >> %>>> Ylimääräinen juttu >>> >> %>>>>>>>>>>>>>>>>>>>>>>>>>> >> %Kuvien muuttaminen jpg-muodosta eps-muotoon Matlabilla: >> %Tallensin kuvan http://felineaddiction.com/images/art/Wain_cat.jpg työkansiooni nimellä kisu.jpg >> kisu=imread(kisu,'jpg'); Undefined function or variable 'kisu'. >> kisu=imread('kisu','jpg'); >> image(kisu) >> image(kisu) >> [a,b]=ginput a = 144.4516 b = 231.0336 >> text(a,b,'valkea läikkä') >> [a,b]=ginput a = 106.5484 b = 294.3523 >> text(a,b,'<- tämän kuvan maalasi Louis Wain') >> print -djpeg 'kisu2.jpg' >> print -depsc 'kisu.eps' >> %Nyt voin laittaa kuvan kisu.eps Latexiin >> %>>> Palataan tehtäviin >>> >> %>>>>>>>>>>>>>>>>>>>>>>>>>> >> plot(x,y,'*') >> print -depsc 'kuva_c.eps' >> print -depsc 'kuva_d.jpg' >> v=sqrt(2*rand(5)-1) v = 0.7934 0 + 0.8972i 0 + 0.8275i 0 + 0.8463i 0.5581 0.9009 0 + 0.6656i 0.9701 0 + 0.3956i 0 + 0.9636i 0 + 0.8637i 0.3062 0.9562 0.9119 0.8356 0.9093 0.9566 0 + 0.1710i 0.7645 0.9317 0.5145 0.9642 0.7750 0.9586 0.5979 >> v=sqrt(2*rand(5,1)-1) v = 0.7180 0.6973 0 + 0.4643i 0.5576 0 + 0.8109i >> plot(v,'*') >> axis([-2 1 -2 2]) >> plot(0,0,'o') >> hold on >> plot(v,'*') >> axis([-2 1 -2 2]) >> [a,b]=ginput a = 0.0565 0.0565 b = -0.1228 -0.1579 >> [a,b]=ginput a = 0.0357 b = -0.1462 >> text(a,b,'\____origo on tuolla ja tämä on kompleksitaso') Warning: incomplete command in TeX text string: '\____origo on tuolla ja tämä on kompleksitaso' >> text(a,b,'^___origo on tuolla ja tämä on kompleksitaso') Warning: incomplete command in TeX text string: '^___origo on tuolla ja tämä on kompleksitaso' >> text(a,b,'origo') >> close >> plot(0,0,'o') >> hold on >> plot(v,'*') >> axis([-2 1 -2 2]) >> text(a,b,'origo') >> print -depsc 'kuva_e.jpg' %tehtävä 1 p=[1,2,3,4] p = 1 2 3 4 >> x=linspace(-2,2);y=polyval(p,x); >> plot(x,y) >> title('Tehtävän 1 esimerkkipolynomin p kuvaaja') >> print -djpeg 'h4t1.jpg' >> roots(p) ans = -1.6506 -0.1747 + 1.5469i -0.1747 - 1.5469i >> a=0*x; >> hold on >> plot(x,a,'r') >> [s,t]=ginput s = -1.6438 t = 0.0481 >> %Ok, p:n ensimmäinen juuri nähtäisiin kuvastakin >> b=roots(p) b = -1.6506 -0.1747 + 1.5469i -0.1747 - 1.5469i >> poly(b) ans = 1.0000 2.0000 3.0000 4.0000 >> q=[1 2;2 3]; >> y=polyval(q,[1,2]); Error using polyval (line 50) P must be a vector. >> roots(rand(1,5)) ans = 0.2865 + 0.5761i 0.2865 - 0.5761i -0.3090 + 0.4867i -0.3090 - 0.4867i >> roots(rand(1,5)) ans = -1.2515 0.2222 + 0.9286i 0.2222 - 0.9286i -0.0367 >> roots(rand(1,5)) ans = 0.1054 + 1.3094i 0.1054 - 1.3094i -0.7524 -0.3281 >> roots(rand(1,5)) ans = 0.3608 + 1.1185i 0.3608 - 1.1185i -0.8157 + 0.6710i -0.8157 - 0.6710i >> roots(rand(1,5)) ans = -1.2109 + 0.7746i -1.2109 - 0.7746i -0.0203 + 0.4563i -0.0203 - 0.4563i >> roots(rand(1,5)) ans = -1.8300 0.1486 + 0.7761i 0.1486 - 0.7761i -0.3930 >> %neljännen asteen satunnaisella polynomilla näyttäisi olevan aina neljä juurta >> %katsotaan asia 10000:ssa tapauksessa >> numel([1,2,3,4,5,6,7]) ans = 7 >> a=[1,2;2,3] a = 1 2 2 3 >> numel(a) ans = 4 >> %siis numel antaa matriisin alkioiden lukumäärän >> for k=1:10000 aste=round(10*rand(1))+2; b(k)=numel(roots(rand(aste+1)))-aste; end Error using roots (line 24) Input must be a vector. >> for k=1:10000 aste=round(10*rand(1))+2; b(k)=numel(roots(rand(aste+1)))-aste; end Error using roots (line 24) Input must be a vector. >> for k=1:10000 aste=round(10*rand(1))+2; b(k)=numel(roots(rand(1,aste+1)))-aste; end >> mean(b) ans = 0 >> max(b) ans = 0 >> min(b) ans = 0 >> %nyt vektorin b alkiot ovat kaikki nollia, siis 10000 tapauksessa kaikissa päti "Polynomin aste on sen juurien lukumäärä". >> p=[1 0 0] p = 1 0 0 >> roots(p) ans = 0 0 >> v=1+i v = 1.0000 + 1.0000i >> norm(v) ans = 1.4142 >> p=[1,2,3,4]; >> r1=max(1,2) r1 = 2 >> r1=max(1,sum(p)) r1 = 10 >> r2=max(1,sum(abs(p).^2)) r2 = 30 >> 1^2+2^2+3^2+4^2 ans = 30 >> %ok >> r3=1+max(abs(p)) r3 = 5 >> ok Undefined function or variable 'ok'. >> r1=max(1,sum(p)); >> r2=max(1,sum(abs(p).^2)); >> r3=1+max(abs(p)); >> r=min(1,2,3) Error using min MIN with two matrices to compare and a working dimension is not supported. >> r=min([1,2,3]) r = 1 >> r=min([r1,r2,r3]) r = 5 >> r1=max(1,sum(p)); >> r2=max(1,sum(abs(p).^2)); >> r3=1+max(abs(p)); >> r3=1+max(abs(p)); >> r1=max(1,sum(p)); >> r2=max(1,sum(abs(p).^2)); >> r3=1+max(abs(p)); >> r=min([r1,r2,r3]) r = 5 >> r1=max(1,sum(p)); r2=max(1,sum(abs(p).^2)); r3=1+max(abs(p)); r=min([r1,r2,r3]); >> p=rand(5,1); >> r1=max(1,sum(p)); r2=max(1,sum(abs(p).^2)); r3=1+max(abs(p)); r=min([r1,r2,r3]) r = 1.7995 >> roots(p) ans = 0.5461 + 1.0197i 0.5461 - 1.0197i -0.7298 + 0.4008i -0.7298 - 0.4008i >> norm(p) ans = 1.3415 >> abs(p) ans = 0.7055 0.2591 0.3083 0.8436 0.6543 >> abs(1+i) ans = 1.4142 >> %abs antaa siis kompleksiluvun modulin >> abs(p') ans = 0.7055 0.2591 0.3083 0.8436 0.6543 >> max(abs(p')) ans = 0.8436 >> r1=max(1,sum(p));r2=max(1,sum(abs(p).^2));r3=1+max(abs(p));r=min([r1,r2,r3]); >> for kertoimien_lkm=2:10 a=kertoimien_lkm; for k=1:10000 p=randn(5,1); r1=max(1,sum(p));r2=max(1,sum(abs(p).^2));r3=1+max(abs(p));r=min([r1,r2,r3]); c(k,a)=max(abs(p'))/r; end end >> mean([1 2 3; 4 5 6]) ans = 2.5000 3.5000 4.5000 >> mean([1 2 3; 4 5 6]') ans = 2 5 >> mean(c) ans = 0 1.3036 1.2967 1.2980 1.3015 1.3021 1.2957 1.2981 1.2920 1.2968 >> %KAAVASTA PUUTTUI ^0.5!!!!!!!!!!!!!!!!!!!!!!!!!!!! >> for kertoimien_lkm=2:10 a=kertoimien_lkm; for k=1:10000 p=randn(5,1); r1=max(1,sum(p));r2=max(1,sum(abs(p).^2))^0.5;r3=1+max(abs(p));r=min([r1,r2,r3]); c(k,a)=max(abs(p'))/r; end end >> mean(c) ans = 0 1.3174 1.3185 1.3123 1.3145 1.3154 1.3253 1.3012 1.3271 1.3095 >> for kertoimien_lkm=2:10 a=kertoimien_lkm; for k=1:10000 p=randn(5,1); r1=max(1,sum(abs(p)));r2=max(1,sum(abs(p).^2))^0.5;r3=1+max(abs(p));r=min([r1,r2,r3]); c(k,a)=max(abs(p'))/r; end end >> mean(c) ans = 0 0.7373 0.7343 0.7340 0.7354 0.7368 0.7346 0.7359 0.7359 0.7364 >> C=mean(c) C = 0 0.7373 0.7343 0.7340 0.7354 0.7368 0.7346 0.7359 0.7359 0.7364 >> C^2 Error using ^ Inputs must be a scalar and a square matrix. To compute elementwise POWER, use POWER (.^) instead. >> C.^2 ans = 0 0.5436 0.5392 0.5387 0.5408 0.5429 0.5397 0.5416 0.5415 0.5423 >> C.^0.5 ans = 0 0.8587 0.8569 0.8567 0.8575 0.8584 0.8571 0.8579 0.8578 0.8581 >> mean(mean(c)) ans = 0.6621 >> mean(mean(c(2:end))) ans = 0.6621 >> mean(mean(c(3:end))) ans = 0.6621 >> %näyttäisi siltä, että kiekko, jonka säde on 0.75r riittäisi >> p=randn(5,1)+randn(5,1)*i; >> p p = 0.5377 - 1.3077i 1.8339 - 0.4336i -2.2588 + 0.3426i 0.8622 + 3.5784i 0.3188 + 2.7694i >> for kertoimien_lkm=2:10 a=kertoimien_lkm; for k=1:10000 p=randn(5,1)+randn(5,1)*i; r1=max(1,sum(abs(p)));r2=max(1,sum(abs(p).^2))^0.5;r3=1+max(abs(p));r=min([r1,r2,r3]); c(k,a)=max(abs(p'))/r; end end >> mean(c) ans = 0 0.6968 0.6988 0.6982 0.6991 0.6984 0.6985 0.6979 0.6981 0.6980 >> mean(mean(c(2:end))) ans = 0.6284 >> C=mean(c) C = 0 0.6968 0.6988 0.6982 0.6991 0.6984 0.6985 0.6979 0.6981 0.6980 >> mean(C(2:end)) ans = 0.6982 >> min(C(2:end)) ans = 0.6968 >> for kertoimien_lkm=2:100 a=kertoimien_lkm; for k=1:100000 p=randn(5,1)+randn(5,1)*i; r1=max(1,sum(abs(p)));r2=max(1,sum(abs(p).^2))^0.5;r3=1+max(abs(p));r=min([r1,r2,r3]); c(k,a)=max(abs(p'))/r; end end >> for kertoimien_lkm=2:10 a=kertoimien_lkm; for k=1:100000 p=randn(5,1)+randn(5,1)*i; r1=max(1,sum(abs(p)));r2=max(1,sum(abs(p).^2))^0.5;r3=1+max(abs(p));r=min([r1,r2,r3]); c(k,a)=max(abs(p'))/r; end end >> C=mean(c) C = Columns 1 through 13 0 0.6983 0.6984 0.6983 0.6987 0.6985 0.6989 0.6987 0.6985 0.6985 0.6983 0.6982 0.6984 Columns 14 through 17 0.6981 0.6981 0.6985 0.6356 >> plot(1:length(C),C) >> C' ans = 0 0.6983 0.6984 0.6983 0.6987 0.6985 0.6989 0.6987 0.6985 0.6985 0.6983 0.6982 0.6984 0.6981 0.6981 0.6985 0.6356 >> format long >> C' ans = 0 0.698282012837824 0.698363752817972 0.698342915100173 0.698679018381431 0.698533044692707 0.698859083416552 0.698698037641449 0.698538810333346 0.698474426017543 0.698264489218283 0.698230226671242 0.698423818644136 0.698081644778173 0.698109362167603 0.698524718630943 0.635641220106702 >> format short >> atan(1) ans = 0.7854 >> x=linspace(-3,3);y=h4t3f(x);plot(x,y) >> nolla=0*x; >> hold on >> plot(x,nolla) >> %otetaan uusiksi >> close >> x=linspace(-10,10);y=h4t3f(x);plot(x,y) >> x=linspace(-100,100);y=h4t3f(x);plot(x,y) >> help linspace linspace Linearly spaced vector. linspace(X1, X2) generates a row vector of 100 linearly equally spaced points between X1 and X2. linspace(X1, X2, N) generates N points between X1 and X2. For N = 1, linspace returns X2. Class support for inputs X1,X2: float: double, single See also logspace, colon. Overloaded methods: distributed/linspace codistributor2dbc/linspace codistributor1d/linspace codistributed/linspace Reference page in Help browser doc linspace >> x=linspace(-100,100,10^6);y=h4t3f(x);plot(x,y) >> nolla=0*x; >> hold on >> plot(x,nolla,'r') >> print -djpeg 'h4t3f_kaukokuva.jpg' >> axis([-10 10 -40 40]) >> axis([-40 40 -10 10]) >> [a,b]=ginput a = -17.2350 -12.6267 -9.3088 -6.9124 -2.6728 -0.8295 3.5945 5.8065 10.2304 12.8111 b = -0.3801 -0.3216 -0.3801 -0.4386 -0.3801 -0.4386 -0.2632 -0.2632 -0.3216 -0.3216 >> length(a) ans = 10 >> for k=1:10 eval(['text(''' num2str(k) ''')']) end Error using text Invalid parameter/value pair arguments >> for k=1:10 eval(['text(' num2str(a(k)) ',' num2str(b(k)) ',' num2str(k) ''')']) end Error using text String argument expected after 2 or 3 numeric arguments >> for k=1:10 eval(['text(' num2str(a(k)) ',' num2str(b(k)) ',''' num2str(k) ''')']) end >> help text text Text annotation. text(X,Y,'string') adds the text in the quotes to location (X,Y) on the current axes, where (X,Y) is in units from the current plot. If X and Y are vectors, text writes the text at all locations given. If 'string' is an array the same number of rows as the length of X and Y, text marks each point with the corresponding row of the 'string' array. text(X,Y,Z,'string') adds text in 3-D coordinates. text returns a column vector of handles to text objects, one handle per text object. text objects are children of AXES objects. The X,Y pair (X,Y,Z triple for 3-D) can be followed by parameter/value pairs to specify additional properties of the text. The X,Y pair (X,Y,Z triple for 3-D) can be omitted entirely, and all properties specified using parameter/value pairs. Execute GET(H), where H is a text handle, to see a list of text object properties and their current values. Execute SET(H) to see a list of text object properties and legal property values. See also xlabel, ylabel, zlabel, title, gtext, line, patch. Reference page in Help browser doc text title Graph title. title('text') adds text at the top of the current axis. title('text','Property1',PropertyValue1,'Property2',PropertyValue2,...) sets the values of the specified properties of the title. title(AX,...) adds the title to the specified axes. H = title(...) returns the handle to the text object used as the title. See also xlabel, ylabel, zlabel, text. Reference page in Help browser doc title >> a=text(100,100,'aa') a = 191.0026 >> a=text(100,100,'aa') a = 192.0026 >> a=text(100,100,'aa') a = 193.0026 >> get(a) Annotation = [ (1 by 1) hg.Annotation array] BackgroundColor = none Color = [0 0 0] DisplayName = EdgeColor = none Editing = off Extent = [99.4023 99.0962 2.94253 1.04956] FontAngle = normal FontName = Helvetica FontSize = [10] FontUnits = points FontWeight = normal HorizontalAlignment = left LineStyle = - LineWidth = [0.5] Margin = [2] Position = [100 100 0] Rotation = [0] String = aa Units = data Interpreter = tex VerticalAlignment = middle BeingDeleted = off ButtonDownFcn = Children = [] Clipping = off CreateFcn = DeleteFcn = BusyAction = queue HandleVisibility = on HitTest = on Interruptible = on Parent = [173.003] Selected = off SelectionHighlight = on Tag = Type = text UIContextMenu = [] UserData = [] Visible = on >> [a,b]=ginput a = -16.6820 b = -4.0643 >> a=text(a,b,'aa') a = 194.0026 >> set(a,'BackGroundColor','[0.5 0.5 0.5]') Error using set Bad property value found. Object Name : text Property Name : 'BackgroundColor'. >> set(a,'BackgroundColor','[0.5 0.5 0.5]') Error using set Bad property value found. Object Name : text Property Name : 'BackgroundColor'. >> set('a','BackgroundColor','[0.5 0.5 0.5]') Error using set Value must be a handle >> set(a,'BackgroundColor','[0.5 0.5 0.5]') Error using set Bad property value found. Object Name : text Property Name : 'BackgroundColor'. >> set(a,'BackgroundColor',[0.5 0.5 0.5]) >> set(a,'FontSize',[20]) >> set(a,'Rotation',[pi]) >> set(a,'Rotation',[90]) >> set(a,'Rotation',[-90]) >> x=linspace(-100,100,10^6);y=h4t3f(x);plot(x,y) >> axis([-40 40 -10 10]) >> nolla=0*x; >> plot(x,nolla,'r') >> x=linspace(-100,100,10^6);y=h4t3f(x);plot(x,y) >> axis([-40 40 -10 10]) >> hold on >> nolla=0*x; >> plot(x,nolla,'r') >> for k=1:10 eval(['a' num2str(k) '=text(' num2str(a(k)) ',' num2str(b(k)) ',''' num2str(k) ''')']) eval(['set(a' num2str(k) ',''Rotation'',[-90])']) end a1 = 176.0045 Index exceeds matrix dimensions. >> for k=1:10 eval(['a' num2str(k) '=text(' num2str(a(k)) ',' num2str(b(k)) ',''' num2str(k) ''')']) eval(['set(a' num2str(k) ',''Rotation'',[-90])']) end a1 = 177.0045 Index exceeds matrix dimensions. >> [a,b]=ginput a = -11.9086 -9.8656 -6.1022 -2.9839 -0.3495 3.3602 6.1022 9.8656 11.9086 b = -0.0113 -0.0113 -0.0113 0.0113 -0.0339 -0.0339 -0.0113 -0.0113 -0.0566 >> for k=1:10 eval(['a' num2str(k) '=text(' num2str(a(k)) ',' num2str(b(k)) ',''' num2str(k) ''')']) eval(['set(a' num2str(k) ',''Rotation'',[-90])']) end a1 = 179.0045 a2 = 180.0045 a3 = 181.0045 a4 = 182.0045 a5 = 183.0045 a6 = 184.0045 a7 = 185.0045 a8 = 186.0045 a9 = 187.0045 Index exceeds matrix dimensions. >> a a = -11.9086 -9.8656 -6.1022 -2.9839 -0.3495 3.3602 6.1022 9.8656 11.9086 >> b b = -0.0113 -0.0113 -0.0113 0.0113 -0.0339 -0.0339 -0.0113 -0.0113 -0.0566 >> length(a) ans = 9 >> close >> x=linspace(-100,100,10^6);y=h4t3f(x);plot(x,y) >> axis([-40 40 -10 10]) >> hold on >> nolla=0*x; >> plot(x,nolla,'r') >> for k=1:9 eval(['a' num2str(k) '=text(' num2str(a(k)) ',' num2str(b(k)) ', ----------''' num2str(k) '.juuri'')']) eval(['set(a' num2str(k) ',''Rotation'',[-90])']) end Error using text String argument expected after 2 or 3 numeric arguments >> for k=1:9 eval(['a' num2str(k) '=text(' num2str(a(k)) ',' num2str(b(k)) ', ''----------' num2str(k) '.juuri'')']) eval(['set(a' num2str(k) ',''Rotation'',[-90])']) end a1 = 176.0065 a2 = 177.0065 a3 = 178.0065 a4 = 179.0065 a5 = 180.0065 a6 = 181.0065 a7 = 182.0065 a8 = 183.0065 a9 = 184.0065 >> x=linspace(-100,100,10^6);y=h4t3f(x);plot(x,y) >> hold on >> nolla=0*x; >> plot(x,nolla,'r') >> x=linspace(-100,100,10^6);y=h4t3f(x);plot(x,y) >> hold on >> nolla=0*x; >> plot(x,nolla,'r') >> axis([-40 40 -10 10]) >> for k=1:9 eval(['a' num2str(k) '=text(' num2str(a(k)) ',' num2str(b(k)) ', ---------------''' num2str(k) '.juuri'')']) eval(['set(a' num2str(k) ',''Rotation'',[-90])']) end Error using text String argument expected after 2 or 3 numeric arguments >> for k=1:9 eval(['a' num2str(k) '=text(' num2str(a(k)) ',' num2str(b(k)) ', ''---------------' num2str(k) '.juuri'')']) eval(['set(a' num2str(k) ',''Rotation'',[-90])']) end a1 = 176.0072 a2 = 177.0072 a3 = 178.0072 a4 = 179.0072 a5 = 180.0072 a6 = 181.0072 a7 = 182.0072 a8 = 183.0072 a9 = 184.0072 >> title('h4t3 funktion f juuret, joita on 9 kpl') >> print -djpeg 'h4t3f_lahikuva.jpg' >>