1 / 19

Functions

Functions. http://www2.warwick.ac.uk/fac/sci/moac/degrees/modules/tutorial/matlab. Review. Script files Run a list of commands Flow Control If, for, while, etc. Functions. All variables are local variables. Example. Fibonacci Sequence.

stacia
Download Presentation

Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Functions

  2. http://www2.warwick.ac.uk/fac/sci/moac/degrees/modules/tutorial/matlabhttp://www2.warwick.ac.uk/fac/sci/moac/degrees/modules/tutorial/matlab

  3. Review • Script files • Run a list of commands • Flow Control • If, for, while, etc

  4. Functions • All variables are local variables

  5. Example

  6. Fibonacci Sequence • Write a function that calculates the nth number in the Fibonacci Sequence

  7. My solution

  8. or

  9. or

  10. or

  11. Multiple inputs and outputs • Comments + good layout make things easier to read, correct, use and re-use.

  12. Solving Equations • Write a function that solves • For real roots, otherwise displays an error. • Also creates a plot of this function. • And displays the real roots.

  13. My Solution

  14. What is the difference between a script and a m-file?

  15. Pendulum Simulation

  16. Inputs: • Length of pendulum • Starting pendulum angle • Hints: • To start just draw the pendulum in its starting position • Use Euler rule

More Related