1 / 8

MATLAB Numerical Basics

MATLAB Numerical Basics. Roots of Polynominals. MATLAB can find all roots (both real and imaginary) of polynominals.

elton-pope
Download Presentation

MATLAB Numerical Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MATLAB Numerical Basics

  2. Roots of Polynominals • MATLAB can find all roots (both real and imaginary) of polynominals. Store coefficients in a vector v = [ a1 a2 … an an+1 ]. Use roots builtin function with vector as argument. Return value is a vector containing all n roots of the polynominal

  3. >> roots( [ 1 0 -17 12 ] ) ans = -4.4389 3.7102 0.7286

  4. Roots of Functions • MATLAB can find a single root for any function for which a MATLAB function file can be written. One of the builtin methods for doing this is fzero. fzero( @fname , approx_root ) fname is the name of the function for which a root is to be located. It can have only one argument, the function’s variable. approx_root is an initial guess for the value of the root.

  5. Van der Waals Equation P = Pressure ( 10 atm ) T = Temperature ( 250°K ) R = Gas Constant ( 0.082 liter-atm/gmole-°K ) V = Specific Volume ( liter/gmole ) Ammonia a = 4.19 atm (liter/gmole)2 b = 0.0372 liter/gmole

  6. Minimums • MATLAB has builtin procedures to find minimums in functions. This is an important tool in optimizations. One such tool is fminbnd. It finds the minimum of a MATLAB function between two bounds. fminbnd( @fname , x1 , x2 ) fname is the name of the MATLAB function to be optimized. This function has one argument, the independent variable, and must be written to accept vector arguments. x1 is the lower bound of the minimum x2 is the upper bound of the minimum

  7. Minimize x3 -17x + 12 between 0 and 10 m-file simple.m: function y = simple( x ) y = x.^3 -17*x + 12; >> fminbnd(@simple , 0 , 10) ans = 2.3805

  8. Global Variables • Normally variables in functions are local only to that function. • Many times one would like to define constants to be used in several functions or be able to change the value of a variable in a function without editing the function. This would be useful for instance in changing the temperature or pressure in a VDW calculation. • The global statement in MATLAB allows variables to be shared. • The global statement must be used in each MATALB area where the sharing is to occur. • The global statement must be executed before the variable is used. Gilat, Section 6.3

More Related