I want a vaule of function instead of formula
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Sugandhi
2023-6-7
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numbers and Precision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!