% matlabThe system should respond (eventually) with:
Commands to get started: intro, demo, help help Commands for more information: help, whatsnew, info, subscribe >>Our first command will make a record of the session, in a file named "session". [The ">>" is Matlab's prompt, you don't need to type it]. Enter:
>> diary sessionArithmetic uses some fairly standard notation. More than one command may be entered on a single line, if they are seperated by commas.
>> 2+3 >> 3*4, 4^2Powers are performed before division and multiplication, which are done before subtraction and addition.
>> 2+3*4^2The arrow keys allow "command-line editing," which cuts down on the amount of typing required, and allows easy error correction. Press the "up" arrow, and add "/2." What will this produce?
>> 2+3*4^2/2Parentheses may be used to group terms, or to make them more readable.
>> (2 + 3*4^2)/2The equality sign is used to assign values to variables.
>> x = 3 >> y = x^2 >> y/xIf no other name is given, an answer is saved in a variable named "ans."
>> z=2*ans, ansHere z was defined in terms of ans. The result was called z, so ans was unchanged.
To get a list of your variables, use one of
>> who, whosIn Matlab, like C or Fortran, variables must have a value [which might be numerical, or a string of characters, for example]. All arithmetic is done to double precision [about 16 decimal digits], even though results are normally displayed in a shorter form.
>> a=sqrt(2) >> format long, b=sqrt(2) >> a-b >> format shortTo save the value of the variable "x" to a plain text file named "x.value" use
>> save x.value x -asciiTo save all variables in a file named mysession.mat, in reloadable format, use
>> save mysessionTo restore the session, use
>> load mysessionTo find out about this kind of thing, consult the help system. There's even an HTML version!
>> help >> help general >> docFinally, to stop Matlab and return to the operating system, use
>> quitThen, to see the saved files from your session, type
% more foo % more x.value