- Mathematica code for exercise in section 3.3
- Mathematica code for exercises in section 3.4
- Mathematica code for exercises in NewtonÐRaphson Method

Chapter 3

**Mathematica code for exercise in section 3.3**

**22.**

> |
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); |

**Mathematica code for exercises in section 3.4**

**15.**

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)); |

**21.**

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); |

**Mathematica code for exercises in NewtonÐRaphson Method**

**2.**

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; |

**3.**

The following command will iterate NewtonÐRaphson 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; |

**4.**

The letter I designates the squareroot of Ð1

> |
f := 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; |

**9.**

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ÐRaphson 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; |