% This is demoscript.m, a demonstration script file.

% M. M. Sussman
% $Date: 2013/01/01 21:28:47 $

% Comments start with a percent ("%") character.
% Variables start with a letter, can be any length
% and are CASE SENSITIVE.
x=1.3

% If you want to set a variable and do not want
% to get its value printed out, end the statement
% with a semicolon
xsquared=x^2;

% Later on you can print the variable by typing its name
xsquared

% multiplication, division, addition, subtraction as usual
p=(3*x^2+4*x-1)/5

% pi (the ratio of circumference of a circle to diameter) is 
% a fixed constant in Matlab
pi
theta=3*pi/4;

% All the elementary functions are there, too
adjacent=sin(theta)

% Complex numbers are available, with either i or j used to
% represent the sqrt(-1)
z=3+2i

% Matlab knows about complex arithmetic and elementary functions
zsquared=z^2
logz=log(z)

% Use a "for" statement to do loops
% use parentheses for subscripts
% It is a good idea to use indenting in for loops
for index = 1:10
  cuberoots(index)=(index)^(1/3);
end

% Strings are enclosed in single quotes.  They are constants
% and placing them on the command line causes them to be
% reflected just as with any constant
'The following is a list of cube roots.'
cuberoots

x=1;
% The following statement, without comment character, will 
% cause an error when executed.
% If you have turned on debugging with "dbstop if naninf"
% the error will bring up a debug window.
%bad=1/(x-1)
