0

I have a function f(x, y, z, t) which has 4 different variables, and I want to find the numerical integration of it with quad in case of just one variable:

quad(f(x,y,z,t), x, 0, inf) %// numerical integration in case of x

Is it possible? I assume I need symbolic result. Do you have any other idea?

Shai
  • 111,146
  • 38
  • 238
  • 371
frwmetric
  • 41
  • 1
  • 1
  • 6
  • If you need a symbolic result, you'll probably have to do [symbolic integration](http://www.mathworks.com/help/symbolic/int.html) then, no? :) – Eitan T May 27 '13 at 13:53
  • no, I mean y,z and t( except the x ) behave like a constant(but they are not a constant, just in this integration) I need the numerical result of x integration – frwmetric May 27 '13 at 14:03
  • That's what I said. Define your symbolic function `f` and use [`int`](http://www.mathworks.com/help/symbolic/int.html) with the syntax `int(f, x, a, b)`, specifying the numerical values for `a` and `b`. – Eitan T May 27 '13 at 14:07

1 Answers1

0

If you want to "fix" y, z and t to some parameters, say y0, z0 and t0 and integrate the function h(x) = f(x, y0, z0, t0) you can use annonymuous function:

quad( @(x) f( x, y0, z0, t0 ), x, 0, inf );

EDIT:

To get a matlab function that depends on y z and t you can do:

function area = marginalizeX( y0, z0, t0 )
% integrate f(x,y,z,t) over x while fixing y0, z0, and t0
area = quad( @(x) f( x, y0, z0, t0 ), x, 0, inf );
Shai
  • 111,146
  • 38
  • 238
  • 371
  • The result should be a function of `y0`, `z0` and `t0`, whereas in your case it is not. – Eitan T May 27 '13 at 14:05
  • @EitanT it most certainly is. The function `h(x) = f(x,y0,z0,t0)` is **parameterized** by `y0` `z0` ant `t0` changing them will change `h(x)`. – Shai May 27 '13 at 14:21
  • It's a function in the theoretical sense, but you won't get a real function in MATLAB. You will only have a numerical result corresponding to the initial values of `y0`, `z0` and `t0` for which the integration has been performed. – Eitan T May 27 '13 at 14:33
  • I think you're missing my point. What if you want to obtain the mathematical expression? What if you want to integrate first and substitute later? – Eitan T May 27 '13 at 15:20
  • @EitanT since we are talking numerical solution we do not need the mathematical expression. – Shai May 27 '13 at 15:26
  • @EitanT quoting "I want to find the **numerical** integration..." – Shai May 27 '13 at 15:36
  • Hi, sorry about this very late respond... at the end, I don't need mathematical expression but I have three integration which are separately integrated because after first integration I will plug it into another expression... Therefore, if you mean that I need an mathematical expression after the first integration... absolutely yes... but just for sure, in the first integration (suppose dx) each y,z and t just behaves like an constant they do not have any dependence to x... by the way when I used the int(f,a,b), matlab could not solve it, because of that I need a numerical integration... – frwmetric May 28 '13 at 09:27