Wednesday, May 12, 2010

MATLAB BASICS(input & output)

Input and Output
You input commands to MATLAB in the MATLAB Command Window. MAT-
LAB returns output in two ways: Typically, text or numerical output is re-
turned in the same Command Window, but graphical output appears in a
separate graphics window. A sample screen, with both a MATLAB Desktop
and a graphics window, labeled Figure No. 1, is shown in Figure 2–1.
Togeneratethisscreenonyourcomputer,firsttype1/2 + 1/3.Thentype
ezplot(’xˆ3 - x’). While MATLAB is working, it may display a “wait” symbol — for example,
an hourglass appears on many operating systems. Or it may give no visual
evidence until it is finished with its calculation.
As we have just seen, you can use MATLAB to do arithmetic as you would a
calculator.You can use “+” to add, “-” to subtract , “*” to multiply, “/” to divide,and “ˆ” to exponentiate.
For example,
>> 3ˆ2 - (5 + 4)/2 + 6*3
ans =
MATLAB prints the answer and assigns the value to a variable called ans.
If you want to perform further calculations with the answer, you can use the
variable ans rather than retype the answer. For example, you can compute
the sum of the square and the square root of the previous answer as follows:

>> ansˆ2 + sqrt(ans)
ans =

Observe that MATLAB assigns a new value to ans witheachcalculation.
of your choosing.
For example,

>> u = cos(10)

>> v = sin(10)
>> uˆ2 + vˆ2
ans =

MATLAB uses double-precision floating point arithmetic,which is accurate
to approximately 15 digits;however,MATLAB displays only 5 digits by default.
To display more digits, type format long. Then all subsequent numerical
output will have 15 digits displayed. Type format short to return to 5-digit
MATLAB differs from a calculator in that it can do exact arithmetic. For
example,it can add the fractions 1/2 and 1/3 symbolically to obtain the correct
fraction 5/6.
We discuss how to do this in the section Symbolic Expressions,
Variable Precision, and Exact Arithmetic Post


Related Posts Plugin for WordPress, Blogger...

civil engineering,electrical and other engg. software video tutorials.ebook and setups for free.... SAP2000,ETABS,SAFE,Autocad,revit Architecture,MS Project,Primavera ,Matlab,PSpice and much more

  © Blogger templates Newspaper III by 2008

Back to TOP