필터 지우기
필터 지우기

I want a vaule of function instead of formula

조회 수: 1 (최근 30일)
Jacky Wang
Jacky Wang 2023년 5월 25일
답변: Sugandhi 2023년 6월 7일
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.

채택된 답변

Sugandhi
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개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by