Why do I keep getting infinity as my script answer?

I am trying to write a script that requests user input for belt angle β(beta), friction coefficient μ(mu), and one of the forces F2. The script then computes the corresponding force F1, and reports the answer using a disp([ ]) sentence. This is my code thus far:
prompt= 'State the belt angle beta: ';
beta = input(prompt, 's');%degrees
prompt= 'State the friction coefficient mu: ';
mu = input(prompt, 's');
prompt= 'State the Force F2: ';
F2 = input(prompt, 's');%Newtons
F1 = F2.*exp(mu.*beta);%Newtons
format bank
disp(['The corresponding force F1 is ',num2str(F1), '.']);
My script is called BeltForces.m and the result I get is this:
>> BeltForces
State the belt angle beta: 130
State the friction coefficient mu: 0.3
State the Force F2: 100
The corresponding force F1 is Inf Inf Inf.
Why am I getting infinity? My teacher told us to watch out for radians and to "Be careful with β, because math operations like e and sin require unitless input arguments."....Could this be why I am getting infinity?

 Respuesta aceptada

KSSV
KSSV el 6 de Mzo. de 2018
You need to convert beta, mu and F2 into numbers..using str2num
prompt= 'State the belt angle beta: ';
beta = input(prompt, 's');%degrees
beta = str2num(beta) ;
prompt= 'State the friction coefficient mu: ';
mu = input(prompt, 's');
mu = str2num(mu) ;
prompt= 'State the Force F2: ';
F2 = input(prompt, 's');%Newtons
F2 = str2num(F2) ;
F1 = F2.*exp(mu.*beta);%Newtons
format bank
disp(['The corresponding force F1 is ',num2str(F1), '.']);

4 comentarios

Steven Lord
Steven Lord el 6 de Mzo. de 2018
Or just remove the 's' from the input statements.
Thank you it worked! But how do I get an whole number?
>> BeltForces
State the belt angle beta: 130
State the friction coefficient mu: 0.3
State the Force F2: 100
The corresponding force F1 is 8.659340042399411e+18.
For example I know the answer is supposed to be 197.5217, do you know how I could change my code to get it like that?
@KSSV: it is recommended to use str2double, which avoids the eval inside str2num:
beta = str2double(input(prompt, 's'));
Steven Lord
Steven Lord el 6 de Mzo. de 2018
Is the belt angle supposed to be in degrees (as you've entered it) or in radians? A quick experiment with deg2rad suggests it is supposed to be entered in radians based on your expected value.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre General Applications en Centro de ayuda y File Exchange.

Preguntada:

el 6 de Mzo. de 2018

Comentada:

el 6 de Mzo. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by