lab - Numbers Matlab recognizes several different kinds of...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Numbers Matlab recognizes several different kinds of numbers Type Examples Integer 1362;-217897 Real 1:234;-10:76 Complex 3:21 - 4:3i (i = -1) Inf Infinity (result of dividing by 0) NaN Not a Number, 0=0 Formats Command Example of Output format short 31.4162(4{decimal places) format short e 3.1416e+01 format long e 3.141592653589793e+01 format short 31.4162(4{decimal places) format bank 31.42(2{decimal places) Examples >> format long >> x = 3 + 11/16 + 2^1.2 x = 5.98489670999407 >> format short >> x = 3 + 11/16 + 2^1.2 x = 5.9849 Variables >> 3-2^4 ans =-13 >> ans*5 ans =-65 The result of the first calculation is labelled \ans" by Matlab and is used in the second calculation where its value is changed.We can use our own names to store numbers: >> x = 3-2^4 x =-13 >> y = x*5 y =-65 so that x has the value x= -13 and y = - 65. These can be used in subsequent calculations. These are examples of assignment statements: values are assigned to variables. Each variable must be assigned a value before it may be used on the right of an assignment statement. Variable Names Legal names consist of any combination of letters and digits, starting with a letter. These are allowable: NetCost, Left2Pay, x3, X3, z25c5 These are not allowable: Net-Cost, 2pay, %x, @sign Suppressing output One often does not want to see the result of intermediate calculations terminate the assignment statement or expression with semi{colon >> x=-13; y = 5*x, z = x^2+y y =-65 z = 104 >> the value of x is hidden. Note also we can place several statements on one line, separated by commas or semi{ colons. Exercise 1 In each case the value of the expression in Matlab and explain precisely the order in which the calculation was performed....
View Full Document

Page1 / 8

lab - Numbers Matlab recognizes several different kinds of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online