s10 - Ma 449: Numerical Applied Mathematics Model Solutions...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Ma 449: Numerical Applied Mathematics Model Solutions to Homework Assignment 10 Prof. Wickerhauser Exercise 1* of Section 8.1, pp.427--428. (a) f'(x) = 6x^2-18x+12 = 6(x-1)(x-2), so f(x) increases on (-infty, 1) where f'(x) > 0; decreases on (1, 2) where f'(x) < 0; increases on (2, infty) where f'(x) > 0. (b) f'(x)=1/(x+1)^2 >0, so f(x) increases on R - {-1} (c) This is the reciprocal of the function in part (b). It decreases where the part (b) function increases, so f(x) decreases on R - {-1}. (d) f(x)=x^x = exp(x log x), so f'(x) = (1+log x) exp(x log x), so f(x) decreases on (0, 1/e), where f'(x)<0 increases on (1/e, infty), where f'(x)>0. Exercise 2(b) of Section 8.1, pp.427--428. Observe that cos(x) is decreasing on [0, pi] and increasing on [pi, 2*pi], and that 0 < pi < 4 < 2*pi. Conclude that f is unimodal on [0,4] with a unique minimum at pi. Exercise 7(d*) of Section 8.1, pp.427--428. C PROGRAM: /* Golden ratio search with N iterations for the minimum of a function f(x) unimodal on [a0,b0] */ #include <assert.h> #include <math.h> #include <stdio.h> double f(double x) { return -sin(x)-x+x*x/2; } double a0=0.8, b0=1.6; int N=20; /* number of iterations */ main() { double a, b, c, d, fa, fb, fc, fd; const double r=(sqrt(5.0)-1)/2; /* golden ratio */ int k; a=a0; b=b0; fa=f(a); fb=f(b); /* initialize */ c=r*a+(1-r)*b; d=r*b+(1-r)*a; fc=f(c); fd=f(d); /* a < c < d < b */ for(k=0; k<N; k++) { printf("k=%d: a[%d]=%.4f, b[%d]=%.4f\n", k, k,a, k,b); if( fc > fd ) { /* ==> min lies in [c,b] */ a=c; c=d; d=r*b+(1-r)*a; /* b is still the same */ fa=fc; fc=fd; fd=f(d); /* f(b) is still the same */ } else { /* min lies in [a,d] */ b=d; d=c; c=r*a+(1-r)*b; /* a is still the same */ fb=fd; fd=fc; fc=f(c); /* f(a) is still the same */ } } return 0; } OUTPUT: k=0: a[0]=0.8000, b[0]=1.6000 k=1: a[1]=1.1056, b[1]=1.6000 k=2: a[2]=1.1056, b[2]=1.4111 k=3: a[3]=1.2223, b[3]=1.4111 k=4: a[4]=1.2223, b[4]=1.3390 k=5: a[5]=1.2669, b[5]=1.3390 k=6: a[6]=1.2669, b[6]=1.3115 k=7: a[7]=1.2669, b[7]=1.2944 k=8: a[8]=1.2774, b[8]=1.2944 k=9: a[9]=1.2774, b[9]=1.2879 k=10: a[10]=1.2814, b[10]=1.2879 k=11: a[11]=1.2814, b[11]=1.2854 k=12: a[12]=1.2830, b[12]=1.2854 k=13: a[13]=1.2830, b[13]=1.2845 k=14: a[14]=1.2830, b[14]=1.2839 k=15: a[15]=1.2833, b[15]=1.2839 k=16: a[16]=1.2833, b[16]=1.2837 k=17: a[17]=1.2833, b[17]=1.2835 k=18: a[18]=1.2834, b[18]=1.2835 k=19: a[19]=1.2834, b[19]=1.2835 Exercise 8(d) of Section 8.1, pp.427--428. Modify the Fibonacci method Matlab function from the textbook's web site: fib.m from http://math.fullerton.edu/mathews/software/NumericalMethods7.1.zip function y=fib(n) %Generates fibonacci numbers for the program fibonacci fz(1)=1;fz(2)=1; for k=3:n fz(k)=fz(k-1)+fz(k-2); end y=fz(n); fibonacci10.m (modified from fibonacci.m) from http://math.fullerton.edu/mathews/software/NumericalMethods7.1.zip function X=fibonacci10(f,a,b,tol,e) %Input - f, the object function % - a, the left endpoint of the interval % - b, the right endpoint of the interval...
View Full Document

This note was uploaded on 05/16/2010 for the course MATH 449 taught by Professor Wickerhauser during the Fall '09 term at Washington University in St. Louis.

Page1 / 12

s10 - Ma 449: Numerical Applied Mathematics Model Solutions...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online