0

I wrote a function in octave and got an error like this:

parse error near line 6 of file D:\Evan\Kuliah\Smt 4\METNUM\newton_method.m

  syntax error

 y = @3*x^2 - 4*x;e
code:
function y = df(x)
  y = @3*x^2 - 4*x;
end

I've changed the function to something like this

function y = df
  y = @3*x^2 - 4*x;
end

but the result remains the same

3 Answers3

0

The @ doesn't belong there, without it it should work fine. Also I recommend using the pointwise operators, so you can evaluate the function on whole arrays, otherwise they will be interpreted as matrix operations:

function y = df(x)
  y = 3*x.^2 - 4*x;
end
flawr
  • 10,814
  • 3
  • 41
  • 71
0

The right syntax is:

y= @(x)3*x^2-4*x

You forgot to write the variable "x" between braces after "@".

Moritz Ringler
  • 9,772
  • 9
  • 21
  • 34
Moctar
  • 1
  • 1
0

The problem is the @ sign in the function definition. In octave, the @ symbol is used to denote anonymous functions. Since you're not defining an anonymous function, you don't need it. So this should work:

function y = df(x)
  y = 3*x^2 - 4*x;
end
Nyakiba
  • 862
  • 8
  • 18