How to do iterative integral with anonymous functions?
Show older comments
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
Wouter
on 28 Mar 2013
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);
Answers (0)
Categories
Find more on Structural Mechanics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!