Let's say I have a function like f(x)=x+y
, and I want to integrate with respect to x and leave y
as is. In Mathematica I can just put in Integrate[x+y, {x,0,3}]
but in Octave when I try the code below I get the error,
error: quad: evaluation of user-supplied function failed
error: called from
f at line 2 column 5
octave-test.m at line 4 column 21
Code:
function g = f(x)
g = x+y;
endfunction
[q, ier, nfun, err] = quad('f',0,3)
So how can I have a variable in there and get an output of 9/2+3y
, which is the answer to that integral?
quad
does numerical integration, it will never give you a result with a y
variable in it, the result will always be a number.
You are attempting to do symbolic math. You need the symbolic package. I found this link for how to install his package. Then the following code will do as you want:
pkg load symbolic % do this once for the session.
syms x y
f = x + y;
F = int(f, x, 0, 3)