# Numerical differentiation with change of variable

1. Nov 2, 2012

### diegojolin

Hi all

I am trying to solve for an integral whose integrand is a derivative that has a change of variable inside of it.

∫ (dz/dx) * cos(θ) dθ between 0 and pi.

I have a function for z(x), and also know the relation between of x and θ, but what I don't know is how to evaluate such differential-integral operation numerically with the required change of variable.

x = c/2*(1-cos(θ) )

dz/dx = dz/dθ * dθ/dx...... how can I evaluate that derivative NUMERICALLY in terms of θ ??

2. Nov 2, 2012

### HallsofIvy

What method are you using to evaluate dz/dx numerically in terms of x? I would suggest that you calculate the value of x for your given value of θ and find dz/dθ as (dz/dx)/(dθ/dx).

3. Nov 3, 2012

### diegojolin

I have finally solved it as I wanted to do it at the beginning, I still don't understand very much why this way is working and others i tried not, but so far i am happy with the results...

this is the piece of code that once run in matlab solved my problem

c = 1;
e = 1e-3;
Zc = @(x) -e.*x./c .* (x/c - 1);

N = 1e5;
xdom = linspace(0,c,N);
th = linspace(0,pi,N);

X= @(TH) c/2.*(1-cos(TH));
TH = @(X) acos(1 - 2*X/c);

Zth = Zc(X(th));

dzdth = diff(Zth) ./ diff(th);
dthdx = diff(TH(X(th))) ./ diff(X(th));
dzdx = dzdth.*dthdx;

I11 = trapz(th(2:N),dzdx)
I22 = trapz(th(2:N),dzdx.*cos(th(2:N))