midterm solutionC

midterm solutionC - Question 1 >> f = @(x)...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Question 1 >> f = @(x) x^2-5*x+6; >> bisect (f, 2.5, 4, 0.001, 1) step xl xh 1 2.500000 4.000000 2 2.500000 3.250000 3 2.875000 3.250000 xr 3.250000 2.875000 3.062500 yr 0.312500 -0.109375 0.066406 Emax 0.750000 0.375000 0.187500 3 marks for hand execution of bisection algorithm: 1 mark for Emax column 2 marks for the rest EMAX x 0 0.01953 210 x 0 210 0.01953 20 xU xL 20 30 2 marks Question 2 the derivate is cos 2 x sin 2 x the required commands are: >> fp =@(x) cos(x)^2sin(x)^2; >> maxx = fzero (fp, [0 2]); 1 mark Award the full mark if the derivative is close to correct (e.g. signs backward or similar). >> f = @(x) -sin(x)*cos(x); >> golden (f, 0, 2, 0.001, 1) xL x2 x1 0.000000 0.763932 1.236068 0.000000 0.472136 0.763932 0.472136 0.763932 0.944272 0.472136 xU 2.000000 1.236068 1.236068 0.944272 -0.499539 -0.310280 -0.405035 -0.499539 -0.499539 -0.474971 2.5 marks for hand execution of algorithm Students who evaluate the function in degrees rather than radians will get the first line shown below. Provided that everything else is correct deduct only 0.5 marks for this. k 1 xL 0.000000 x2 0.763932 x1 1.236068 xU 2.000000 -0.01333 -0.02156 I've adjusted for the fact that a maximum is required by sticking a minus sign in front of the function. Students who adapt the algorithm instead will positive rather than negative function values. This is fine. the best guess is the midpoint = 0.708202 max error is half the interval width = 0.236068 0.5 mark required commands: >> f = @(x)sin(x)*cos(x) >> xmin = fminbnd(f, 0, 2) 1 mark Question 3 >> f = @(x) x^25*x6; >> fp = @(x) 2*x5; >> x = newton(f, fp, 3, 0.001, 1) step xr 1 3.0000 15.000000 2 15.0000 9.240000 3 9.2400 6.778754 3 marks for hand execution of algorithm yr 144.000000 33.177600 6.057733 Ea 12.000000 5.760000 2.461246 A scant search with the given starting points will fail because the denominator becomes 0 (the line between the two points does not intersect the x axis). The solution is to choose different starting points. Any number of possibilities will work . The function is a parabola and symmetric about x = 2.5. Making both starting values greater than 2.5 will guarantee that we find the correct root. x0 = 4.0 and x1 = 5.0 is one good possible choice. 2 marks 1 mark for explaining the problem 1 mark for any reasonable solution Question 4 Let the length of the pool be X Then the volume of concrete is V (( X 2) * ( X 8 2) X * ( X 8)) * 0.01X Formulation for solution requires the form f(x) = 0: (( X 2) * ( X 8 2) X * ( X 8)) * 0.01X 13.6 0 2 marks 1 mark for correct volume formula 1 mark for putting problem into the form f(x) = 0 If X is zero the volume will be too low. This gives one limit. The other is established by picking values until one gives a volume that is greater than 13.6. Any number of correct answers are possible. 1 mark Matlab commands: f = @(x) ((x + 2) * (x6) x * (x 8))*0.01*x 13.6; x = fzero (f, [low, high]); fprintf ('L = %f, D = %f\n', x, x * 0.01); 2 marks 0.5 for defining function (award mark is function matches earlier answer, even if wrong) 0.5 mark for using fzero 0.5 marks for limits (low and high should be as selected earlier) 0.5 marks for fprintf ...
View Full Document

Ask a homework question - tutors are online