CS计算机代考程序代写 matlab ENGR20005

ENGR20005
Numerical Methods in Engineering
Workshop 2
Part A: MATLAB Livescripts
2.1 The livescript ENGR20005 Workshop2p1.mlx shows you how to use while loops and conditional statements by looking at the sample problem
f(x) = x − 2. (2.1) Read through and experiment with the livescript and make sure you understand each
of the commands in the code.
2.2 The livescript ENGR20005 Workshop2p2.mlx shows you how to analyse the problem
f(x)=ax2 +(1−a)x=0 (2.2)
where a > 0, using fixed point iteration.
(a) Read through the livescript and understand what each line of code does.
(b) Predict the value of a when the solution diverges.
(c) Vary a in the livescript and determine when the solution diverges. Does this match with what you found in part (b)?
2.3 The livescript ENGR20005 Workshop2p3.mlx shows you how to analyse Eq. (2.2) using the Newton–Raphson method. Read through the livescript and understand what each line of code does.
Part B: Problems
2.4 In workshop 1 you would have written your own MATLAB program (.m file) to im- plement the Babylonian method of computing the square root of S, which was given by the iterative formula
xi+1 = 1􏰄xi + S 􏰅 (2.3) 2 xi
1

Derive Eq. (2.3) yourself.
Hint: √S satisfies the equation x2 − S = 0.
2.5 Another problem you considered in workshop 1 is the solution of the quadratic equation
f(x)=x2 −2x−1=0
(a) Determine the roots of Eq. (2.4) analytically.
(b) Show that Eq. (2.4) can be arranged into the following forms
(2.4)
using bracketing methods.

ii. x=g2(x)= 12(x2 −1)
i. x=g1(x)= iii. x=g3(x)= 1
Apply Eq. (2.5) to Eq. (2.4). can approximate the derivative,
x−2
1+2x
(c) Write a MATLAB program (.m file) that applies fixed point iteration using the formulae in part (b). Use a range of guesses xguess ∈ [−3,3]. Does the method converge or diverge? What initial guesses does the method converge for? Do you know why?
(d) The Newton–Raphson method for root finding is given by
xi+1 = xi − f(xi) (2.5)
f′(xi)
(e) In the case of functions with derivatives of f that are complicated to derive, we
df/dx≈(f(xi)−f(xi−1))/(xi −xi−1). (2.6) Substitute Eq. (2.6) into Eq. (2.5) and show that
xi+1 = xi − (xi − xi−1)f(xi) (2.7) f(xi) − f(xi−1)
Equation (2.7) is called the Secant method. Apply Eq. (2.7) to Eq. (2.4) to find the roots of the equation. Check that your answer is correct by comparing with the Newton–Raphson and fixed point iteration method.
(f) Write new MATLAB programs (.m files) to solve Eq. (2.4) using the Newton– Raphson and Secant methods. Check your answer with the answer given using fixed point iteration.
2

2.6 * The temperature on a square plate is given by the following two-dimensional function T (x, y) = 80e−(x−1)2 e−3(y−1)2 (2.8)
where x ∈ [0,1] and y ∈ [0,1]. The temperature of the plate is 80oC at the corner x = y = 1.
(a) WriteaMATLABcodetoplotcontourswhereT(x,y)=70,60,50,40,30,27,20,10,5. Note the contour line for T = 27oC.
(b) Calculate the partial derivatives ∂ T and ∂ T . ∂x ∂y
(c) You have spotted a spider on the x = 0 edge of this plate. You know that spider likes to be in an area where the temperature T = 27oC. Any cooler or hotter, it will not be good for the spider. You are required to find the y location where you will tell the spider (for this exercise, you have the special ability to talk to the spiders!) to go in order to feel the temperature of T = 27oC. You might like to follow the steps below to answer this question.
i. Explain why you will need to solve f (y) = 80e−(0−1)2 e−3(y−1)2 − 27 = 0 in order to get the initial y location for the spider.
ii. Plotthefunctionf(y)=80e−(0−1)2e−3(y−1)2 −27
iii. Guess what the y value should be such that f(y) = 0.
iv. Use this guess value of y and the Newton-Raphson method to find a more accurate value of y such that f(y) = 0. In implementing the Newton-Raphson method, use your answer in 2.6b.
(d) Now that you have told the spider where the y value is such that T = 27oC at x = 0, the spider now tells you that she/he would like to walk to the right edge of the plate, x = 1 but only along the path where T = 27oC. Modify your code in (b) to such that you can find this path. Check your answer with the contour of T(x,y) = 27oC in part (a).
3