Chapter 3
<Text-field layout="Section" style="Section">Mathematica code for exercise in section 3.3</Text-field>
<Text-field layout="Subsection" style="Subsection">22.</Text-field>f := (n, x) -> (ln(x+2)-x^(2*n)*sin(x))/(1+x^(2*n)) ;plot(f(2,x),x=0..1/2*Pi);plot(f(5,x),x=0..1/2*Pi);plot(f(10,x),x=0..1/2*Pi);plot(f(20,x),x=0..1/2*Pi);The command fsolve(f(x) = 0, x = a); finds a root of f near x=a.fsolve(f(2,x)=0,x=1);fsolve(f(5,x)=0,x=1);fsolve(f(10,x)=0,x=1);fsolve(f(20,x)=0,x=1);
<Text-field layout="Heading 1" style="Heading 1">Mathematica code for exercises in section 3.4</Text-field>
<Text-field layout="Heading 2" style="Heading 2">15.</Text-field>How are these solutions related to the value of x?fsolve(sin(1) = sin(1/c) - 1/c * cos(1/c));fsolve(sin(1/3) = sin(1/c) - 1/c * cos(1/c));fsolve(sin(0.01) = sin(1/c) - 1/c * cos(1/c));
<Text-field layout="Subsection" style="Subsection">21.</Text-field>The numpoints command gives somewhat greater detail in the plot. What parts of this graph might warrant studying in closer detail?plot(x/(1+x*sin(1/x)),x = 0 .. 1,numpoints = 500);Enter the following command to define a new function, F, that is the derivative of the given function.F := y -> eval(diff(x/(1+x*sin(1/x)),x),x = y);You can now draw the graph of F.plot(F(y),y = 0 .. 1);
<Text-field layout="Heading 1" style="Heading 1"><Font encoding="UTF-8">Mathematica code for exercises in Newton\342\200\223Raphson Method</Font></Text-field>
<Text-field layout="Heading 2" style="Heading 2"><Font executable="false">2.</Font></Text-field>If you define f(x), specify an initial value for x, and then define the command nr as given below, then each time you enter nr, Maple will perform another iteration of the Newton--Raphson method. To change the intial value of x, you need only define the new value.f := x -> x^3 - 4*x^2 - x + 2;x:= 4; for n from 1 to 10 do x := evalf(x - f(x)/D(f)(x),12) end do;
<Text-field layout="Heading 2" style="Heading 2">3.</Text-field>The following command will iterate Newton\342\200\223Raphson for each of the starting points.f := x -> sin(x) - x/2;x:=0.84; for n from 1 to 10 do x := evalf(x - f(x)/D(f)(x),12) end do;
<Text-field layout="Heading 2" style="Heading 2">4.</Text-field>The letter I designates the squareroot of \342\200\2231f := x -> sin(x) - x/2;x:=0.84+0.1*I; for n from 1 to 10 do x := evalf(x - f(x)/D(f)(x),12) end do;
<Text-field layout="Subsection" style="Subsection">9.</Text-field>Find the range of values of x at which there could be a root. Use a plot command to find approximate values of these roots. Then use Newton\342\200\223Raphson to find roots to 10-digit accuracy.f := cos(3*x)-x;x:= 4; for n from 1 to 10 do x := evalf(x - f(x)/D(f)(x),12) end do;