Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A few noteworthy points to ponder:

  1.  {{return_value }} is the only data that gets passed back to the main code.
  2. You do not need to have a function description but it is good programming practice to add a comment on each function that describes what the function does. Also, if you add a description of the function, MATLAB will be able to index it and return a description of your function if you type help function_name in the Command Window.
  3. Once you have created a function you MUST name the .m file with the same name the function has. Otherwise MATLAB will not be able to access your function when you call it.

We will start by creating the bending stress function that outputs σx given (M, ri, ro ). Create a new page in the editor. Type in the following statements into the new page (yeah, yeah, yeah ... go ahead :
Image Added{{}}You can be lazy like me and copy-and-paste ): Image Removedthe last two statements from your previous code. Save this file as bending_stress.m, which is the name that MATLAB automatically assigns the file. Notice is . Thus, the function name and the .m have the same name as the function name.  .
Bring up beam3.m in the MATLAB editor. Make a copy of beam4beam3.m using Save As ...  and call the new file beam5.m
. In this file comment out the lines below since this evaluation is now done within the function.


 

Now we will need to call the function bending_press we just created to obtain the value for σx that is needed to create the plot. Do this by typing:

We'll replace these statements with a call to the bending_stress function. The following statement does this:

Image Added
Add this to beam5.m. Run the file Image Removed
Run  the file beam4.m and check the output  You should get the same plot you got in the file with beam3.m.

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

...