Integral2 MATLAB Function Error: Q = integral2C​alc(fun,xm​in,xmax,ym​infun,ymax​fun,opstru​ct);

26 次查看(过去 30 天)
Hello,
I am facing an error with the "integral 2" function in MATLAB.
This is the integral I am trying to perform in MATLAB.
See screenshot attached:
Integration_MATLAB.png
Essentially, I made my integration variables "z" and "z_prime" symbolic variables in MATLAB.
This is so that I can use them throughout my analytical process of creating the equation "K".
The equation "K" is a function of "z" and "z_prime".
After I calculate K, I specify my integration boundaries for "z" and "z_prime". Then I "convert" to a "MATLAB Function"
For some reason, I keep getting the error: Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
I've tried looking up this error up for other cases on the MathWorks forum. I wasn't able to find something that was relevant to my case.
I've tried using the "trapz" integration function in MATLAB but I wasn't able to get anywhere with that either.
I have attached my code for reference
See code attached:
Using_Integral_2_Function.m

采纳的回答

Star Strider
Star Strider 2024-7-27,19:19
Note that because ‘zprime’ only enters into your calculations in ‘R’ and that is defined as:
R = sqrt(a^2 + (z_prime - z_prime)^2)
neither of tthem ever appears anywhere else.
Changing that to:
R = sqrt(a^2 + (z - z_prime)^2)
produces this result —
%% Starting Timer and Clearing Plots/Command Line
tic
close all; clc;
%% Fixed Variables and Parameters
% Value of j
j = 1i;
% Speed of light = c = 3*10^8 m/s
c = 3*10^8;
% Frequency = 300 MHz = 300*10^6 Hz = 3*10^8 Hz
f = 300*10^6;
% Value of lambda = c / f
% lambda = wavelength = speed of light / frequency
% lambda = 3*10^8 Hz / 3*10^8 m/s = 1 meter
lambda = c/f;
% Wavenumber value = k
k = (2*pi)/lambda;
% Intrinsic Impedance Value = eta
eta = 120*pi;
% Radius of the wire
a = 0.005*lambda;
% Length of the dipole antenna
L = 0.5*lambda;
% Number of segments
N = 23;
% Delta_Z = Spacing between each segment
% Delta_Z From Lecture Notes = Length / Number of Segments
% So, Delta_Z = L / N = L / 23;
Delta_Z = L / N;
% Declaring "z" and "z_prime" as symbolic variables in MATLAB
syms z z_prime
%% Calculating the Kernel Factor
% R equation
R = sqrt(a^2 + (z - z_prime)^2);
R = 
% Factor_1 = (-j*eta) / k
F_1 = (-j*eta) / k;
% Factor_2 = (e^-jKR) / 4*pi*(R)^5
F_2 = exp(-j*k*R) / ( 4*pi*(R)^5 );
% Factor_3 = 1 + jkR
F_3 = 1 + (j*k*R);
% Factor_4 = 2R^2 - 3a^2
F_4 = ( 2*(R)^2 ) - ( 3*(a)^2 );
% Factor_5 = (kaR)^2
F_5 = (k*a*R)^2;
% Kernel Factor
K = (F_1*F_2) * ( (F_3*F_4) + F_5);
%% Calculating Z_11
% z integral boundaries
lower_z = 0;
upper_z = L/N;
% z_prime integral boundaries
lower_z_prime = 0;
upper_z_prime = L/N;
% Defining the Integrand
Z_11_Integrand = K
Z_11_Integrand = 
% Converting the Integrand to a "MATLAB" Function
% Also, defining the integral variables "dz" and "dz_prime"
Z_11_function = matlabFunction(Z_11_Integrand, 'Vars', [z_prime, z])
Z_11_function = function_handle with value:
@(z_prime,z)(exp(pi.*sqrt((z-z_prime).^2+2.5e-5).*-2.0i).*1.0./((z-z_prime).^2+2.5e-5).^(5.0./2.0).*(((z-z_prime).^2.*2.0-2.5e-5).*(pi.*sqrt((z-z_prime).^2+2.5e-5).*2.0i+1.0)+(pi.^2.*((z-z_prime).^2+2.5e-5))./1.0e+4).*-1.5e+1i)./pi
% Using the integral2 function to calculate Z_11
% integral2 will perform the double integration across "dz" and "dz_prime"
Z_11_Result = -1 * integral2(Z_11_function,lower_z_prime,upper_z_prime,lower_z,upper_z)
Z_11_Result = 3.7295e-01 - 1.4737e+03i
toc
Elapsed time is 0.939050 seconds.
.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by