888888888888 88 ad8888ba, 88 88 ,d 8P' "Y8 88 88 88 d8 88 ,adPPYba, 88,dPPYba, MM88MMM 88,dd888bb, 88 a8P_____88 88P' "8a 88 88P' `8b 88 8PP""""""" 88 88 88 88 d8 88 "8b, ,aa 88 88 88, 888 88a a8P 88 `"Ybbd8"' 88 88 "Y888 888 "Y88888P" %funktio on Matlabissa nimellä h4t6.m >> fsolve(@h4t6,[0 0 0]) Equation solved. fsolve completed because the vector of function values is near zero as measured by the default value of the function tolerance, and the problem appears regular as measured by the gradient. ans = -1.6090 -1.2019 0.7941 >> %näin saatiin yksi ratkaisu >> fsolve(@h4t6,[1 1 1]) No solution found. fsolve stopped because the problem appears regular as measured by the gradient, but the vector of function values is not near zero as measured by the default value of the function tolerance. ans = 0.4121 2.4719 2.3808 >> %funktio on Matlabissa nimellä h4t6.m >> fsolve(@h4t6,[0 0 0]) Equation solved. fsolve completed because the vector of function values is near zero as measured by the default value of the function tolerance, and the problem appears regular as measured by the gradient. ans = -1.6090 -1.2019 0.7941 >> %funktio on Matlabissa nimellä h4t6.m >> ra1=fsolve(@h4t6,[0 0 0]) Equation solved. fsolve completed because the vector of function values is near zero as measured by the default value of the function tolerance, and the problem appears regular as measured by the gradient. ra1 = -1.6090 -1.2019 0.7941 >> %Matlab sanoo: "Equation solved.", joten tämän pitäisi olla oikea ratkaisu >> %Tarkistus: >> h4t6(ra1) ans = 1.0e-06 * 0.0523 -0.2779 0.1180 >> %Nähdään, että h4t6 on pisteessä ra1 melkein 0, joten saatiin oikea ratkaisu >> ra2=fsolve(@h4t6,[1 1 1]) No solution found. fsolve stopped because the problem appears regular as measured by the gradient, but the vector of function values is not near zero as measured by the default value of the function tolerance. ra2 = 0.4121 2.4719 2.3808 >> %Matlab sanoo: "No solution found." Siis lopputulos ei ole ratkaisu, Matlab vain lopetti iteroinnin siihen >> h4t6(ra2) ans = 5.5086 -0.1407 0.1478 >> %h4t6 ei ole 0 pisteessä ra2, joten ra2 ei ole ratkaisu >> ra3=fsolve(@h4t6,[-1 2 -4]) Equation solved. fsolve completed because the vector of function values is near zero as measured by the default value of the function tolerance, and the problem appears regular as measured by the gradient. ra3 = -1.6090 -1.2019 0.7941 >> ra1-ra3 ans = 1.0e-06 * -0.0770 0.2348 0.1735 >> %nyt saatiin siis sama ratkaisu, kuin aiemmin >> %alkuarvoja on ihmisen vaikea muuttaa satunnaisesti itse >> %käytetään for-silmukkaa for k=1:10 x=10*randn(1,3); a(k,:)=fsolve(@h4t6,x); end %TÄSTÄ TULEE RUMAA JÄLKEÄ. Muista Ctrl+c, jolla saat silmukan poikki. %alla esimerkkiajon antama vastaus a a = -1.9665 -0.1009 1.0144 -1.9665 -0.1009 1.0144 0.4121 2.4719 2.3808 -1.9665 -0.1009 1.0144 -1.9665 -0.1009 1.0144 0.4121 2.4719 2.3808 -1.6090 -1.2019 0.7941 -1.6090 -1.2019 0.7941 1.5237 -3.0136 1.6677 -1.9665 -0.1009 1.0144 b=round(a*10^4)/10^4 %pyöristetään a:n alkiot, että voidaan käyttää unique-komentoa b = -1.9665 -0.1009 1.0144 -1.9665 -0.1009 1.0144 0.4121 2.4719 2.3808 -1.9665 -0.1009 1.0144 -1.9665 -0.1009 1.0144 0.4121 2.4719 2.3808 -1.6090 -1.2019 0.7941 -1.6090 -1.2019 0.7941 1.5237 -3.0136 1.6677 -1.9665 -0.1009 1.0144 c=unique(b,'rows') c = -1.9665 -0.1009 1.0144 -1.6090 -1.2019 0.7941 0.4121 2.4719 2.3808 1.5237 -3.0136 1.6677 %löydettiin muka neljä ratkaisua %tarkistus: h4t6b(a) ans = 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 5.5086 -0.1407 0.1478 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 5.5086 -0.1407 0.1478 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 0.0000 0.0000 h4t6b(c) ans = -0.0001 0.0001 -0.0002 0.0006 -0.0000 -0.0000 5.5087 -0.1400 0.1480 -0.0001 0.0000 -0.0004 %nähdään, että c:n kolmas rivi ei ole ratkaisu! c=[c(1:2,:);c(4,:)] c = -1.9665 -0.1009 1.0144 -1.6090 -1.2019 0.7941 1.5237 -3.0136 1.6677 %kun kolmas rivi jätetään pois, jäävät jäljelle oikeat ratkaisut, joita löydettiin nyt kolme