1
ES2 Review fprintf(‘format, format\n’, x1, x2); Format: %d = integer, %f = decimal, %s = strings Control: \n = new line, \t = tab >eg: >>fprintf(‘The velocity is %8.4f m/s\n’, 50.617487); **NOTE %x.y (x = total, y = decimal) The velocity is 50.6175 m/s (note 8 characters total in velocity & 4 decimal places) sprintf does the same thing but saves the string to a variable >eg: >>thread = sprintf(‘The velocity is %8.4f m/s\n’, 50.617487); >>thread thread = The velocity is 50.6175 m/s linspace(x1,x2,n); Generates vector from x1 to x2 with n values >eg: x = linspace(0,1,6) yields x = 0 0.200 0.400 0.600 0.800 1.000 vectors: ; gives column, : gives row eg: [1;2;3] yields 1 [1:2:3] yields 13 3 ‘ transposes vectors, flips orientation, turns rows to columns and vice versa Indexing vectors: x(n) or x(n1:dn:n2) Where n is the number in the vector you want >eg: x = 2 4 6 8, >>x(1) yields 2, x(1:3) yields 2 4 6, x(1:2:3) yields 2 6 plot(x,y) xlabel(‘string’) ylabel(‘string’) title(‘Title Plot’) grid on/off figure creates a new plot, figure(n) accesses that number plot function outvar = functionname(argumentlist) eg: function x = freefall(speed) %function outvar = functionname(argumentlist) %blahblahblah statements x = sqrt(speed); outvar = value; MULTIPLE OUTPUTS: function [x,y] = freefall(speed) x = sqrt(speed); y = speed * 2; To integrate in script, call function, eg: z = freefall(2.4) would yield z = 1.549 Operators: == (equal), ~= (not equal), < (less than), > (greater than), <= (less/equal), >= (great/ equal) Logical Operators: ~x (true if x is false), x & y (true if x and y true), x | y (true if x or y are true) Logical variables: format is: isSomething eg: isTallerthan == 1; isTallerthan is true if something operator something for i = [1:2:10] statements statements else if something operator something end statements else while variable operator something statements statements end end

ES2 Exam 1 Review

Embed Size (px)

DESCRIPTION

Review Sheet for ES2

Citation preview

  • ES2 Review

    fprintf(format, format\n, x1, x2); Format: %d = integer, %f = decimal, %s = stringsControl: \n = new line, \t = tab

    >eg: >>fprintf(The velocity is %8.4f m/s\n, 50.617487); **NOTE %x.y (x = total, y = decimal)The velocity is 50.6175 m/s (note 8 characters total in velocity & 4 decimal places)

    sprintf does the same thing but saves the string to a variable>eg: >>thread = sprintf(The velocity is %8.4f m/s\n, 50.617487); >>thread

    thread = The velocity is 50.6175 m/s

    linspace(x1,x2,n); Generates vector from x1 to x2 with n values>eg: x = linspace(0,1,6) yields x = 0 0.200 0.400 0.600 0.800 1.000

    vectors: ; gives column, : gives row eg: [1;2;3] yields 1 [1:2:3] yields 1 33

    transposes vectors, flips orientation, turns rows to columns and vice versa

    Indexing vectors: x(n) or x(n1:dn:n2) Where n is the number in the vector you want>eg: x = 2 4 6 8, >>x(1) yields 2, x(1:3) yields 2 4 6, x(1:2:3) yields 2 6

    plot(x,y) xlabel(string) ylabel(string) title(Title Plot) grid on/offfigure creates a new plot, figure(n) accesses that number plot

    function outvar = functionname(argumentlist) eg: function x = freefall(speed)%function outvar = functionname(argumentlist) %blahblahblahstatements x = sqrt(speed);outvar = value; MULTIPLE OUTPUTS: function [x,y] = freefall(speed)

    x = sqrt(speed); y = speed * 2;To integrate in script, call function, eg: z = freefall(2.4) would yield z = 1.549

    Operators: == (equal), ~= (not equal), < (less than), > (greater than), = (great/equal)Logical Operators: ~x (true if x is false), x & y (true if x and y true), x | y (true if x or y are true)

    Logical variables: format is: isSomething eg: isTallerthan == 1; isTallerthan is true

    if something operator something for i = [1:2:10]statements statements

    else if something operator something endstatements

    else while variable operator somethingstatements statements

    end end