Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask MATLAB Expert

Problem 1: Let f : [a, b] → R, for a < b, be a bounded function and consider a point x and some spacing h > 0. We define the forward divided difference of f on x with spacing h by

δh,+f (x) = (f (x + h)h - f (x))/h      (1)

provided that x + h ∈ [a,b].

As seen on Problem Sheet 3, the following results holds, if f is sufficiently smooth.

h,+ f(x) - f'(x)| ≤ h/2 maxξ∈ [a,b]|f''(ξ)|.     (2)

The results of the above indicate that, as h is reduced, the finite difference approximation becomes more accurate. However, this results assumes exact arithmetic, we investigate what happens in a computer implementation.

(a) For f (x) = cos(x), write a piece of MATLAB code to evaluate the forward difference approximation δh,+ f(Π/4) for a given h. For h ∈ [10-12,10-2], plot the error |f' (Π/4) - δh,+ f (Π/4)| against h. What do you notice?

[Hint: Use logspace to uniformly divide the interval [10-12,10-2] with 1000 points on a logarithmic scale, then use loglog to plot the error against h, but plot the points individually, i.e., do not join the points with lines.]

(b) Show that, when using floating point arithmetic (assuming no underflow or overflow), the following holds:

h,+ f(x))^ := fl((fl(fl( f (x + h)) - fl( f (x)))/h) ≈ (f (x + h) - f (x))/h + (f (x + h)(∈1 + ∈3 + ∈4) - f(X)(∈2 + ∈3 + ∈4))/h

where |∈il < ∈M/2, for i = 1,.....,4 and ∈m <<1 is the machine epsilon.

[Hint: Use the results on Slide 30 of Section 3 and assume that x + h is stored exactly on the machine. Also, notice that ∈ij < ∈M, for i, j = 1, ... ,4.]

(c) Hence, show that, when floating point numbers are used, the truncation and round-off errors combine so that

|f'(x) - (δh,+ f(x))^| <≈ h/2 maxξ∈[x, x+h]|f''(ξ)| + 6(∈Mmaxξ∈[x, x+h]|f(ξ)|)/h

(d) For f (x) = cos(x), plot the theoretical error from part (c) against h on a pair of axes with logarithmic scales with x = Π/4. Compare your results with those from part (a).

[Hint: MATLAB's machine epsilon can be found by typing eps in the command window.]

Problem 2 We wish to solve the initial-value problem: For some interval [a, b] ⊂ R, find a function y : I -+ Rn such that

y'(x) = f (x, y(x)) and y(a) = y0   (3)

for some known vector function f : [a, b] x y([a, b]) → Rn and some values y0 ∈ Rn.

Consider a subdivision of the interval [a, b] into subintervals [xi-1, xi] of equal width, with

a = x0 < x1 < x2.... < xN = b

where xi = xi-1+ h, and h = (b - a)/N.

(a) Download newtonraphson.m, explicit_euler m and implicit_euler m from Blackboard. As written, the Euler functions will compute approimxate solutions to (3) with n = 1.

Apply the explicit and implicit Euler methods with f (x, y) = -1000y, y(0) = 1 and [a, b] = [0, 1].

(i) At what values of N (and hence h), does the explicit Euler method become unstable?

(ii) Is the implicit Euler method stable at these values? Does it ever become unstable?

(b) Apply the explicit and implicit Euler methods to the differential equation with f (x, y) = cos(4Π(x + y2)), on the interval [a, b] = [0, 1] and again let y(0) = 1.

(i) Using N = 5000, compute a good approximation to y(1) using either Euler method. Call this approxi-mation (1).

(ii) By choosing N = 10, 20, 40, 80, 160, 320, find the error |y(xN)-y~(1)| when both the implicit and explicit Euler method is used. Plot the error against N on a logarithmic scale. What is the order of convergence of both methods in terms of N and in terms of h?

(c) The Lotka-Volterra equations are a model for a predator-prey system in mathematical ecology. Let x(t) be the population of the prey at time t and y(t) be the population of the predator at time t. The equations read:

dx/dt = αx - βxy,

dy/dt = δxy - γy,

for some constants α, β, γ, δ.

Convert the implicit Euler code so that it can now solve systems of equations of the form (3), with n ≥ 1.

Let α = 0.1, β = 0.02, γ = 0.04 and δ = 0.004, x(0) = 20, y(0) = 2 and use your implicit Euler method to compute approximations to x(t) and y(t) for t ∈ [0, 1000] using a grid with time-step δt = 1. Plot x and y against t on a set of axis.

[Note, partial credit will be given if the explicit Euler method is used instead.]

Problem 3 - In this problem we use the finite difference method to solve the following convection-diffusion-reaction problem:
-u'' + cu' + du = f, x ∈ (a, b),         (4)
u(a) = A,     (5)
u(b) = B.,    (6)

where c > 0 and d > 0 are constants, f : [a, b] -> R is a known function and A and B are boundary conditions.

(a) Write a MATLAB function to approximate u(x) using the finite difference method, it should take as input the interval [a, b] and c, d, A and B and the number of subintervals N, such that

a = xo 1 = xo + h ..... < XN-2 + h < XN-1+ h = XN = b.

with h = (b - a)/N

(b) Let a = 0, b = 1, c = 1, d = 1, A = 0, B = 0 and f (x) = 1. Find the exact solution to the equation with these parameters. For N = 10, 20, 40, 80, 160, 320 run your code and compute the error:

EN = √(1/N∑i=0N(u(xi) - ui)2)

where ui is the finite difference approximation to u(xi).

Plot the solution for N = 3200 and give a plot of E against N on a set of axes with logarithmic scales. What is the order of the convergence of the method with respect to N?

Problem 4: The Euler methods can also be used to find solutions to problems of the form (4)-(6), this technique is called the shooting method. First, we convert the second order differential equation into a system of first order equations. By letting v = u', we have

du/dx = V,

dv/dx = cv + du - f (x).

We have u(a) = A, but we do not have information about v(a), however, we know that we need u(b) = B. We pick v(a) and solve to find u(b), then modify v(a) until u(b) = B. This is like changing the angle at which a gun is fired until the target is hit, hence the name.

For the same problem as in Problem 3(a), implement the shooting method with your Euler method from Problem 2(c) and find an approximation to u. For N = 20, 40, 80,160, 320 run your code and compute the error:

EN = √(1/N∑i=0N(u(xi) - ui)2)

Plot the solution for N = 320 and give a plot of E against N on a set of axes with logarithmic scales. What is the order of the convergence of the method with respect to N?

[Hint: Finding the correct v(a) is simple in this case because we have a linear differential equation, hence u(b) depends linearly on v(a).]

MATLAB, Engineering

  • Category:- MATLAB
  • Reference No.:- M92576648
  • Price:- $150

Guranteed 48 Hours Delivery, In Price:- $150

Have any Question?


Related Questions in MATLAB

Discrete optimisation- solve the following two problems

Discrete Optimisation - Solve the following two problems with both exhaustive enumeration and branch and bound - Problem 1 is a mixed integer linear optimisation problem (the problem has both discrete and continuous vari ...

Assignment details -need to write a code for connecting

Assignment Details - Need to write a code for connecting segments (Lines) a special case of TSP. The problem is to connect lines in 2d/ 3d space with path obstructions. Can you help me write the code for this? Hope you m ...

Question - verify the attached paper with matlab and get

Question - Verify the attached paper with matlab and get all the results in the paper and explain step by step the matlab code. Paper - Improving Massive MIMO Belief Propagation Detector with Deep Neural Network. Attachm ...

Assignment matlab programmingusing appropriate matlab

Assignment: MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

Question 1 manipulate spectral imagehyperspectral images

Question 1. Manipulate spectral image Hyperspectral images can be seen as a generalisation of normal colour images such as RGB images. In a normal RGB colour image, there are 3 channels, i.e. channels for red colour, gre ...

Recitation problems -1 determine the highest real root of

Recitation Problems - 1. Determine the highest real root of f(x) = 2x 3 - 11.7x 2 + 17.7x - 5 using the Newton-Raphson method with at least four iterations. Start with an initial guess of x 0 = 3. 2. Determine the real r ...

Suppose that a student has the option of enrolling for a

Suppose that a student has the option of enrolling for a single elective during a term. The student must select a course from a limited list of options: "English, " "History, " "Biology, " "Computer, " or "Math." Constru ...

Assignment - matlab programmingusing appropriate matlab

Assignment - MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

Lab assignment - matlab matrix relationallogical operators

Lab Assignment - MATLAB Matrix, Relational/Logical Operators and Plotting This laboratory exercise/assignment will involve you 1) practicing multiplication operators in MATLAB; 2) practicing relational and logical operat ...

Assignment - matlab programmingusing appropriate matlab

Assignment - MatLab Programming Using appropriate MatLab syntax, write the code required to analyse and display the data as per the problem description. The order of the MatLab Program should be as follows: Variables and ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As