octave:2> a=1e-10 a = 1.0000e-10 octave:3> b=1 b = 1 octave:4> c=1e-4 c = 1.0000e-04 octave:5> x1=(-b+sqrt(b^2-4*a*c))/(2*a) x1 = -9.9920e-05 octave:6> x2=(-b-sqrt(b^2-4*a*c))/(2*a) x2 = -1.0000e+10 octave:7> format long e octave:8> x1 x1 = -9.99200722162641e-05 octave:9> x2 x2 = -9.99999999999990e+09 octave:10> a*x1^2+b*x1+c ans = 7.99277837369190e-08 octave:11> a*x2^2+b*x2+c ans = 8.17871093750005e-07 octave:12> bisezione(@sin,0,pi,1e-6,10) ans = Columns 1 through 3: 0.00000000000000e+00 3.14159265358979e-02 6.28318530717959e-02 Columns 4 through 6: 9.42477796076938e-02 1.25663706143592e-01 1.57079632679490e-01 Columns 7 through 9: 1.88495559215388e-01 2.19911485751286e-01 2.51327412287183e-01 Columns 10 through 12: 2.82743338823081e-01 3.14159265358979e-01 3.45575191894877e-01 Columns 13 through 15: 3.76991118430775e-01 4.08407044966673e-01 4.39822971502571e-01 Columns 16 through 18: 4.71238898038469e-01 5.02654824574367e-01 5.34070751110265e-01 Columns 19 through 21: 5.65486677646163e-01 5.96902604182061e-01 6.28318530717959e-01 Columns 22 through 24: 6.59734457253857e-01 6.91150383789755e-01 7.22566310325652e-01 Columns 25 through 27: 7.53982236861550e-01 7.85398163397448e-01 8.16814089933346e-01 Columns 28 through 30: 8.48230016469244e-01 8.79645943005142e-01 9.11061869541040e-01 Columns 31 through 33: 9.42477796076938e-01 9.73893722612836e-01 1.00530964914873e+00 Columns 34 through 36: 1.03672557568463e+00 1.06814150222053e+00 1.09955742875643e+00 Columns 37 through 39: 1.13097335529233e+00 1.16238928182822e+00 1.19380520836412e+00 Columns 40 through 42: 1.22522113490002e+00 1.25663706143592e+00 1.28805298797182e+00 Columns 43 through 45: 1.31946891450771e+00 1.35088484104361e+00 1.38230076757951e+00 Columns 46 through 48: 1.41371669411541e+00 1.44513262065130e+00 1.47654854718720e+00 Columns 49 through 51: 1.50796447372310e+00 1.53938040025900e+00 1.57079632679490e+00 Columns 52 through 54: 1.60221225333079e+00 1.63362817986669e+00 1.66504410640259e+00 Columns 55 through 57: 1.69646003293849e+00 1.72787595947439e+00 1.75929188601028e+00 Columns 58 through 60: 1.79070781254618e+00 1.82212373908208e+00 1.85353966561798e+00 Columns 61 through 63: 1.88495559215388e+00 1.91637151868977e+00 1.94778744522567e+00 Columns 64 through 66: 1.97920337176157e+00 2.01061929829747e+00 2.04203522483337e+00 Columns 67 through 69: 2.07345115136926e+00 2.10486707790516e+00 2.13628300444106e+00 Columns 70 through 72: 2.16769893097696e+00 2.19911485751286e+00 2.23053078404875e+00 Columns 73 through 75: 2.26194671058465e+00 2.29336263712055e+00 2.32477856365645e+00 Columns 76 through 78: 2.35619449019234e+00 2.38761041672824e+00 2.41902634326414e+00 Columns 79 through 81: 2.45044226980004e+00 2.48185819633594e+00 2.51327412287183e+00 Columns 82 through 84: 2.54469004940773e+00 2.57610597594363e+00 2.60752190247953e+00 Columns 85 through 87: 2.63893782901543e+00 2.67035375555132e+00 2.70176968208722e+00 Columns 88 through 90: 2.73318560862312e+00 2.76460153515902e+00 2.79601746169492e+00 Columns 91 through 93: 2.82743338823081e+00 2.85884931476671e+00 2.89026524130261e+00 Columns 94 through 96: 2.92168116783851e+00 2.95309709437441e+00 2.98451302091030e+00 Columns 97 through 99: 3.01592894744620e+00 3.04734487398210e+00 3.07876080051800e+00 Columns 100 and 101: 3.11017672705390e+00 3.14159265358979e+00 octave:13> bisezione(@sin,0,pi,1e-6,10); octave:14> bisezione(sin,0,pi,1e-6,10); error: Invalid call to sin. Correct usage is: -- Mapping Function: sin (X) Additional help for built-in functions and operators is available in the online version of the manual. Use the command 'doc ' to search the manual index. Help and information about Octave is also available on the WWW at http://www.octave.org and via the help@octave.org mailing list. octave:14> miafunzione(2) ans = 4.93150590278539e-01 octave:15> bisezione(miafunzione,0,pi,1e-6,10); error: 'x' undefined near line 2 column 9 error: evaluating argument list element number 1 error: called from: error: /home/accounts/personale/clrmrc90/aa1819/calcolo_numerico1/miafunzione.m at line 2, column 3 error: evaluating argument list element number 1 octave:15> bisezione(@miafunzione,0,pi,1e-6,10); octave:16> nuovafunzione = @(x) exp(x)-sin(x); octave:17> nuovafunzione(1)ù error: invalid character 'Ã' (ASCII 195) near line 1, column 18 parse error: syntax error >>> nuovafunzione(1)ù ^ octave:17> nuovafunzione(1) ans = 1.87681084365115e+00 octave:18> bisezione(nuovafunzione,0,pi,1e-6,10); octave:19> bisezione(@(x) 1./(sin(x)+2),0,pi,1e-6,10); octave:20> bisezione(@sin,1,2,1e-6,10) error: bisezione: Nessuno zero nell'intervallo error: called from: error: /home/accounts/personale/clrmrc90/aa1819/calcolo_numerico1/bisezione.m at line 9, column 5 octave:20> bisezione(@sin,1,3*pi/2,1e-6,10) warning: bisezione: Raggiunto il numero massimo di iterazioni. ans = Columns 1 through 3: 2.85619449019234e+00 3.78429173528852e+00 3.32024311274043e+00 Columns 4 through 6: 3.08821880146639e+00 3.20423095710341e+00 3.14622487928490e+00 Columns 7 through 9: 3.11722184037564e+00 3.13172335983027e+00 3.13897411955758e+00 Column 10: 3.14259949942124e+00 octave:21> [x,its,delta]=bisezione(@sin,1,3*pi/2,1e-6,10) warning: bisezione: Raggiunto il numero massimo di iterazioni. x = Columns 1 through 3: 2.85619449019234e+00 3.78429173528852e+00 3.32024311274043e+00 Columns 4 through 6: 3.08821880146639e+00 3.20423095710341e+00 3.14622487928490e+00 Columns 7 through 9: 3.11722184037564e+00 3.13172335983027e+00 3.13897411955758e+00 Column 10: 3.14259949942124e+00 its = 1.00000000000000e+01 delta = Columns 1 through 3: 1.85619449019234e+00 9.28097245096172e-01 4.64048622548086e-01 Columns 4 through 6: 2.32024311274043e-01 1.16012155637022e-01 5.80060778185108e-02 Columns 7 through 9: 2.90030389092554e-02 1.45015194546277e-02 7.25075972731385e-03 Column 10: 3.62537986365692e-03 octave:22> bisezione(@sin,1,3*pi/2,1e-6,10) warning: bisezione: Raggiunto il numero massimo di iterazioni. ans = Columns 1 through 3: 2.85619449019234e+00 3.78429173528852e+00 3.32024311274043e+00 Columns 4 through 6: 3.08821880146639e+00 3.20423095710341e+00 3.14622487928490e+00 Columns 7 through 9: 3.11722184037564e+00 3.13172335983027e+00 3.13897411955758e+00 Column 10: 3.14259949942124e+00 octave:23> [x,its,delta]=bisezione(@sin,1,3*pi/2,1e-6,10); warning: bisezione: Raggiunto il numero massimo di iterazioni. octave:24> x x = Columns 1 through 3: 2.85619449019234e+00 3.78429173528852e+00 3.32024311274043e+00 Columns 4 through 6: 3.08821880146639e+00 3.20423095710341e+00 3.14622487928490e+00 Columns 7 through 9: 3.11722184037564e+00 3.13172335983027e+00 3.13897411955758e+00 Column 10: 3.14259949942124e+00 octave:25> errore=abs(pi-x); octave:26> semilogy(1:its,errore,'o',1:its,delta,'*') octave:27> legend('errore','delta') octave:28> xlabel('iterazioni') octave:29> ylabel('valori assoluti') octave:30> newton(@sin,@cos,3,1e-6,10) ans = 3.00000000000000e+00 3.14254654307428e+00 3.14159265330048e+00 octave:31> [x,its,delta]=newton(@sin,@cos,3,1e-6,10); octave:32> delta delta = 1.42546543074278e-01 -9.53889773801016e-04 2.89316249076218e-10 octave:33> semilogy(1:its,errore,'o',1:its,abs(delta),'*') error: __plt2vv__: vector lengths must match error: called from: error: /usr/share/octave/3.8.1/m/plot/draw/private/__plt__.m at line 484, column 5 error: /usr/share/octave/3.8.1/m/plot/draw/private/__plt__.m at line 243, column 14 error: /usr/share/octave/3.8.1/m/plot/draw/private/__plt__.m at line 113, column 17 error: /usr/share/octave/3.8.1/m/plot/draw/semilogy.m at line 60, column 10 octave:33> x x = 3.00000000000000e+00 3.14254654307428e+00 3.14159265330048e+00 octave:34> its its = 3.00000000000000e+00 octave:35> delta delta = 1.42546543074278e-01 -9.53889773801016e-04 2.89316249076218e-10 octave:36> octave:36> errore=abs(pi-x); octave:37> semilogy(1:its,errore,'o',1:its,abs(delta),'*') octave:38> errore errore = 1.41592653589793e-01 9.53889484484716e-04 2.89316126611538e-10 octave:39> delta delta = 1.42546543074278e-01 -9.53889773801016e-04 2.89316249076218e-10 octave:40> [x,its,delta]=bisezione(@sin,1,3*pi/2,1e-6,10); warning: bisezione: Raggiunto il numero massimo di iterazioni. octave:41> errore=abs(pi-x); octave:42> semilogy(1:its,errore,'o',1:its,delta,'*') octave:43> axis([0,10,1e-10,1]) octave:44> [x,its,delta]=newton(@sin,@cos,3,1e-6,10); octave:45> errore=abs(pi-x); octave:46> figure octave:47> semilogy(1:its,errore,'o',1:its,abs(delta),'*') octave:48> axis([0,10,1e-10,1]) octave:49> [x,its,delta]=newton(@sin,@(x) 2*cos(x),3,1e-6,10); % sbaglio appositamente la derivata warning: newton: Raggiunto il numero massimo di iterazioni. octave:50> xù error: invalid character 'Ã' (ASCII 195) near line 1, column 3 parse error: syntax error >>> xù ^ octave:50> x x = Columns 1 through 3: 3.00000000000000e+00 3.07127327153714e+00 3.10649103014786e+00 Columns 4 through 6: 3.12404905368178e+00 3.13282175366864e+00 3.13720731608831e+00 Columns 7 through 9: 3.13939999889503e+00 3.14049632799937e+00 3.14104449101420e+00 Column 10: 3.14131857232945e+00 octave:51> errore=abs(pi-x); octave:52> semilogy(1:its,errore,'o',1:its,abs(delta),'*') octave:53> [x,its,delta]=newton(@sin,@(x) -cos(x),3,1e-6,10); % sbaglio appositamente la derivata warning: newton: Raggiunto il numero massimo di iterazioni. octave:54> x x = Columns 1 through 3: 3.00000000000000e+00 2.85745345692572e+00 2.56541230869854e+00 Columns 4 through 6: 1.91568948427560e+00 -8.67872650396784e-01 -2.04809410653374e+00 Columns 7 through 9: -1.14535221736911e-01 -2.29573922004850e-01 -4.63267892244269e-01 Column 10: -9.62793336374198e-01 octave:55> diary off