I have the following problem in matlab:
i need to create a function (well, it is rather relationship between x and y than function) which should look like this:
function y = fcn(x)
Bext = 0.6;
G = 10.553;
if x < 0
y = 0;
elseif x == 0
y = 10^10;
elseif x == 180
y = 10^10;
elseif x > 180
y = 0;
else
y = 1./(G.*Bext.*(sind(x)));
end
end
Basically, for all x below 0 y should be 0, the same in case of x larger than 180. For all x in the range 1-179 i need to have a function 1/sin(x), and for x=0 and x=180 which is infinity(singularity) for the function 1/sin(x) i set the cap like 10^10 (any big number different than infinity will do). Here I treat x as an angle and I work with angle step deltax=1.
As far as I know the code above correctly computes y for any given x. The problem begins when I want to work on a range of x values, even simple plotting :
x=-10:200;
plot(x,fcn(x))
shows the function 1/sin(x) exists even outside the range (x=1:179) defined in the simple code above.
So the question is why I still see the function y=1/sin(x) where it should be y=0 and how to limit/bound the function to the defined range.
Thanks for help in advance.
Roger Kalvig