Numerical differentiation with change of variable

diegojolin
Messages
5
Reaction score
0
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 θ ??

thanks in advance
 
Physics news on Phys.org
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).
 
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))
 

Similar threads

Replies
4
Views
2K
Replies
4
Views
2K
Replies
29
Views
4K
Replies
6
Views
2K
Replies
8
Views
3K
Replies
1
Views
1K
Replies
9
Views
2K
Replies
4
Views
1K
Back
Top