Numerical differentiation with change of variable

Click For Summary
SUMMARY

This discussion focuses on numerically evaluating the derivative of a function with a change of variable in the context of an integral involving the expression ∫ (dz/dx) * cos(θ) dθ. The user successfully implemented a solution using MATLAB, specifically employing the change of variable x = c/2*(1-cos(θ)) and the chain rule for derivatives. The final numerical integration was performed using the trapezoidal rule with the trapz function, yielding satisfactory results for the integral.

PREREQUISITES
  • Understanding of numerical integration techniques, specifically the trapezoidal rule.
  • Familiarity with MATLAB programming and its syntax.
  • Knowledge of calculus, particularly derivatives and integrals involving change of variables.
  • Basic understanding of trigonometric functions and their properties.
NEXT STEPS
  • Explore MATLAB's numerical integration functions beyond trapz, such as quad or integral.
  • Learn about the chain rule in calculus and its applications in numerical differentiation.
  • Investigate other numerical methods for solving integrals with variable changes, such as Simpson's rule.
  • Study the implications of different choices of variable transformations on numerical stability and accuracy.
USEFUL FOR

Mathematicians, engineers, and data scientists who are involved in numerical analysis, particularly those working with integrals and derivatives in MATLAB.

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 ·
Replies
4
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 29 ·
Replies
29
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K