MATLAB: Double integral with one changing limits integral

integrationnumeric equation solving

Hi experts,
I am trying to numerically calculate a double integral with one changing limits integral. f(x,a,b), g(y,a,b) are the functions, a and b are parameters. the integral is: h(a,b) = int [0,b/a] ( f * {int [0,x] (g*dy)} * dx). Give the value of a, I want to solve the value of b with h(a,b) = 1.
I tried to use function handles and quad() and fsolve(), there is always error saying the fsolve() cannot initiate the integration. Does anyone can help me solve this problem?
Here is my code which does not work (just a simplified version):
function test
f = @(x,a,b) sin(a*x+b);
g = @(y,a,b) quad(@(x) f(x,a,b),0,y);
h = @(a,b) quad(@(y) cos(y)*g(y,a,b),0,2);
for b=1:1:3
n =@(a) h(a,b);
fsolve(n,1)
end
Thanks!!

Best Answer

Try this is code:
f = @(x,a,b) sin(a*x+b);
g = @(y,a,b) arrayfun(@(z)quad(@(x) f(x,a,b),0,z),y);
h = @(a,b) quad(@(y) cos(y).*g(y,a,b),0,2);
out = arrayfun(@(c)fzero(@(a)h(a,c),1),1:3);