{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

02-Basic-MATLAB-4UP

02-Basic-MATLAB-4UP - InteractiveM ATLAB Managing the...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
InteractiveM ATLAB Managing the workspace Scripts Basic M ATLAB Dhavide Aruliah UOIT MATH 2070U c D. Aruliah (UOIT) Basic M ATLAB MATH 2070U 1 / 23 InteractiveM ATLAB Managing the workspace Scripts Basic M ATLAB 1 Interactive computing in M ATLAB 2 Managing the M ATLAB workspace 3 M ATLAB scripts c D. Aruliah (UOIT) Basic M ATLAB MATH 2070U 2 / 23 InteractiveM ATLAB Managing the workspace Scripts Entering expressions interactively We can calculate numbers in a sequence of assignment statements >> a = 4; % assigns value 4 to variable a >> a = a + 1.42644 % assigns value 5.42644 to variable a >> b = a, b = ... % command continued on next line >> 3 >> command prompt ; statement separator (without output) , statement separator (with output) ... continuation of statement on next line ans “answer”, last value calculated % comment symbol; characters to right ignored (Extra spaces don’t matter) c D. Aruliah (UOIT) Basic M ATLAB MATH 2070U 4 / 23 InteractiveM ATLAB Managing the workspace Scripts Typesetting expressions for programs Use ASCII (”typewriter”) characters for programming. Arithmetic operations of addition, subtraction, multiplication, division, and exponentiation are + , - , * , / , and ^ respectively e.g. the expressions below have are typeset as specified x + y x+y b - a b-a uv = u × v u*v m / n = m div n = m n m/n a k a^k (Some languages allow a**k for a k , e.g., M APLE & Fortran) c D. Aruliah (UOIT) Basic M ATLAB MATH 2070U 5 / 23
Image of page 1

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

View Full Document Right Arrow Icon
InteractiveM ATLAB Managing the workspace Scripts Identifiers in M ATLAB Identifier : generic term for “variable name” in programming Rules for identifiers in M ATLAB : 1 Identifiers are case sensitive (e.g., Alpha = alpha ) 2 Identifiers can contain up to 63 characters. Any character beyond the 63rd is ignored. 3 Identifiers must start with a letter, followed by any number of letters, digits, or underscores. Punctuation characters are not allowed. (e.g., foo 4 is allowed, but not foo4 or 4foo ) Use sensible identifiers term to clarify code, e.g., area = pi * radius * radius volume = length * height * width amount owing = principal + interest c D. Aruliah (UOIT) Basic M ATLAB MATH 2070U 6 / 23 InteractiveM ATLAB Managing the workspace Scripts Syntax for common mathematical functions sqrt(x) square root x nthroot(x,n) n th root n x = x 1/ n exp(x) exponential function e x = exp ( x ) abs(x) absolute value | x | log(x)
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern