Final Exam Review Part 2 - MATLAB ChE 160 SI – Becca Fall 2016
What are you concerned about? MATLAB What do you remember? What are you concerned about?
Basics What do these commands or notations do? clc clear % ; \n
Basics- Answers clc - clears command window clear - clears workspace % - makes a comment ; - suppresses values from showing in command window \n – return to the next line (like hitting enter)
Vectors Fill in where the starting and ending values go and step size/number of places in the vector. Spring_vector = _______:_______:_______ ; Spring_vector2 = linspace(_______,________,________);
Vectors- Answers Spring_vector = starting value : step size : end value ; Spring_vector2 = linspace(start, end, number points)
Assorted How do you transpose/flip a vector or matrix? What does the function input( ) do? How do you use fprintf( )?
Assorted- Answers Single apostrophe transposes column_vector = row_vector’ ; input( ) allows the user to put in a value from the command window Candy_Hearts = input(‘How many candy hearts do you eat each Valentine’s Day?’) ; fprintf( ) displays text and numbers into the command window from script fprintf(‘You eat %g candy hearts each Valentine’s Day. \n’, Candy_Hearts)
Graphing How do you plot 2 sets arrays of data? What is the difference between plot(), semilogy(), and loglog() How do you use ‘MarkerFaceColor’? What is the letter for a line, circle, and triangle? What is the letter for black, magenta, blue, green, and red?
Graphing- Answers How do you plot 2 sets arrays of data? plot(a,b) What is the difference between plot(), semilogy(), and loglog() Rectangular, semilog with y log scale, log-log plot How do you use ‘MarkerFaceColor’? Change color of the marker face in a plot to fill What is the letter for a line, circle, and triangle? ‘-’ ‘o’ ‘^’ What is the letter for black, magenta, blue, green, and red? ‘k’ ‘m’ ‘b’ ‘g’ ‘r’
Polyfit/Polyval Why do you use polyfit and polyval? What does polyfit find? What does polyval find? Fill in the blanks: __ = polyfit(_____,______,_____); __ = polyval(______,______);
Polyfit/Polyval- Answers Why do you use polyfit and polyval? Fitted line for the data, linear regression for Matlab What does polyfit find? Polynomial coefficients, m slope and b intercept What does polyval find? Fitted dependent values Fill in the blanks: P = polyfit(x,y,[degree of polynomial]); yfit= polyval(P,xfit);
What is the basic structure of… Loops What is the basic structure of… For loop If Loop While Loop
for (counting statement) calculations and statements end For Loops- Answers for (counting statement) calculations and statements end
If Loops- Answers if (conditional statement) calculation/statement elseif (conditional statement) else final option end
While Loops- Answers %Initialize value while (conditional statement) calculations end
Loops What is the difference between the structure of a for and while loop? How can you use nested for loops to create matrix?
Loops- Answers What is the difference between the structure of a for and while loop? For iterates a certain number of times, while does it until a condition is met, unknown number of iterations How can you use nested for loops to create matrix? Matricx(r,c) = 3*r-c;
Matrices [A][x] = [b] [x] = [A]\[b]
Functions Function [Outputvariable] = FunctionName(inputvariable) Calculations Outputvariable = calculation
How did that go?