0

I use GNU Octave 4.4.1 (x86_64-pc-linux-gnu on Arch Linux), and I have problem with fplot function. I would like to know why

fplot(@(x) 1/(1+25*x.^2),[-1,1])

Have a different result of

fplot(@(x) (1+25*x.^2).^-1,[-1,1])

(the latter returns the correct graphic)

Had the exact same problem with my students in a windows version of Octave 4.4.1.

I would like to know if it is an actual error or there's a fancy explanation for why the latter command is correct and the first one is wrong (so I can try to convince my students that they should use GNU Octave. OK, I'll try it anyway).

0

The problem is a lack of a ".", however octave should produce a error message that is not coming out. To demonstrate the difference just calculate the values to be plotted:

octave:16> x=linspace(-1,1,11)
x =

 Columns 1 through 8:

  -1.00000  -0.80000  -0.60000  -0.40000  -0.20000   0.00000   0.20000   0.40000

 Columns 9 through 11:

   0.60000   0.80000   1.00000

octave:17> 1/(1+25*x.^2)
error: operator /: nonconformant arguments (op1 is 1x1, op2 is 1x11)
octave:17> 1./(1+25*x.^2)
ans =

 Columns 1 through 7:

   0.038462   0.058824   0.100000   0.200000   0.500000   1.000000   0.500000

 Columns 8 through 11:

   0.200000   0.100000   0.058824   0.038462

So the correct form is

fplot(@(x) 1./(1+25*x.^2),[-1,1])
  • Thanks for the answer. I also don't know why the vector division doesn't return the same error I get with the multiplication without the "." – Felipo Bacani Dec 17 '18 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.