Help using switch statement

3 views (last 30 days)
Steven
Steven on 17 Mar 2012
I have a problem dealing with a switch statement but I am having problems with it.
Here is the problem:
The following table gives the approximate values of the static coefficient of friction "u" for vaious materials.
  • Metal on metal, u=0.20
  • wood on wood, u=0.35
  • Metal on wood, u=0.40
  • Rubber on concrete, u=0.70
To start a weight 'W' moving on a horizontal surface, you must push with a force 'F', where F= u*W. Write a MATLAB program that uses the switch structure to compute the force 'F'. The program should accept as the input the value of W and the type of materials.
PLEASE HELP! Thank You.
  1 Comment
Oleg Komarov
Oleg Komarov on 17 Mar 2012
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 17 Mar 2012
This doesn't make sense. You can't switch on the input W because switch normally takes fixed, discrete values (though you can put in an expression). Plus it just doesn't make any sense to switch on W since your formula doesn't have any multiple cases that are different depending on the value of W in any way, shape, or form - it's the same formula no matter what W is - it only depends on u, not W. You could switch on u, but your instructions didn't say how u was to be decided on. Are you going to ask the user for u (or the material type) also? If so, you could switch on u (or the material name) and inside the switch perform the F=u*W formula.
  2 Comments
Steven
Steven on 17 Mar 2012
Yes, I think it says that the program should accept The input the value of W and u so that is user input. Can you help me now?
Walter Roberson
Walter Roberson on 17 Mar 2012
m = input('Whatcha gonna do?',s);
switch m
case 'petal to the metal': u = 2/9;
case 'rubber hits the road': u = 3/4;
end

Sign in to comment.

Categories

Find more on Condensed Matter & Materials Physics in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!