My equation in for loop with 180 iterations is only giving me one answer

1 visualización (últimos 30 días)
I am using matlab online so can not attach file, here is my code.
Though a is a 1x180 vector my t only has one output. How do I fix this?
My graph is giving me a horizontal line at 0.9152
anglei=90;
a=linspace(0,180,180);
T=zeros(numel(a));
for n=1:numel(a)
t=((tan(anglei)-tan(a))/(tan(anglei)+tan(a)));
T(:,n)=t;
end
plot(T,a)
axis([0 180 0 1])

Respuesta aceptada

madhan ravi
madhan ravi el 10 de Feb. de 2019
Editada: madhan ravi el 10 de Feb. de 2019
You don't need a loop:
anglei=90;
a=linspace(0,180,180);
t=(tan(anglei)-tan(a))./(tan(anglei)+tan(a));
plot(t,a)
  6 comentarios
Stephen23
Stephen23 el 10 de Feb. de 2019
Editada: Stephen23 el 10 de Feb. de 2019
@Sarah Brianne: read the tan documentation, the very first line clearly states "Tangent of argument in radians". Are the angles in your code radians? (hint: degrees). I would not expect to get particularly sensible outputs until you use the correct units.
This is why you should read the documentation for every function and operator that you use, no matter how trivial you think it is.
Sarah Brianne
Sarah Brianne el 10 de Feb. de 2019
Editada: Sarah Brianne el 10 de Feb. de 2019
@Stephen Cobeldick Thank you Stephen. I did try originally in radians and it still does not look right. I try a lot of different things just post the last thing I tried. I also tried with tand

Iniciar sesión para comentar.

Más respuestas (1)

madhan ravi
madhan ravi el 10 de Feb. de 2019
If you insist loop then:
anglei=90;
a=linspace(0,180,180);
T=zeros(size(a)); % look here
for n=1:numel(a)
t=((tan(anglei)-tan(a(n)))/(tan(anglei)+tan(a(n))));
% ^^^---------------------^^^---- missed it
T(:,n)=t;
end
plot(T,a)
% Don't limit the axis let matlab interpret with the limits!

Community Treasure Hunt

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

Start Hunting!

Translated by