Introduction to Programming for Mechanical Engineers

Slides:



Advertisements
Similar presentations
MATLAB EXAMPLES Initial-value problems
Advertisements

ES 240: Scientific and Engineering Computation. Chapter 17: Numerical IntegrationIntegration  Definition –Total area within a region –In mathematical.
Numerical Differentiation and Quadrature (Integration) 1Daniel Baur / Numerical Methods for Chemical Engineers / Numerical Quadrature Daniel Baur ETH Zurich,
Numerical Integration of Functions
Chapter 7 Numerical Differentiation and Integration
Data mining and statistical learning - lecture 6
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
Newton-Cotes Integration Formula
LINEAR EQUATION IN TWO VARIABLES. System of equations or simultaneous equations – System of equations or simultaneous equations – A pair of linear equations.
6&7-2 Dynamics, two examples of the use of ode45. Numeric Integration using trapz and quad/quadl functions. Readings: Matlab by Pratap Chapter 5.4,5.5.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Numerical Differentiation and Integration ~ Newton-Cotes.
Lecture 24 Introduction to state variable modeling Overall idea Example Simulating system response using MATLAB Related educational modules: –Section 2.6.1,
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Chapter 21 Newton-Cotes Integration Formula.
MECN 3500 Inter - Bayamon Lecture Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
1 Chapter 7 NUMERICAL INTEGRATION. 2 PRELIMINARIES We use numerical integration when the function f(x) may not be integrable in closed form or even in.
Chapter 9 Introduction to MATLAB for Engineers, Third Edition
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
DIFFERENTIAL EQUATIONS, INTEGRATION, POLYNOMIALS, RANDOM NUMBERS MEKANIKA SOFTWARE SEMINARS.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Chapter 9 Numerical Integration Flow Charts, Loop Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Curve Fitting and Interpolation: Lecture (I)
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Chapter 21 Exact Differential Equation Chapter 2 Exact Differential Equation.
BEH.420 Matlab Tutorial Bambang Adiwijaya 09/20/01.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Lecture 22 Numerical Analysis. Chapter 5 Interpolation.
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Analyzing Functions (4.16) y=f(x) MATLAB. Functional Analysis includes: Plotting and evaluating a function Finding extreme points Finding the roots (zeros.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical calculus and differential equations.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
More Functions in MATLAB. Functions that operate on other functions A function F() can take another function G() as an argument by using a notation:
Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
Lecture 40 Numerical Analysis. Chapter 7 Ordinary Differential Equations.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 5 Integration and Differentiation.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations.
Lecture 39 Numerical Analysis. Chapter 7 Ordinary Differential Equations.
1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
1 Spline Interpolation Method Mechanical Engineering Majors Authors: Autar Kaw, Jai Paul
Mathematical Applications By Matlab 3 rd Day Dr. Wael Khedr CSI Dept.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 20 Numerical Integration of Functions.
CMPSC 200 Fall 2013 Lecture 37 November 18, 2013.
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
S5.40. Module Structure 30% practical tests / 70% written exam 3h lectures / week (except reading week) 3 x 2h of computer labs (solving problems practicing.
EEE 244-3: MATRICES AND EQUATION SOLVING
Introduction to Programming for Mechanical Engineers
Chapter 7 Numerical Differentiation and Integration
Numerical Methods by Dr. Laila Fouad.
CHAPTER 3 NUMERICAL METHODS.
Introduction to Programming for Mechanical Engineers (ME 319)
Introduction to Programming for Mechanical Engineers (ME 319)
MTH1170 Differential Equations
525602:Advanced Numerical Methods for ME
SE301: Numerical Methods Topic 8 Ordinary Differential Equations (ODEs) Lecture KFUPM (Term 101) Section 04 Read , 26-2, 27-1 CISE301_Topic8L4&5.
MATH 2140 Numerical Methods
Direct Method of Interpolation
Spline Interpolation Method
Simpson’s 1/3rd Rule of Integration
Write Polynomial Functions and Models
MATH-321 In One Slide MATH-321 & MATLAB Command.
Simpson’s 1/3rd Rule of Integration
Simpson’s 1/3rd Rule of Integration
Simpson’s 1/3rd Rule of Integration
Numerical Integration
EEE 244-3: MATRICES AND EQUATION SOLVING
Spline Interpolation Method
Dear Power point User, This power point will be best viewed as a slideshow. At the top of the page click on slideshow, then click from the beginning.
Presentation transcript:

Introduction to Programming for Mechanical Engineers Lecture 9 (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh

Quote of the day “Education is what remains after one has forgotten what one has learned in school.” - Albert Einstein

Things you should have known so far! In chapter 8, we discussed the polynomials and curve fitting. The evaluation of polynomials at certain points is very easy application in MATLAB. Polynomials addition, subtraction, multiplication and division is performed when the polynomials are defined as vectors. Interpolation was also presented as being a useful application of polynomials. Curve fitting can also be performed in the plot window. (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh

Numerical analysis: solving equations with one variable If there is an equation which can be written as f(x)=0, then the solution for this equation is easily obtained. x=fzero(function,x0) is the command used to find the solution of a function. You can define the function is several ways: Function p Evaluation Define it as a string >> w = fzero('x^3-sin(x)',2) w = 0.9286 Define it as an anonymous function, then use its name >> fun = @(x)x^3-sin(x) fun = @(x)x^3-sin(x) >> v = fzero(fun,2) v = (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh

Numerical analysis: plotting equations with one variable Using fplot command, one can plot the function in the interval provided within the command line. fplot('x^3-sin(x)',[0 4]) will plot the provided function within the [0 4] interval. >> fplot('x^3-sin(x)',[0 4]) (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh

Numerical analysis: minimum and maximum of a function fminbnd is the command used to find the minimum of a function. The syntax is fminbnd(function,x1,x2). When the command executes, it searches for a local minimum and compare it to the ends of the interval. To find a maximum, you need to multiply the function by -1 and find its minimum. >> r = fminbnd('x^3-sin(x)',0,4) r = 0.5354 (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh

Numerical analysis: numerical integration (quad & quadl) Functions with one variable can also be integrated with respect to that variable over a certain period. p = quad(function,a,b) is the command to be used to find the numerical integration in the interval [a b]. The function inserted here should carefully written to represent element by element operations. >> y = quad('x.^3-sin(x)',0,4) y = 62.3464 >> y = quadl('x.^3-sin(x)',0,4) (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh

Numerical analysis: numerical integration (trapz) p = trapz(x,y) is the command to be used to find the integration of given data points (x-y pairs). It uses trapezoidal method to integrate these points. Take the same function, define x = linspace(0,4,5); y = x.^3-sin(x); plot(x,y); p = trapz(x,y) >> x = linspace(0,4,5); >> y = x.^3-sin(x); >> plot(x,y,'r') >> p = trapz(x,y) p = 66.4865 (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh

Numerical analysis: ordinary differential equation (ODE) Ordinary differential equations are the ones of the form for Steps: Write the differential equation in the standard form. Create a user defined or an anonymous function. Define the interval [t0 tf] and the initial condition y0. Choose a solver and perform integration. (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh

Numerical analysis: ordinary differential equation (ODE) solver Description Method ode45 For non-stiff problems, one step solver. Best as an initial method1. http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/ode45.html&http://www.google.com/search?q=ode45&rls=com.microsoft:*&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1 Please refer to the above URL for more reading about these solvers. ode23 For non-stiff problems, one step solver. Quicker but less accurate than ode451 ode113 For non-stiff problems, multistep solver1. ode15s For stiff problems, multistep solver. Uses a variable order method. Used if ode45 failed1. ode23s For stiff problems, one step solver. Can solve some problems that ode15 cannot1. ode23t For moderately stiff problems1. ode23tb For stiff problems. More efficient that ode15s1. 1 MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley. (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh

Numerical analysis: ordinary differential equation (ODE) Let us take an example to illustrate these ideas: % Define the function dx/dt = x^0.2-sin(t) >> fun = @(t,x)x^0.2-sin(t) fun = @(t,x)x^0.2-sin(t) % Use ode45 as it should be an easy solver to begin with >> ode45(fun,[0 3],4) >> [t x] = ode45(fun,[0 1 2 3],4) t = 1 2 3 x = 4.0000 4.8917 5.3209 6.1619 (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh

Numerical analysis: ordinary differential equation (ODE) Example: % Define the function dx/dt = x^0.2*cos(t)-sin(x*t) >> fun = @(t,x)x^0.2*cos(t)-sin(x*t) fun = @(t,x)x^0.2*cos(t)-sin(x*t) >> ode45(fun,[-1 6],2) % Use ode45 as it should be an easy solver to begin with >> [t x] = ode45(fun,[0:1:4],2) t = 1 2 3 4 x = 2.0000 2.2678 2.6030 2.0019 1.4543 (1) MATLAB an Introduction with Applications, Amos Gilat, 3rd ed, Wiley.Mohammad Y. Saadeh