1 / 6

MatLab Basics

MatLab Basics. Jae Hoon Kim Department of Physics Kangwon National University. • It contains hundreds of commands to do mathematics. • Graph functions, solve equations, perform statistical tests • High level programming language that can communicate

johnniee
Download Presentation

MatLab 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 Basics Jae Hoon Kim Department of Physics Kangwon National University • It contains hundreds of commands to do mathematics. • Graph functions, solve equations, perform statistical tests • High level programming language that can communicate with the other programming language such as FORTRAN and C.

  2. MatLab Desktop  Double click the MatLab icon on the Windows Desktop → Launch the MatLab → MatLab Desktop appears: Workspace Display the information for the defined variables Command window Enter the command and Output the result Command History List of used commands

  3. Arithmetic • Simple Arithmetic (1) Four fundamental operations : +, -, *, / >> 3^2-(5+4)/2+6*3 ans= 22.5000 (2) Mathematic Functions: sqrt, cos, sin, tan >>ans^2+sqrt(ans) ans= 510.9934 • Precision (1) MATLAB uses double-precision floating point arithmetic. -> 15 digits (2) MATLAB display only 5 digits for the output result by default. Format long -> display 15 digits Format short -> return to 5-digit display

  4. • To perform symbolic calculation, use “syms” command to declare the symbolic variable. >> syms x y >> (x-y)*(x-y)^2 ans = (x-y)^3 • Commands for the symbolic calculation (1) expand: multiply out the expression >> expand(ans) ans = x^3-3*x^2*y+3*x*y-y^3 (2) factor: restore to factored form >> factor(ans) ans = (x-y)^3 (3) simplify: express a formula as simply as possible. >> simplify((x^3-y^3)/(x-y)) ans = x^2+x*y+y^2 • Calculation with the Symbolic Expression >>cos(pi/2) -> 6.1232e-17 (not 0) Because “pi” gives an approximation to  accurate to about 15 digits, not its exact value. >>cos(sym(‘pi/2’)) ->0 Symbolic representation of /2 -> exact value. • Variable – precision Arithmetic >>vpa(‘sqrt(2)’, 50) print 50 digits of √ 2 Algebraic and Symbolic Calculation

  5. Managing Variables • Data type (1) floating point numbers (2) symbolic expressions (3) strings • “whos” command: display a summary of the names and types of currently, defined variables. (Workspace browser presents a graphical alternative to “whos”) • “clear” or “clear all” : Clear all defined variables

  6. Online Help  To get help on a command, enter help followed by the name of the command. ex) help solve: print out the online help for “solve” command. •more on: Display the online help. One screen-full at a time  To search the first line of every online help for a specified string use “lookfor” command ex) lookfor factor: Display the help that contain the word “factor” as part of the command name of brief description

More Related