Symbolic to numeric conversion not working

7 vues (au cours des 30 derniers jours)
Eduardo Santiago
Eduardo Santiago le 9 Avr 2021
Greetings!
I have the following code where I am solving symbolically an integral in respect to 'x' an then, finally, I am trying to substitutie the symbolic values of x1 and x2 to a vector and a number of interest, respectively. So far as I could see, the code seemed to work out fine, however, the output of Y, from the subs() command, despite not seeming to output a sym variable, does not seem to convert to a double, required to make a plot. I do not not understand what am I doing wrong. As you can see, I've even desperatly tried to convert pi to pi, but to no avail.
Thank you very much in advance for your time!
clc
clear all
% não há desfazamento longitudinal
a = 0;
b = a;
s1 = 476; %um
s2 = 409; %um
L1 = s1 + a;
L2 = s2 + b;
wxo1 = 6.75;
wxo2 = 5;
lambda = 1.55;
k = 2*pi/lambda;
wx1 = 2.*L1./(k*wxo1);
wx2 = 2.*L2./(k*wxo2);
f = 220; %distância focal da lente em um
lambda = 1.55;
k = 2*pi/lambda;
syms x x1 x2
a2 = 2^(1/4)/(pi^(1/4)*sqrt(wx1)) * 2^(1/4)/(pi^(1/4)*sqrt(wx2));
b2 = exp( -(x-x1)^2/(wx1^2) ) * exp( -(x-x2)^2/(wx2^2) );
c2 = exp( -1i*k/L1 * (x-x1)^2) * exp( -1i*k/L2 * (x-x2)^2);
d2 = exp( -1i*k*x^2/(2*f) );
cx2 = abs( int(a2*b2*c2*d2, x, -10^10, 10^10) ).^2;
x1Num = linspace (-10,10,1000);
x2Num = 0;
Y = subs(cx2, {x1, x2, pi}, {x1Num, x2Num, double(pi)})
plot(x1Num,Y)

Réponses (1)

Tanmay Das
Tanmay Das le 4 Août 2021
You have been trying to integrate an expression within limits which is exceeding the bounds of double data type. MATLAB constructs the double data type according to IEEE® Standard 754 for double precision. The range for a negative number of type double is between -1.79769 x 10^(308) and -2.22507 x 10^(-308), and the range for positive numbers is between 2.22507 x 10^(-308) and 1.79769 x 10^(308). You can look into the double Documentation for further information.
In some cases, when the expression is resulting in infinite value, some random plot may get generated, but it is recommended to fix the limits of integration within the bounds of double data type. In case you want to keep the limits same, you can take the Natural Logarithm of a2*b2*c2*d2 and then plot it. This will not cause overflow as it is well within the bounds of double data type.

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by