Can an anonymous function be used as an input to another anonymous function, which will be integrated?

2 views (last 30 days)
Hello, I've been having some issues with the output from a piece of my code, in that it gives infinities and sharp peaks at strange points. I'm not currently sure whether this is because I have done the maths leading me to the equations wrong, or the coding wrong, so I wanted to check the latter possibility.
What I am doing it trying to integrate an anonymous function of 3 variables, which is made up of a number of smaller functions multiplied together. The issue is that to get the correct dependence on the 3 variables, I must enter another function of them as one of the arguments in the smaller function. See the code below for what I mean. My question is, is this allowed in Matlab? If so, am I doing it wrong and how? The code is:
sigxyintegrand = @(k0,psi,psipr) vx(k0-(k00+k06*cos(6*phi+6.*psi)).*cos(psi)*tan(theta),psi).*vy(k0-(k00+k06*cos(6*phi+6.*psipr)).*cos(psipr)*tan(theta),psipr).*exp(psipr.*cos(theta)./wt0); %Defines the integrand
limit = @(k0,psi) psi*cos(theta);
Sxy = e^2*cos(theta)*m/(4*pi^3*hbar^2*omega_c)*integral3(sigxyintegrand,-pi/c,pi/c,0,(2*pi)/cos(theta),-Inf,limit);
The vx and vy functions are defined as simple functions of two variables involving sines and cosines, and e, theta, m, hbar, pi, phi, wt0 and omega_c are all constants. As you can see, changing variables from k0 to chi = the function used as an argument will not work as the two arguments are different - one depends on psi and the other on psipr. Any help in this would be hugely appreciated, thank you!
EDIT: I've now tried this via setting up another anonymous function, kz, as:
kz = @(k0,psi) k0-(k00+k06*cos(6*phi+6.*psi)).*cos(psi)*tan(theta);
sigxyintegrand = @(k0,psi,psipr) vx(kz(k0,psi),psi).*vy(kz(k0,psipr),psipr).*exp(psipr.*cos(theta)./wt0); %Defines the integrand
This clearly makes it easier to read, but doesn't seem to make it work better at all. Are there any other ways I could try and do this?

Answers (0)

Categories

Find more on Numerical Integration and Differential Equations 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!