162 Nonlinear equations
25 out = x;
26
27 function out = getf(x)
28 out = sin(x) – x*cos(x);
29
30 function out = getdf(x)
31 out = x*sin(x);
The root for initial guess 4.000000 is 4.493409
(c) The files for this problem are contained in the folder s15c5p3 matlab.
The Matlab script is:
1function s15h5p3
2clc
3close all
4set(0,‘defaulttextinterpreter’,‘latex’)
5
6%get the first ten roots
17 npts = 101;
18 xmin = -0.1; % a bit before the trivial root
19 xmax = max(roots10) + 1; %slightly past the last root
20 x = linspace(xmin,xmax,npts);
21 for i = 1:npts
31 ylabel(‘$\sin x – x \cos x$’,‘FontSize’,14)
32 saveas(h,‘s15h5p3 solution figure1.eps‘,‘psc2’)
33
34 %get the first 150 roots