## Primer reševanja naloge (14. teden) / Solution example (week 14)

Once we have derived the necessary systems of DEs and written necessary Octave functions, we can use them:

octave:1> izstrelek([pi/4; pi/4])octave:2> izstrelek([pi/3; pi/4])octave:3> izstrelek([pi/4; pi/3])

Since our target is at $$T(400, 300)$$, we define a function handle:

octave:4> F = @(kot) (izstrelek(kot) - [400; 300])

The methods 'secant', 'broyden', and 'dnewton' will find the zeros of this $$F$$. Let's start with the secant method:

octave:5> kot = secant([[pi/4; pi/4], [pi/3; pi/4], [pi/4; pi/3]], F, 1e-8, 100)

A quick test:

octave:6> izstrelek(kot)

For the Broyden method we run (and test):

octave:7> kot = broyden([pi/4; pi/4], F, 1e-8, 100)octave:8> izstrelek(kot)

And for the discretized Newton's method:

octave:9> kot = dnewton([pi/4; pi/4], F, 1e-8, 100)octave:10> izstrelek(kot)

We can also compare how much time each of those three methods consumes for this task (using tic; ...; toc):

octave:11> tic; kot = secant([[pi/4; pi/4], [pi/3; pi/4], [pi/4; pi/3]], F, 1e-8, 100); tococtave:12> tic; kot = broyden([pi/4; pi/4], F, 1e-8, 100); tococtave:13> tic; kot = dnewton([pi/4; pi/4], F, 1e-8, 100); toc

Last modified: Wednesday, 19 May 2021, 3:04 PM