Ask Question, Ask an Expert


Ask MATLAB Expert

1 Errors

a. Run the MATLAB script

sum = single(0); term = single(1);
while sum + term > sum
sum = sum + term;
term = 1/n;

Describe what you think it is trying to do. What would this code do in exact arithmetic? describe why the code produces a finite result and (harder) describe the output. What would happen (don't try it!) if you replaced the  first line with sum=0; term=1;?

b. Use Taylor series to derive the form of the truncation error of the approximation

f'(x) =3f(x) -4f(x - h) + f(x -2h)/2h

assuming f ≡ C3. Given that the round off error has the same form as in the Forward Difference case, find an expression for the step size h that gives the smallest total (absolute) error. Modify ForwardDifference.m to show how the total error in using Equation 1 behaves for various values of h and comment on your results.

2 Operation counts

a. Derive the operation count (multiplications and divisions only) for

(i) Choleski factorization (without pivoting) A detailed algorithm for Choleski factorization can be found via the MAST30028 website on p. 78 of Heath's Lecture Slides --- Chapter 2.

(ii) Gauss elimination (equivalent to LU factorization) without pivoting of an Upper Hessenberg matrix. An Upper Hessenberg matrix is one with zeroes below the subdiagonal. Just modify the derivation for Gauss elimination.

(iii) solution of a tridiagonal system via LU factorization without pivoting (also called the Thomas algorithm) This is the algorithm implemented in the code tridisolve in the Asst1 folder on the server.

b. Verify qualitatively the running times you obtained above, by timing the solution of linear systems of size at least 1000X1000 with matrices having the appropriate structure (symmetric positive definite, Upper Hessenberg or tridiagonal).

Construct the matrices yourself with suitable MATLAB commands such as diag, triu, rather than using particular matrices from the MATLAB gallery.

For all cases, use \ to solve the system. For case c, try a tridiagonal matrix created with diag and one created with spdiags.

describe what you think is going on.

3 Application: Nonlinear systems of equations

You have met Newton's method as a method for solving nonlinear equations in the form f(x) = 0.

xn+1 = xn-f(xn)/f'(xn)

which gives iterates {xn} that converge rapidly to the solution x*  provided the initial guess x0 is sufficiently close to x* . Applying this to the function

f(x) = x2 - a produces the iteration xn+1 = xn - x2n -a/2xn= xn/2 + a/(2xn)

which should look familiar. It can be written in the alternative form: solve in turn

f'(xn)sn = f(xn); xn+1 = xn - sn

For a system of two nonlinear equations f1(x1, x2) = 0; f2(x1,x2) = 0

or  in vector notation

f (x) = 0

Newton's method generalizes in the following way: solve the 2X2 linear system

J(xn)sn = f (xn) then update xn+1 = xn - sn

where J is the Jacobian matrix formed from f

194_Jacobian matrix.jpg

To get an idea how it works, try out the Java applet

a. prepare a MATLAB function to implement Newton's method for a system of 2 nonlinear equations.

It should have the calling sequence [roots, count, resids, history] = ass1Q3(func,x0,tol)


• the first input argument is a function handle to a function that returns the value of the function f and the Jacobian matrix J at the position x e.g. function [ f J] = ex2( xx )

The function ex2 needs to be written by the user, including the expressions for f and J. There is no need for J to be found symbolically from f .

• x0 is the initial guess ( a column vector)

• tol is the absolute tolerance. The iterations should stop once the residual ||f||, measured using the vector ∞-norm, is below tol.

• the  first output argument is a column vector containing the solution x

• count is the number of iterations required

• resids is a vector containing the norms of the residuals at each iteration

• history is a matrix whose columns are the iterates xn i.e. each column is a 2X1 array.

The function should:

• use a default tolerance of 10-10 if none is given

• use a while loop but loop no more than 50 times.

Although I only need it to work for systems of 2 equations, you should be able to prepare it so that it can be used (in principle) on a system of any size. My code is less than 20 lines long.

b. prepare a driver function to test your code on ex 2 of the Newton2D Java applet. The driver should produce output such as
After 5 iterations, the roots are [1.61803 1.61803]

c. Modify your driver to find the solution to

3x31 + 4x22- 145 = 0; 4x21- x32+ 28 = 0

Show results for 2 different initial guesses: x0 = (2, 2),(2,-1).

For each case, plot the convergence history - the residual norms at each iteration - on a suitable plot and (on a different plot) the solution trajectory - the set of iterates xn.
Comment on your results.

MATLAB, Engineering

  • Category:- MATLAB
  • Reference No.:- M91787
  • Price:- $70

Priced at Now at $70, Verified Solution

  • AsyU replied is my first experience and i have to say that you guys are life saver honestly your solution is too awesome which helped me alot thank you so much...

Have any Question? 

Related Questions in MATLAB

Problem 1 10pts the csu-chill radar made observations of

Problem 1 [10pts.]: The CSU-CHILL radar made observations of the Ponnequin Wind Farm located on the boarder of Wyoming and Colorado near I-25. The wind farm is approximately 62 km away from the radar. Complex valued digi ...

Car parking systema building of 10 floors is used for

CAR PARKING SYSTEM A building of 10 floors is used for parking cars. The area of each floor can be used for parking 100 cars. An automatic parking system is used to detect which parking slot is free at each moment. So, t ...

Reports of projectproblem design a fourbar grashof

REPORTS OF PROJECT PROBLEM: Design a fourbar Grashof crank-rocker to give? (Everyone will determine the terms given by professor) of rocker rotation with equal time forward and back, from a constant speed motor input. 1- ...

1 calculate the following for the function f x e-3x -

1) Calculate the following for the function f (x) = e -3x - 2x a. Calculate the derivative of the function by hand. Write a MATLAB function that calculates the derivative of this function and calculate the derivative at ...

Question 1backgroundclimate change is a change in global or

QUESTION 1 Background Climate change is a change in global or regional climate patterns, in particular a change apparent from the mid to late 20th century onwards and attributed largely to the increased levels of atmosph ...

Use matlab to solve the following equations please i plot

Use Matlab to solve the following equations. Please (i) plot the solution as a function of t for t  ∈ [0, 100]. (ii) draw the phase diagram of the ODE. 1. dy/dt = y 2 + y with y(0) = 1         dy 1 /dt = y 2 2.           ...

Question 1backgroundyou have been asked to manage a project

QUESTION 1 Background You have been asked to manage a project to install a pipeline from an offshore gas platform to an onshore gas processing plant, and to find the cheapest design that is possible. The platform is Q km ...

Plotting and computer animation in matlabinstructions for

Plotting and computer animation in MATLAB Instructions: For each of the following exercise, create an M-file to store the MATLAB commands. Copy and paste the M-file into a text document. For problems 1 and 2, include in ...

Problem -tom cat is chasing jerry mouse the initial

Problem - Tom cat is chasing Jerry mouse the initial distance between them is S 0 = 100m. Tom runs V c = 4-at m/s (negative accident) Jerry's velocity depends on the distance between Tom& Jerry V = Vmax - Ks (3-0.025 m/s ...

Matlabproject descriptionwrite a mileage per gallons and

MATLAB Project description: Write a mileage per Gallons and miles per dollar calculator program using two functions, one to calculate MPG and one to calculate MPD. The application will prompt the user to type the odm rea ...

  • 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

WalMart Identification of theory and critical discussion

Drawing on the prescribed text and/or relevant academic literature, produce a paper which discusses the nature of group

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro