Versions Compared

Key

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

Author: Rajesh Bhaskaran, Cornell University

Problem Specification
Step 1: Find Reactions RA, RB
Step 2: Calculate σx for ri = 1 cm
Step 3: Plot σx vs. ri
Step 4: Plot σx vs. ri: Take 2
Step 5: Plot σx vs. ri, Take 3: File Input/Output
Step 6: Plot σx vs. ri, Take 4: Functions

Step 6: Plot

...

σx vs.

...

ri , Take 4: Functions

Let's create a function to calculate the bending _ stress that outputs σx given (M, ri, ro ).

Before we start doing this bring up the help file for creating functions in MATLAB. You can find it in the directory specified below:

Bring up Help > Contents > MATLAB > Programming > M-File Programming > M-File Scripts and Functions > M-File Functions.

Look at Simple Function Example: The average function that calculates the average of the elements in a vector. As you can see MATLAB has a very good help support system that you can use as a reference whenever you run into problems.

As you can see the correct syntax for creating a funcion is:

function return_value = function_name(parameter_1, parameter_2,...)

%function description - MUST  be in a comment

code...

return_value = value

Start by creating the bending stress function that outputs σx given (M, ri, ro ). 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

...