
StartX= %Our starting guess for the solution finds the following solution (Note that it’s only found one of the solutions, not all of them, which is typical of the type of algorithm used in fsolve) X = Now type the following at the MATLAB command prompt to actually solve the problem: options=optimset('Display','off') %Prevents fsolve from displaying too much information To solve this using MATLAB and the optimisation toolbox you could proceed as follows, first create a. you want to find a vector X containing three values for which F(X)=0. For many problems it will come down to a choice between the two ‘easy to use’ routines – c05nb and c05pb (at least, they are the ones I’ve used most of the time) So, the NAG routine you choose depends on whether or not you can supply first derivatives and exactly which options you’d like to exercise. These 6 routines are split into 2 sets of 3 as followsĬ05nb – Solution of system of nonlinear equations using function values only (easy-to-use)Ĭ05nc – Solution of system of nonlinear equations using function values only (comprehensive)Ĭ05nd – Solution of system of nonlinear equations using function values only (reverse communication)įor when you have both function values and first derivativesĬ05pb – Solution of system of nonlinear equations using first derivatives (easy-to-use)Ĭ05pc – Solution of system of nonlinear equations using first derivatives (comprehensive)Ĭ05pd – Solution of system of nonlinear equations using first derivatives (reverse communication)

The NAG Toolbox for MATLAB contains a total of 6 different routines that can perform similar calculations to fsolve. “fsolve Solves a system of nonlinear equation of the form F(X) = 0 where F and X may be vectors or matrices.” The fsolve function is part of MATLAB’s optimisation toolbox and, according to the documentation, it does the following:

Over the last year or so, I have managed to help several researchers get significant speed-ups in their MATLAB programs by doing one simple thing – swapping the fsolve function for an equivalent from the NAG Toolbox for MATLAB.


I employ numerous tricks to get these speed-ups including applying vectorisation, using mex files, modifying the algorithm to something more efficient,picking the brains of colleagues and so on. The users, however, are often happy with a lot less and I once got bought a bottle of (rather good) wine for a mere 25% speed-up (Note: Gifts of wine aren’t mandatory) One of the most common questions I get asked is ‘Can you make this go any faster please?’ and it always makes my day if I manage to do something significant such as a speed up of a factor of 10 or more.
#F solve matlab code#
Part of my job at the University of Manchester is to help researchers improve their code in systems such as Mathematica, MATLAB, NAG and so on.
