Uporaba izpeljav 1. naloge v Octave / Use of derivations for the 1st exercise in Octave
First copy and paste the data into Octave:
octave:1> xi = [0.038; 0.194; 0.425; 0.626; 1.253; 2.5; 3.74];
octave:2> yi = [0.05; 0.127; 0.094; 0.2122; 0.2729; 0.2665; 0.3317];
and then define the functions \(\mathbf{F}\) and \(J\mathbf{F}\) corresponding to the problem of the 1st exercise:
octave:3> F = @(X) X(1)*xi./(X(2) + xi) - yi
octave:4> JF = @(X) [xi./(X(2) + xi), -X(1)*xi./(X(2) + xi).^2]
It never hurts to do a simple sanity check: Do the functions return values of appropriate dimensions? (\(\mathbf{F}\) should return a single column with 7 entries, \(J\mathbf{F}\) should return a \(2\times 7\) matrix.)
octave:5> F([0.5;0.5])All looks OK, now we run the Gauss-Newton iteration:
octave:6> JF([0.5; 0.5])
X = newton(F, JF, [0.5; 0.5])Let's plot the results to see if they make sense:
octave:7> x = linspace(0, 4);
octave:8> plot(xi, yi, 'o')
octave:9> hold on
octave:10> plot(x, X(1)*x./(X(2)+x))
Last modified: Tuesday, 24 March 2020, 4:26 PM