1 / 4

MATLAB Basics

Input and Output Algebra. Arithmetic Errors in Input. MATLAB Basics. Yun Suk Jang Department of physics Kangwon National University. Input and Output. You input commands to MATLAB in the MATLAB command Window. MATLAB returns output in two ways: Text.

tallys
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. Input and Output Algebra Arithmetic Errors in Input MATLAB Basics Yun Suk Jang Department of physics Kangwon National University

  2. Input and Output • You input commands to MATLAB in the MATLAB command Window. MATLAB returns output in two ways: • Text. • Numerical output is returned in the same Command Window. Arithmetic • You can use MATLAB to do arithmetic as you would a calculator: (1) “ + ” to add, “ - ” to subtract, “ * ” to multiply, “ / “ to divide, “ ^ ” to exponentiate. Ex) >> 3^3 – (5 + 4) / 2 + 6*3 Ans = 22.5000 (2) Other Function : sqrt, cos, sin, tan Ex) >> ans^2 + sqrt ( ans ) Ans = 510.9934

  3. To perform symbolic computations, use syms to declare the variables you plan to use to be symbolic variables. >> syms x y >> (x – y)*(x – y)^2 ans = (x – y)^3 The command expand MATLAB to multiply out the expression, and factor forced MATLAB to restore it to factored form. >> expand (ans) ans = x^3 – 3*x^2*y + 3*x*y^2 – y^3 >> factor (ans) ans = (x-y)^3 The command called simplify, which you can sometimes use to express a formula as simply as possible. >> Simplify ((x^ - y^3) / (x – y)) ans = x^2 + x*y + y^2 Calculation with the Symbolic Expression. >>cos(pi/2) ans = 6.1232e-17 -> However, we Know that cos(/2) is really equal to 0. >> cos(sym(‘pi / 2’) ans = 0 -> Symbolic representation of /2 You can also do variable-precision ariyhmetic with vpa. >> vpa(‘sqrt(2)’, 30) ans = 1.41421356237309504880168872420 Algebra

  4. Errors in Input • If you make an error in an input line, MATLAB will beep and print an error message. Ex) >> 3u^2 ??? 3u^2 error: missing operator, comma, or semicolon. • The error is a missing multiplication operator *. The correct in put would be 3*u^2. Note that MATLAB places a marker at the place where it think the error might be; however, the actual error may have occurred earlier or later in the expression.

More Related