You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

Step 6: Plot sigma_x vs. ri, Take 4: Functions

Let's create a function to calculate bending_stress that outputs σx given (M, ri, ro )

Bring up Help > Contents > MATLAB > Programming > M-File Programming > M-File Scripts and Functions > M-File FunctionsLook at Simple Function Example: The average function that calculates the average of the elements in a vector.

Create bending_stress function

 
Save this as bending_stress.mMake a copy of beam3.musing Save As ... call the new file beam5.m

Comment out


 
Call function bending_stress
Run and check output

Before we part, let's remind ourselves of some important programming guidelines that we have followed in this tour:

  • Develop code incrementally, testing obsessively at each stage. Develop a plan for how you are going to build your code before you sit at the computer.
  • Dig through the MATLAB help diligently to figure out how to use specific functions etc. Usually, the examples are the best place to start. This is a better strategy than desperately hunting for the TA every time you need help with your code.
  • Comment your program liberally.
  • No labels