Applying Restraints in Octave while Plotting a Graph

74 Views Asked by At

I am plotting a graph using Octave. I am trying to plot the graph of the following function:

$$y = \ln|\sin x| $$

Where Following Constraints Exist:

$$ 0 \le x \le 22 \land -2 \le y \le 0$$

I know how to draw the graph of basic functions using octave but i am unable to draw appropriate graph for this question. What program should i write to draw graph of above function.

Help will be highly appreciated!

1

There are 1 best solutions below

0
On BEST ANSWER

If you specifically set the values where $y<-2$ to NaN, you will get

x = linspace(0,22,1000);
y = log(abs(sin(x)));
I = find(y<-2);
y(I) = nan;
plot(x,y)

This, however, is not a recommended practice in MATLAB. You can just use logical indexing to simply write it as:

x = linspace(0,22,1000);
y = log(abs(sin(x)));
figure
plot(x(y>-2),y(y>-2))

enter image description here