How to do iterative integral with anonymous functions?

My code looks as follows:
function iter = Iteration(omega)
global zeta ratio
fun = @(x,y) exp(-x.^2/4).*x.^2.*(3*besseli(0,x.*y*1/2) -4*besseli(1,x.*y*1/2)+besseli(2,x.*y*1/2))./(myGamma(omega));
fun2 = @(y) ratio^2/4*exp(-y.^2/4).*integral(@(x) fun(x,y),0,30);
fun3 = @(x,y) exp(-x.^2/4).*x.^2.*(3*besseli(0,x.*y*1/2) -4*besseli(1,x.*y*1/2)+besseli(2,x.*y*1/2))./(myGamma(omega) - x.*fun2(x));
fun8 = @(y) ratio^2/4*exp(-y.^2/4).*integral(@(x) fun3(x,y),0,30);
iter = fun8(zeta);
end
function gamma = myGamma(omega)
gamma = 1-omega^2;
end
The main problem is in the line:
fun3 = @(x,y) exp(-x.^2/4).*x.^2.*(3*besseli(0,x.*y*1/2) -4*besseli(1,x.*y*1/2)+besseli(2,x.*y*1/2))./(myGamma(omega) - x.*fun2(x));
because fun2(x) has been defined as an anonymous function with a y-parameter, so fun2(x) won't work. Is it possible to get the anonymous function to be passed a different parameter so I can iterate it?

1 Comment

You can't put an anonymous function in an anonymous function I guess; try this:
fun2 = @(x,y) ratio^2/4*exp(-y.^2/4).*integral(fun(x,y)),0,30);

Sign in to comment.

Answers (0)

Asked:

on 28 Mar 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!