Integration symbiolic form in matlab gives error

조회 수: 3 (최근 30일)
Anal
Anal 2024년 11월 7일
댓글: Star Strider 2024년 11월 21일
%here is my matlab script
Part_1=@(r,theta) 1+(2.*(1+r.*cos(theta))).^2;
W_i=@(r,theta) Part_1(r,theta).*(whittakerW(50, 0.5,(2.*(r))./(50)));
Matrix_element=(quad2d(W_i,0.5, 2000,0,pi));
This gives me error. What is the best way to solve this integration?

답변 (3개)

Jaimin
Jaimin 2024년 11월 7일
The error in your MATLAB script likely arises from the way you are using the whittakerW function and the quad2d function.
Ensure that the function handles you are using are properly vectorized. The quad2d function expects the integrand to accept arrays as inputs and return an array of outputs.
Make sure that the whittakerW function is available in your MATLAB environment. This function is part of the Symbolic Math Toolbox, so ensure you have it installed and the toolbox is loaded.
Kindly refer to the following code snippet for understanding.
% Define the function Part_1
Part_1 = @(r, theta) 1 + (2 .* (1 + r .* cos(theta))).^2;
% Define the function W_i, ensuring vectorization
W_i = @(r, theta) Part_1(r, theta) .* whittakerW(50, 0.5, (2 .* r) ./ 50);
% Perform the double integration using quad2d
Matrix_element = quad2d(W_i, 0.5, 2000, 0, pi);
% Display the result
disp(Matrix_element);
Kindly refer following MathWorks documentation for more information:
I hope this will be helpful.
  댓글 수: 1
Anal
Anal 2024년 11월 7일
Hi, “whittakerW” function is availble in my Symbiolic math toolbox. I have previously used that. Still it is not working.

댓글을 달려면 로그인하십시오.


Torsten
Torsten 2024년 11월 7일
편집: Torsten 2024년 11월 7일
I think you will have big problems if you try to integrate a function with values in the order of +/- 1e70.
syms r theta
Part_1= 1+(2*(1+r*cos(theta)))^2;
W_i = Part_1*whittakerW(50,0.5,2*r/50);
M = int(W_i,theta,0,pi);
rad = 0.5:0.5:2000;
plot(rad,double(subs(M,r,rad)))

Star Strider
Star Strider 2024년 11월 7일
편집: Star Strider 2024년 11월 7일
If you have R2012a or later, use the integral2 function instead —
Part_1=@(r,theta) 1+(2.*(1+r.*cos(theta))).^2;
W_i=@(r,theta) Part_1(r,theta).*(whittakerW(50, 0.5,(2.*(r))./(50)));
Matrix_element=(integral2(W_i,0.5, 2000,0,pi))
Matrix_element = -2.7744e+72
clearvars
syms r theta
Part_1(r,theta) = 1+(2*(1+r*cos(theta)))^2;
W_i(r,theta) = Part_1(r,theta).*(whittakerW(50, 0.5,(2*(r))/(50)));
Matrix_element=int(int(W_i,r,0.5, 2000), theta,0,pi)
Matrix_element = vpa(Matrix_element)
The symbolic results do not show up here after submitting the post.
.
  댓글 수: 2
Anal
Anal 2024년 11월 21일
thanks it was helpful
Star Strider
Star Strider 2024년 11월 21일
My pleasure!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by