I want a vaule of function instead of formula
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jacky Wang
le 25 Mai 2023
Réponse apportée : Sugandhi
le 7 Juin 2023
I have a little complex function that need to be integrated twice. But the result is a formula that I programed. How can I fix it?
This is my code that has simplified:
syms a b x y
fun1= @(a,b,x,y)
exp(-( (a-x0).^2+(b-y0).^2 ).^2).*...
exp(-1i.*(k.* ( (a-x0).^2+(b-y0).^2 )./2) ) .*...
exp(-1i.*2.*pi.*(a.*(x-x0)+b.*(y-y0)));
f0=int(fun1,a,-limit,limit);
f0=int(f0,b,-limit,limit);
I don't need to get a more precise value. Maybe could use "double" or something.
And I tried "subs" that I found in another question place, but it has an error.
0 commentaires
Réponse acceptée
Sugandhi
le 7 Juin 2023
Hi Jacky Wang,
I understand that you want value of a complex function that need to be integrated twice.
To obtain a numerical solution for the double integral, the following might be a possible workaround:
Use the `vpa` function to evaluate the symbolic expression at a given precision. And then use the `double` function to convert the result to a double-precision floating-point number.
Here's an example of how the code can be modified to obtain a numerical solution:
syms a b x y
fun1 = exp(-( (a-x0).^2+(b-y0).^2 ).^2).*...
exp(-1i.*(k.* ( (a-x0).^2+(b-y0).^2 )./2) ) .*...
exp(-1i.*2.*pi.*(a.*(x-x0)+b.*(y-y0)));
% Define limits and precision
limit = 10;
precision = 10;
% Evaluate double integral using symbolic math
f0_sym = int(fun1,a,-limit,limit);
f0_sym = int(f0_sym,b,-limit,limit);
% Evaluate symbolic expression at given precision
f0_precise = vpa(f0_sym, precision);
% Convert result to double-precision floating-point number
f0_numeric = double(f0_precise);
In this example, the `vpa` function is used to evaluate the symbolic expression at a precision of 10 decimal digits. Adjust the `precision` argument as needed to obtain the desired level of accuracy. The `double` function is then used to convert the resulting vpa object to a double-precision floating-point number.
For more understanding, kindly go through following links:
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numbers and Precision dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!