Unformatted text preview:

Name: _________________________________Lab #1 (for credit)Matlab IntroductionUpdated 01.31.08Points: 30Weight: 5%Purpose: The purpose of this exercise is to familiarize students with the basic functions of Matlab by providing a step by step guide into the basic, introductory concepts of Matlab. This assignment is designed to teach students how to 1) declare a Matlab variable, 2) do basic arithmetic with the variables, 3) declare an array, 4) do basic arithmetic with an array, 5) declare a simple equation and evaluate it with Matlab and 6) and plot the equation on a labeled graph.Tasks (30 points) : I. 20 points: write a Matlab program to do the following:1. Declare a set of variables and manipulate them by 2 arithmetic operations; i.e. addition, subtraction, multiplication and/or division. 2. Declare a set of arrays and manipulate them by 2 arithmetic operations; i.e. addition, subtraction, multiplication and/or division.3. Declare a mathematical equation with two variables x and y.4. Plot the above equation.II. 5 points: document the code thoroughlyIII. 5 points: run the Matlab program file created for the above 4 parts of the exercise. Then show the program and the output to your TA to receive credit for this exercise.Writing and executing a Matlab program:Before doing the above tasks, it would be helpful to know where and how to open the Matlab workspace. Click on start and then All Programs, where you will find a version of Matlab. After starting that version, a Matlab workspace window will be accessible. An alternative would be to type the command matlab at the command prompt. Matlab is mainly an interpretive language where the user can write statements one by one and run them. Using the right syntax, 1statements can be executed by typing in the command window directly and pressing enter to see the result. However, this is not the purpose here. What is needed is to create an M-file that will hold all of the Matlab statements and then run this file. M-file is a text format file and is the best way to implement the idea of a structured program in Matlab. To open an M-file: click on file, then new and open an M-file. In that file start typing the Matlab statements. After the statements are entered, save the file by clicking on file then save as and then specify the path and file name. To compile and run the M-file, press the bottom arrow on the above tab. The output for the M-file statements will be on the Matlab command prompt. But, before writing in the M-file, it would be a good idea to see how each Matlab statement is executed. For instance, type the following statement at the command box in Matlab a = 5and hit <ENTER>. The output generated by executing the statement will appear on the next linein the same window. Doing the same thing in an M-file, however, will not display the output in the same M-file window but would display it at the Matlab command prompt. The following steps are an exercise in the basic syntax of Matlab ( everything in bold indicates Matlab syntax): 1. To declare and initialize a variable ‘a’ for a value: a = 92. to add two variables ‘x’ and ‘y’: x + y3. to subtract two variables ‘x’ and ‘y’: x – y4. to multiply two variables ‘x’ and ‘y’: x * y5. to divide two variables ‘x’ and ‘y’: x / y6. to declare an array or a list ‘a’: a=3:1:10 (‘a’ is an array that starts from 3 to 10 and increment with a step of 1)7. adding and subtracting arrays is the same format as in variables8. to multiply two arrays ‘x’ and ‘y’ : x .*y9. to divide two arrays ‘x’ and ‘y’: x./y10.to declare an equation ‘y’ in function of ‘x’:- First you need to declare the domain for ‘x’ like : x=0:1:5- Then you specify you create your equation: y = x.^2 + 1 11. To plot the above function: plot(x, y)2Examples:a = 7 % declare a variable called a, initialized to 7b = 8 % declare a variable called b, initialized to 8a + b % adding the values of a and b togethera. / b % dividing the value of a by the value of ba * b % multiplying the values of a and b togethera = 1:1:5 % declaring an array called a, indexed from 1 to 5, with an increment of 1b = 5:1:9 % declaring an array called b, indexed from 5 to 9, with an increment of 1s = a + b % adding those two arrays together and storing in sy = b / a % dividing the array b by the array a and storing in yd = b - a % subtracting the array a from the array b and storing in dx = -10:0.1:10; % declaring an array variable called xy = x.^2; % declaring a function y with respect to the array xplot(x, y) % plot x with respect to


View Full Document

UT Arlington CSE 1105 - Matlab Introduction Lab 1

Download Matlab Introduction Lab 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Matlab Introduction Lab 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Matlab Introduction Lab 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?