CME100_workbook_updated

CME100_workbook_updated - MATLAB Workbook CME100 Vector...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
MATLAB Workbook CME100 Vector Calculus for Engineers Second Edition Authors:Perrine Pepiot Vadim Khayms
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Table of Contents 1. Saving Workspace 2. Defining scalar variables 3. Vector operations ( 1 ) 4. Vector operations ( 2 ) 5. Vector operations ( 3 ) 6. Plots in 1 - D 7. How to use a script 8. ‘ If – elseif – else ’ statements 9. ‘ For ’ loops 10. ‘ While ’ loops 11. More programming examples: car motion 12. More programming examples: electric circuit 13. More programming examples: Newton’s method 14. Surfaces in 3 – D 15. Gradient 16. Motion of a particle 17. Level curves 18. Finding local minima of a function 19. Fitting data 20. Vectors of random numbers 21. More random numbers 22. Performing numerical integration 23. Computing work done by a force along a path
Background image of page 2
Getting started 1. Saving Workspace Commands : diary Start saving commands in a file diary (‘ filename ’) Start saving commands in the file filename diary off Stop the diary The diary command allows saving all command window inputs and outputs (except graphics) in a separate file, which can be opened with most text editors (e.g. Microsoft Word) and printed. Start the diary and save the file as mydiary . Compute the number of seconds in one year. Close the diary. Open the file mydiary using any text editor. SOLUTION In the Command Window : >> diary(‘mydiary’) >> 60*60*24*365 ans = 31536000 >> diary off In Microsoft Word : 60*60*24*365 ans = 31536000 diary off Hint: MATLAB workspace will be saved into a file named diary when no file name is specified. Hint : If you need help with a specific MATLAB command, simply type help command name in the command window. Detailed information will be displayed with everything needed to use this command properly. If you don’t know the exact name of the command, type lookfor keyword , which returns all the commands related to that keyword. A YOUR TURN Start a new diary and call it newdiary . Compute the product of all the integers from 1 to 9. Close the diary. Open it with a text editor and print it. 2. Defining scalar variables Commands : + - / * ^ ; Basic algebraic operations clear Clear variables from the workspace % Insert a comment MATLAB can be used as a calculator and can store the inputs or the outputs into variables. If a semicolon “ ; ” is placed at the end of a statement, the value of the variable is calculated but not displayed on the screen. To clear variables from the workspace, use the command clear .
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
SOLUTION >> % Define a >> a = 2 a = 2 >> % Define b >> b = 5 b = 5 >> % Compute c >> c = a + b^2 c = 27 >> % Compute a different value for c >> c = a + 2 * b ; >> % Display c >> c c = 12 >> % Clear all variables >> clear >> c ??? Undefined function or variable 'c' Hint: To display the current value of a variable, double-click on its name in the command window. Hint: To avoid retyping previously used command, use up and down arrows A YOUR TURN Set variable a to 12345679, variable b to 9, and assign your favorite number between 1 and 9 to c . Compute the product abc and display it on the screen. Clear all variables at the end.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 32

CME100_workbook_updated - MATLAB Workbook CME100 Vector...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online