VicenteC
VicenteC

Reputation: 422

Problem with Octave and the area() method

I'm trying to plot and fill the area under the graph curve using area(). It works when I give the method simple functions, ie:

WS = linspace(0,100,500);
x = 2.*(WS)
area(WS,x)

but, for some reason, this method doesn't work in Octave with 'more complex functions'. This is the script

WS = linspace(0,100,500);
TW_LCV = q.*( ( CD_min./WS) + k.*( (n./q).^2 ).*(WS) ); %the parameters are not relevant
figure()
plot(WS,TW_LCV, 'r');
hold on
area(WS, TW_LCV, 'FaceColor','y')
grid on;

I've tried the same script in Matlab, and it works. How can I fix this in Octave? The output: enter image description here

Note. I'm using Windows 10

Upvotes: 1

Views: 175

Answers (1)

Tasos Papastylianou
Tasos Papastylianou

Reputation: 22255

You are likely having infinite / nan values in your array (as in the example above, resulting from a division-by-zero operation).

Replace those values by suitable values (e.g. either get rid of inf values, or replace them by a suitably high value - or in your case possibly a zero value if that is deemed to be the limit of (x/WS)*WS for WS -> 0.

Once you only have appopriate numerical values, the area function will work as expected.

Having said that, if matlab does something with infinite values which octave treats differently, feel free to report it to the octave team in their bug tracker, since the octave team tends to treat deviations from matlab behaviour as 'bugs'.

Upvotes: 2

Related Questions