My equation in for loop with 180 iterations is only giving me one answer
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Sarah Brianne
el 10 de Feb. de 2019
Editada: Sarah Brianne
el 10 de Feb. de 2019
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])
0 comentarios
Respuesta aceptada
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
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.
Más respuestas (1)
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!
0 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!