Using a function in an anonymous function as input argument

Hi everyone.
I would like some help to compute the next integral:
u = integral(@(y) G(R(y)) * f(y), 0, 1)
Where R(y) = ( h(y,R(y)) + integral(G(y),R(y),y) ) / G(y)
and G( ), H( ), f( ) are known functions.
Is there anyway to put R(y) as an anonymous function or should be done in another way?. Thank you for reading this question.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 2 de Abr. de 2016
No, anonymous functions cannot refer to themselves.
R(y) = ( h(y,R(y)) + integral(G(y),R(y),y) ) / G(y) appears to be defining an ODE (Ordinary Differential Equation). The solution to that would depend a lot on the characteristics of G(y), and also somewhat on the characteristics of h()
Could you confirm that integral(G(y),R(y),y) ) is intended to be like integral of G(t) over t = R(y) to y ? I find the meaning confusing when the variable of integration and a bound are the same, so I prefer certainty about the meaning. After all, you could be asking to invoke G on y, have that return a function handle, and integrate that function handle over R(y) to y .

3 comentarios

Thanks for the answer. I'm attaching a pdf file with the full equations. Basically, G() is a cumulative density function, f() a probability density function and h() is a nonlinear equation on y. In the other hand, the integral(G(y),R(y),y)) should actually be integral(G,R(y),y)).
The equations look a bit improbable to me, but if you could supply a sample G() and f() and h() then I might be able to work through it.
I have been able to compute the integral using the composite trapezoidal rule with 100 intervals and fsolve. The problem is that I had to assume a value for one of the variables that should be solved (ommited in the pdf). My idea was to compute the integral with anonymous functions to be able to include it in the fsolve.
My code so far:
clear
clc
r = 0.04; y_0 = 0.2; alpha = 5; delta = 0.5; b = 0; c = 0.2; beta = 0.5; lambda = 0.5; m = @(x) 4*x^0.5; s = 0.3; t = 0.5;
theta = 1.24; %Variable that should be estimated
g = @(y) pdf('Uniform',y); %Uniform is chosen for simplicity
G = @(Y) cdf('Uniform',y);
IG = @(y) 1-cdf('Uniform',y);
x0 = [0.5,0.5,0];
f = @(x) ffu_3(x,0.39);
x = fsolve(f,x0)
fa = x(3);
f = @(x) ffu_3(x,0.47);
x = fsolve(f,x0)
fb = x(3);
u_1 = 0;
for k = 1:100
y = 0.39 + k*(0.47-0.39)/101;
f = @(x) ffu_3(x,y);
x = fsolve(f,x0);
u_1 = u_1 + x(3);
end
u_1 = (u_1 + (fa+fb)/2)*(0.47-0.39)/101;
---------
function F = ffu_3(x,y)
r=0.04; y_0=0.2; alpha=5; delta=0.5; b=0; c=0.2; beta=0.5; lambda=0.5; m = @(z) 4*z^0.5; s = 0.3; t = 0.5;
theta=1.24;
g = @(y) pdf('Uniform',y);
G = @(Y) cdf('Uniform',y);
IG = @(y) 1-cdf('Uniform',y);
F(1) = x(1)-((r+lambda)*G(y)*((1+t)*r*x(2)-r*s)-lambda*(integral(IG,x(1),y)-fun(y)*y))/(r*G(y)+lambda);
F(2) = r*x(2)-(b*(r*G(y)+lambda)+beta*m(theta)*(G(y)*y-s*lambda+lambda*integral(IG,x(1),y)/(r+lambda))/(1+t))/(lambda+(r+beta*m(theta))*G(y));
F(3) = x(3)-g(y)*(lambda*G(x(1)))/(lambda*G(x(1))+m(theta)*G(y));
I know the value of u_1 and I would like to estimate theta.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Numerical Integration and Differential Equations en Centro de ayuda y File Exchange.

Preguntada:

el 2 de Abr. de 2016

Comentada:

el 2 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by