Matlab computing a wrong value

I am trying to do a simple calculation but matlab is outputting a different value than from what it should be, any ideas why?
R=0.5;
Cv=0.4;
B1= 60;
R= Cv/2*(tan(B1) + tan(B2));
[B2] = vpasolve([R], [B2]);
disp(B2);
You are supposed to find that B2 should be around 37.5 but matlab displays a value of -0.3097 so why is matlab getting a different answer?

4 comentarios

I think it's due to it being in radians but even after you convert it to degrees, the answer comes out to be -17.7 which still isn't correct.
Also when I try to use the code
R= Cv/2*(tand(B1) + tand(B2));
I get the error of
Undefined function 'tand' for input
arguments of type 'sym'.
So why exactly is that error occurring?
First two lines of code are:
clear,clc;
syms B1 B2
John D'Errico
John D'Errico el 22 de Mzo. de 2016
I answered your problem. It appears that the symbolic toolbox does not use tand. But I show there how to convert between degrees and radians.
Vidhan Malik
Vidhan Malik el 22 de Mzo. de 2016
Sorry didn't receive the notification!
John D'Errico
John D'Errico el 22 de Mzo. de 2016
There is a time lag, lol. And half the time, I answer a question, only to find that someone else has already answered while I was writing a wordy dissertation on the problem.

Iniciar sesión para comentar.

 Respuesta aceptada

John D'Errico
John D'Errico el 22 de Mzo. de 2016
Editada: John D'Errico el 22 de Mzo. de 2016
Note that the tan function uses radians, NOT degrees. So you use tan(B1), where B1 is clearly a number written in degrees.
You can either use the function tand, which works in degrees, or you can convert degrees to radians.
Next, first, you set R = 0.5, then you set it equal to Cv/2*(tan(B1)+tan(B2)). This is wrong, since you wish to SOLVE for that.
syms B2
R=0.5;
Cv=0.4;
B1= 60;
B2 = solve(R == Cv/2*(tan(B1*pi/180) + tan(B2*pi/180)))
Note the use of == in there, NOT = as you had done.
B2 =
-(180*atan(3^(½) - 5/2))/pi
vpa(B2)
ans =
37.522431511944199990343681864777

Más respuestas (0)

Etiquetas

Preguntada:

el 22 de Mzo. de 2016

Comentada:

el 22 de Mzo. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by