How to solve such integrations on MATLAB?

5 visualizzazioni (ultimi 30 giorni)
For domain, i.e, z is a complex variable in the unit disk, and for n any natural number, we can integrate functions like F(z) but MATLAB doesn't give answers to integrations like G(z), how should i do it? Also, my limits of integration are 0 to z where z .
Is there any numerical method that we can apply like quadgk?, you can see a reference of how to apply quadgk on such integrations in one of my questions asked because i didn't understand that. Also, some other analytic technique if there is like partial fractions or something?
syms z n;
F=int(1/(1-z^n),z)
G=int(z^(3*n-1)/(1-z^(2*n)),z)

Risposta accettata

Torsten
Torsten il 7 Set 2023
Modificato: Torsten il 7 Set 2023
Invest a little time and deduce
z^(3*n-1)/(1-z^(2*n)) = -z^(n-1) + 0.5*z^(n-1)/(1-z^n) + 0.5*z^(n-1)/(1+z^n)
This function can be integrated analytically:
syms z
syms n integer
f = -z^(n-1) + 0.5*z^(n-1)/(1-z^n) + 0.5*z^(n-1)/(1+z^n);
F = int(f)
F = 
simplify(diff(F))
ans = 

Più risposte (2)

Mrutyunjaya Hiremath
Mrutyunjaya Hiremath il 7 Set 2023
The 'quadgk' function in MATLAB can be used for numerical integration. However, since you're dealing with complex variables, you might need to handle the real and imaginary parts separately or look for specialized numerical methods for complex functions.
Here's how you can use quadgk to evaluate the integral for F(z):
n_value = 2; % replace with the value of n you're interested in
z_value = 0.5 + 0.5i; % replace with the value of z you're interested in
realPart_F = @(z) real(1 ./ (1 - z .^ n_value));
imagPart_F = @(z) imag(1 ./ (1 - z .^ n_value));
real_integral = quadgk(realPart_F, 0, z_value);
imag_integral = quadgk(imagPart_F, 0, z_value);
integral_F = real_integral + 1i * imag_integral;
disp(integral_F);
0.4024 + 0.5536i
  4 Commenti
Torsten
Torsten il 7 Set 2023
Modificato: Torsten il 7 Set 2023
Your first code was correct.
n = 2; % Replace with your desired value for n
z_target = 0.5 + 0.5*1i; % Replace with your desired value for z
% Parametrize path from 0 to z
para = @(t) z_target*t;
dpara = @(t) z_target*ones(size(t));
f = @(z,n) 1./(1-z.^n);
fun_to_integrate = @(t,n) f(para(t),n).*dpara(t);
Fz_result = integral(@(t)fun_to_integrate(t,n),0,1)
Fz_result = 0.4024 + 0.5536i
syms z
f = 1/(1-z^n);
Fz_result = int(f,z,0,z_target);
double(Fz_result)
ans = 0.4024 + 0.5536i
Walter Roberson
Walter Roberson il 7 Set 2023
But I don't want to fix n and z. I want the answer in terms of function of z, since 0 to z are the limits.
quadgk() is strictly a numeric integration routine. No numeric integration routine is going to be able to return a symbolic function.

Accedi per commentare.


David Goodmanson
David Goodmanson il 7 Set 2023
Modificato: David Goodmanson il 7 Set 2023
Hi simran,
for any general function f(z) and a set of points [z1, z2, z3 ...] that describes a path in the complex plane (not necessarily a closed path) then numerically you have
function I = contourint(z,f)
%
% complex contour integral by simple trapezoidal method.
% z is a path in the complex plane, f(z) is the integrand
% path does not have to be closed.
%
% I = contourint(z,f)
I = (1/2)*sum((f(1:end-1)+f(2:end)).*diff(z));
Of course you want the z points to be closely spaced enough to describe the path well, and also closely spaced enough to describe f(z) well, if f(z) varies quickly along the path. A typical case of that is when the path goes close by to a pole in f(z), and you need a denser set of z points in that section to pass by the pole. (No need for all the z points to be equally spaced along the path in terms of the distance between them). Don't be afraid to use lots of points, many thousands or more work well before you reach the point of diminishing returns.
This all makes the most sense when f(z) is analytic, but numerically there is not even a requirement for that.
Here are some simple examples where the path is closed and runs around the unit circle
n = 1e5;
th = ((0:n)/n)*2*pi;
z = exp(i*th); % closed path around the unit circle
zin = (1/2)+i*(1/3); % first order pole inside the path
f = 1./(z-zin);
I1 = contourint(z,f)
zout = 2+3*i; % first order pole outside the path
f = 1./(z-zout);
I2 = contourint(z,f)
f = 1./(z-zin).^2; % second order pole inside the path
I3 = contourint(z,f)
f = (z-zin).^3 + (z-zout).^2; % no singularities inside the path
I4 = contourint(z,f)
% results
I1 = 0.0000 + 6.2832i % = 2*pi*i*residue ok
% all these are zero
I2 = -2.2204e-16 - 1.1102e-16i
I3 = -6.6613e-16 - 1.6931e-15i
I4 = -8.8818e-15 + 1.7764e-15i
% example, integral for bessel function J1(a)
a = 2;
f = exp((z-1./z)*a/2)./(z.^2);
J1a = (1/(2*pi*i))*contourint(z,f)
% check
J1a_exact = besselj(1,a)
J1a - J1a_exact
J1a = 0.5767 - 0.0000i
J1a_exact = 0.5767
ans = -3.7947e-10 - 4.4174e-17i

Prodotti


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by