Question

Student have done some work in lab-2-sample with graphs, in which it includes how each graphs should be labeled we have to do activity 1 and activity 2, using the

format provided Need Matlab code + output screen shots + lab report/n EQUIPMENT: Objectives: Department of Mechanical Engineering Technology EXPERIMENT #2 Call functions, Graphs of functions and script files MATLAB software o create variables and call functions in MATLAB Introduction: o create graphs of functions o create script files MATLAB is a software application using high-level language for numerical computation, graphing, and programming. You can use MATLAB to solve arithmetical equations and graph different functions. MATLAB language, tools, and built-in math functions allow you to explore multiple methods to solve and graph equations faster than with spreadsheets or traditional programming languages, such as C/C++ or Java. MATLAB is used in variety of applications, including signal processing and communications, image and video processing, control systems, test and measurement, computational finance, and computational biology. The desktop shown in figure 1 includes these panels: ● › Current Folder Access your files. · Command Window Enter commands at the command line, indicated by the Prompt (>>). • Workspace - Explore data that you create or import from files 1 T T T *****Use the help in MATLAB for functions and information***** AMATLAB R2015a HOME Find Files New New Open Campar Script FILE Name RL.mdl VARIABLE 4444FC: Users hnamdar Documents MATLAB Command Window Current Folder cGraph.fig ricGraph.jpg Procedure: 2 PLOTS APPS New Variable Open Variable Import Save Data Workspace Clear Workspace O 5 >> c= a + b a-2 2 >>55 >> 0. Analyze Code Run and Time Clear Commands CODE This is a Classroca License for instructional use only. Research and commercial use is prohibited. Preferences Lavout Path ENVIRONMENT 2. Create a few more variables. >> b=5 b = Help Community Request Support Add-Ons RESOURCES Fig 1-MATLAB desktop Search Uocumentation 1. As you work in MATLAB, you issue commands that create variables and call functions. You can also put comments in your program by using the following example: >> % Add Comments to Programs using the percent (%) symbol. % start by adding your name, date and lab number using the symbol (%) 2 Workspace Name Ha BE Value 2 5 7 Example 1-create a variable named a by typing this statement at the command line: >> a = 2 MATLAB adds variable a to the workspace and displays the result in the Command Window. a = P C = 7 3. Find the cosine of a: >> d = cos (a) When you do not specify an output variable, MATLAB uses the variable ans, short for answer, to store the results of your calculation. >> sin (1) ans = 0.8415 4. If you end a statement with a semicolon, MATLAB performs the computation, but suppresses the display of output in the Command Window. >> e = a*b; 5. You can recall previous commands by pressing the up- and down-arrow keys, ↑ and ↓. Press the arrow keys either at an empty command line or after you type the first few characters of a command. For example, to recall the command b = 2, type b, and then press the up-arrow key. *****The command clc clears the Command Window* **** clc Table 1.1-Functions use in MATLAB Function Addition times, .* rdivide, ./ Square root Exponential- ex Power or A try it. 3 Syntax in MATLAB C1 = A + B C2 = plus(A,B) C3= A.*B C4 = times(A,B) x1 = A./B x2 = rdivide(A,B) B1 = sqrt(X) Y1 = exp(X) C5 = A.^B C6 = power(A,B) sum Activity 1 Use each function in table 1.1 to find all values of C1,C2, C3, C4, C5, C6, x1, x2, B1, Y1 and S if A = 10, B = 25 and X =4. Print out the result and hand it in with your report. Insert your name and other information on the top of your program. >> x = 0:pi/100:2*pi; >> y = sin(x); >> plot(x,y) Line Plots 6. To create two-dimensional line plots, use the plot function. For example, plot the value of the sine function from 0 to 2 pi: AA= 1:6, S = sum (AA) >> ylabel('sin(x)') >> title('Plot of the Sine Function') 7. To add plots to an existing figure, use hold command. hold on 8. You can label the axes and add a title using the following commands; >> xlabel('x-axis') 4 1 0.8 0.6 0.4 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 0 1 2 >> plot(x,y,'r--') >> x = 0:pi/100:2*pi; >> y2 = cos(x); >>plot(x,y2, 'g-.') 3 4 5 6 9. By adding a third input argument to the plot function, you can plot the same variables using a red dashed line. 7 5 >> legend('sin','cos') ****Until you use hold off or close the window, all plots appear in the current figure window. **** 10. Example of RLC circuit plot. Run the following program one line at a time and print out the program and the graph. Also label the axes. >> t = 0.1:6;/n EQUIPMENT: Objectives: Department of Mechanical Engineering Technology EXPERIMENT #2 Call functions, Graphs of functions and script files MATLAB software o create variables and call functions in MATLAB Introduction: o create graphs of functions o create script files MATLAB is a software application using high-level language for numerical computation, graphing, and programming. You can use MATLAB to solve arithmetical equations and graph different functions. MATLAB language, tools, and built-in math functions allow you to explore multiple methods to solve and graph equations faster than with spreadsheets or traditional programming languages, such as C/C++ or Java. MATLAB is used in variety of applications, including signal processing and communications, image and video processing, control systems, test and measurement, computational finance, and computational biology. The desktop shown in figure 1 includes these panels: ● › Current Folder Access your files. · Command Window Enter commands at the command line, indicated by the Prompt (>>). • Workspace - Explore data that you create or import from files 1 T T T *****Use the help in MATLAB for functions and information***** AMATLAB R2015a HOME Find Files New New Open Campar Script FILE Name RL.mdl VARIABLE 4444FC: Users hnamdar Documents MATLAB Command Window Current Folder cGraph.fig ricGraph.jpg Procedure: 2 PLOTS APPS New Variable Open Variable Import Save Data Workspace Clear Workspace O 5 >> c= a + b a-2 2 >>55 >> 0. Analyze Code Run and Time Clear Commands CODE This is a Classroca License for instructional use only. Research and commercial use is prohibited. Preferences Lavout Path ENVIRONMENT 2. Create a few more variables. >> b=5 b = Help Community Request Support Add-Ons RESOURCES Fig 1-MATLAB desktop Search Uocumentation 1. As you work in MATLAB, you issue commands that create variables and call functions. You can also put comments in your program by using the following example: >> % Add Comments to Programs using the percent (%) symbol. % start by adding your name, date and lab number using the symbol (%) 2 Workspace Name Ha BE Value 2 5 7 Example 1-create a variable named a by typing this statement at the command line: >> a = 2 MATLAB adds variable a to the workspace and displays the result in the Command Window. a = P C = 7 3. Find the cosine of a: >> d = cos (a) When you do not specify an output variable, MATLAB uses the variable ans, short for answer, to store the results of your calculation. >> sin (1) ans = 0.8415 4. If you end a statement with a semicolon, MATLAB performs the computation, but suppresses the display of output in the Command Window. >> e = a*b; 5. You can recall previous commands by pressing the up- and down-arrow keys, ↑ and ↓. Press the arrow keys either at an empty command line or after you type the first few characters of a command. For example, to recall the command b = 2, type b, and then press the up-arrow key. *****The command clc clears the Command Window* **** clc Function Addition Table 1.1-Functions use in MATLAB times, .* rdivide, ./ Square root Exponential- ex Power or .^ sum try it. 3 Syntax in MATLAB C1 = A + B C2 = plus(A,B) C3= A.*B C4 = times(A,B) x1 = A./B x2 = rdivide(A,B) B1 = sqrt(X) Y1 = exp(X) C5 = A.^B C6 = power(A,B) AA= 1:6, S = sum (AA) Use each function in table 1.1 to find all values of C1,C2, C3, C4, C5, C6, x1, x2, B1, Y1 and S if A = 10, B = 25 and X =4. Print out the result and hand it in with your report. Insert your name and other information on the top of your program. >> x = 0:pi/100:2*pi; >> y = sin(x); >> plot(x,y) Activity 1 6. To create two-dimensional line plots, use the plot function. For example, plot the value of the sine function from 0 to 2 pi: Line Plots 7. To add plots to an existing figure, use hold command. >> hold on >> ylabel('sin(x)") >> title('Plot of the Sine Function') 8. You can label the axes and add a title using the following commands; >> xlabel('x-axis') >> plot(x,y,'r--') >> x = 0:pi/100:2*pi; >> y2 = cos(x); >>plot(x,y2, 'g-.') 9. By adding a third input argument to the plot function, you can plot the same variables using a red dashed line. >> legend('sin','cos') ****Until you use hold off or close the window, all plots appear in the current figure window. **** 4 10. Example of RLC circuit plot. Run the following program one line at a time and print out the program and the graph. Also label the axes. >> t = 0:.1:6; >> i= 3*exp(-t)- 3*exp(-2*t); >> vr=3*i; >> vl= -3*exp(-t)+6*exp(-2*t); >> vc= 3 + 2 * (-3*exp(-t)+3/2*exp(-2*t)); >> plot (t,i) hold on >> plot (t,vr,'r--') >> plot(t,vl,'b:') >> plot(t,vc,'g-.') >> legend('i','vr','vl','vc') >> title(ʻyour name RLC circuit graph') 3 2.5 2 1.5 1 0.5 -0.5 0 0.5 1 1.5 2 2.5 5 3 3.5 vr vl - VC 4 Using Script Files The above method was one way of performing operation in MATLAB which is the interactive mode. Another way of implementing operation in MATLAB is to store the program in a script file. The script file contains MATLAB commands which you save in a file, and you run it by typing the name of the file.