MATLAB: How can i integrate numerically by mantaining some parameters (need to differentiate later)

integrationnumericalparameter

Hi guys! I'm having problems with MATLAB, I'm not such an expert and have not used it for a bit, and I'm trying to evaluate an integral of a function with more variables. The variables are x and d (Rs,Rc have finite values that are given before). This is a piece of the function:
fun =@(x,d) 1/(((d+Rs+Rc)^2*sin(x)^2-Rs^2)^2);
This has to be integrated between 0 and pi for x. The result has to be differentiated in d after.
I= int(fun,x,0,pi); (i know this is wrond but I don't know how to write it right)
D=diff(I,d);
I get a problem of "Undefined function or variable 'd'." and can't do the integral. I don't know how to avoid the problem. i tried to solve it symbolically, but the function is too long and the program can't solve it. I don't know how to solve the problem with my actual knowledge. The final thing I need is the value of the differential as function of d.
Thanks in advance!
EDIT: If you may understand better, there it is the full expression I need to integrate-differentiate:
fun= @(x,d,Rs,Rc) 1/(((d+Rs+Rc)^2*sin(x)^2-Rs^2)^2)*( -((d+Rs+Rc)^2*cos(x)^2+(d+Rs+Rc)^2-Rs^2)/(((d+Rs+Rc)^2-Rs^2)^(1/2))+((d+2*Rs+Rc)*(d+Rc)*((d+Rs+Rc)^2*cos(x)^2+3*Rc*(d+Rs+Rc)*cos(x)+(d+Rs+Rc)^2-Rs^2)+Rc*(d+Rs+Rc)*cos(x)*(2*Rc^2+6*Rc*(d+Rs+Rc)*cos(x)+3*(d+Rs+Rc)^2*cos(x)^2))/((Rc^2+2*Rc*(d+Rs+Rc)*cos(x)+(d+Rs+Rc)^2-Rs^2)^(3/2)));
fun= @(x,d,Rs,Rc) 1/(((d+Rs+Rc)^2*sin(x)^2-Rs^2)^2)*( -((d+Rs+Rc)^2*cos(x)^2+(d+Rs+Rc)^2-Rs^2)/(((d+Rs+Rc)^2-Rs^2)^(1/2))+((d+2*Rs+Rc)*(d+Rc)*((d+Rs+Rc)^2*cos(x)^2+3*Rc*(d+Rs+Rc)*cos(x)+(d+Rs+Rc)^2-Rs^2)+Rc*(d+Rs+Rc)*cos(x)*(2*Rc^2+6*Rc*(d+Rs+Rc)*cos(x)+3*(d+Rs+Rc)^2*cos(x)^2))/((Rc^2+2*Rc*(d+Rs+Rc)*cos(x)+(d+Rs+Rc)^2-Rs^2)^(3/2)));

Best Answer

Manually differentiate "fun" with respect to d.
If the result is "dfun(x,d)", then
D = @(d) integral(@(x)dfun(x,d),0,pi,'ArrayValued',true)
should work.
Best wishes
Torsten.