Search code examples
matlabnumerical-integration

Function integration on Matlab


I'm trying to re-write a code from Mathematica to Matlab.

The Mathematica original code is:

Mathematica code sampple

Ok, no problem until here because I can evaluate the TT[x] function wherever I want (x, x+1, ...) and perform the numeric integral.

I want to do exactly the same thing on Matlab and here comes my problem:

TT = simplify(T);
Fx = 7.734*10^(-2)*vpaintegral(TT,x+1,0,Mu)
Result = double(Fx)

Error using sym/vpaintegral (line 131) Cannot integrate with respect to 'x + 1'. The integration variable must be a symbolic variable.

What am I doing wrong? It's possible to evaluate & integrate the function correctly on Mathematica but not on Matlab, is there another way to do it? If I introduce 'x' instead of 'x + 1' the integral works perfectly, as could not have been otherwise.

Thanks in advance!


Solution

  • why don't you replace TT by subs(TT,x,y-1) and then integrate over new symbol y, for example, I am replacing cos(x) in the below function by y and do an integration

    syms x y
    f=3/4*(1+cos(x))^2
    vpaintegral(subs(f,cos(x),y),y,0,1)