% Example 15.1a (Physics 330) %********************************************************* % Uses fminsearch to look for solutions to the % nonlinear system of equations defined in the % file eqsystem.m %********************************************************* clear; itry=0; while itry ==0 disp(' Enter an initial guess for the solution') x=input('of the system of equations in the form [x1,x2,...] - '); % evaluate the scalar function S(x1,x2,...) so the % user can see how good the guess is s=eqsystem(x); fprintf(' For this guess: S(x1,x2,...) = %g \n',s) itry=input(' Enter 0 to guess again, 1 to try to solve with this guess- ') end x=fminsearch(@eqsystem,x) s=eqsystem(x); fprintf(' Final value of S(x1,x2,...) = %g \n',s) disp(' (Make sure it is close to zero)')