{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

pset_2_sol

# pset_2_sol - 2.29 Numerical Fluid Mechanics Solution of...

This preview shows pages 1–4. Sign up to view the full content.

2.29: Numerical Fluid Mechanics Solution of Problem Set 2 MASSACHUSETTS INSTITUTE OF TECHNOLOGY DEPARTMENT OF MECHANICAL ENGINEERING CAMBRIDGE, MASSACHUSETTS 02139 2.29 NUMERICAL FLUID MECHANICS— SPRING 2007 Problem Set 2 Posted 02/25/07, due Thursday 4 p.m. 03/8/07, Focused on Lecture 4 to 7 Problem 2.1 (6% of final grade): Advance your programming skills and review root finding methods Review MATLAB help about: Function handle eval nargin varargin cell: as a data type switch: as flow control command fprintf lower Here we want to develop a script as a generalized one dimensional solver. Later you can use it for next problems. The function that you write should provide the maximum ease of use, as well as the maximum amount of flexibility and adjustment. To that end and to develop a user friendly program: The function should have default values for everything so that the user can run it with minimum number of inputs. The input function (to be solved) should be either a function handle or a string (like ‘3*x^3-5*x+1’). The program should have a nice command line output or plot displaying the gradual progress of solution. The user should be able to adjust/provide the below options, if necessary. Note that user should not need to memorize any order for them and option names should not be case sensitive: a) Method: Newton, Secant, Bi-Section, False-Position, Modified False- Position b) Initial guess: it can be two numbers for methods like Bi-Section c) Derivative of f (note that you can compute the derivative if user provides you with a string as solution equation) d) Absolute tolerance on x or f 1

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

View Full Document
2.29: Numerical Fluid Mechanics Solution of Problem Set 2 e) Relative error on x f) Maximum number of iterations g) Plot Here is what function should be like: [x_solution, x_iterations, f_iterations] = solver(func_name) [x_solution, x_iterations, f_iterations] = solver(func_name, x_guess) [x_solution, x_iterations, f_iterations] = solver(func_name, x_guess, OPTIONS) A few example calls are shown: After writing the program you have to UPLOAD IT ON THE COURSE WEBSITE and PRINT IT AS WELL. That’s all you have to do for this problem. This will replace the MATLAB workshop assignment about MATLAB programming. Solution: Look at the attached MATLAB file “solver.m”. 2
x < 4 x > 20 x < ! 20 2.29: Numerical Fluid Mechanics Solution of Problem Set 2 Problem 2.2 (10 Points): Examine your root finding script We are interested to find the roots of: f ( x ) = e x sin x + e ! x cos 2 2 x a) b) c) d) e) How many roots does this equation have? Can you approximate analytically some roots of this equation and characterize their type? Discuss. Find all the roots where . Use above program and examine all the methods for any root. For each root use “plotyy” command and plot two things at the same figure: - x versus number of iterations - Relative error of x (with respect to the most trusted solution) versus number of iterations (use logarithmic scale if needed) Repeat part c and find the fist two roots where Repeat part c and find the fist two roots where

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

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

{[ snackBarMessage ]}