Borrar filtros
Borrar filtros

Help using switch statement

3 visualizaciones (últimos 30 días)
Steven
Steven el 17 de Mzo. de 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 comentario
Oleg Komarov
Oleg Komarov el 17 de Mzo. de 2012
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 17 de Mzo. de 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 comentarios
Steven
Steven el 17 de Mzo. de 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 el 17 de Mzo. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by