Worcester Polytechnic Institute

Variables and Arrays

Home

Google

Online Materials

Contact Us

Site Map

 

 

We can setup a variable by defining it as a scalar.  For example, enter x=1; into the Matlab command window similar to the above picture.  All entries should end in a semicolon similar to C++ notation, this suppresses the output.  Now for some algebra, what should (x+3)­2 +4 equal?  Enter the line (x+3)^2 +4 into Matlab, notice without a semicolon so the answer is displayed.  The answer is 20.  I trust that this is what Matlab responded with.

 

When we need to plot or analyze a range of values we must setup an array.  To create an array t from -10 to 10, the command is t = -10:1:10; The -10 before the colon represents the starting value, the 10 represents the final value in the array and the middle value represents the steps from start to finish.  Now we are ready to plot functions. 

 

Return to Matlab Tutorial.

 

[WPI]