필터 지우기
필터 지우기

I want to integrate a symbolic matrix numerically. How can I do it??

조회 수: 1 (최근 30일)
Aninda pal
Aninda pal 2023년 4월 27일
댓글: Paul 2023년 4월 29일
clear all
clc
syms x y
A= [1 x^2+y^2;x-y x^2+y^2];
I want to numerically integrate all elements of A for x limits (0-10) and ylimits (0-15) .
Thanks for your time and help..

채택된 답변

Walter Roberson
Walter Roberson 2023년 4월 28일
Use nested vpaintegral() calls. The inner call will execute first and figure out that it cannot integrate because there is an additional free variable, so it will return a vpaintegral() data form. The outer vpaintegral will recognize the vpaintegral data form from the inner and will be able to proceed with the 2d integration.
  댓글 수: 2
Walter Roberson
Walter Roberson 2023년 4월 28일
syms x y
A= [1 x^2+y^2;x-y x^2+y^2];
result = vpaintegral(vpaintegral(A, x, 0, 10), y, 0, 15)
result = 
Aninda pal
Aninda pal 2023년 4월 29일
Thank you very much sir. This is the way exactly what I was searching for.

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

추가 답변 (2개)

Torsten
Torsten 2023년 4월 27일
syms x y
A = [1 x^2+y^2;x-y x^2+y^2];
IntA = int(int(A,x,0,10),y,0,15)
IntA = 
  댓글 수: 1
Aninda pal
Aninda pal 2023년 4월 28일
I want to do this integration numerically.. I have a larger system of equations where in matrix formation each element are functions of different variables. some cases arise where the value to integrate is constant. "int" operation is taking very long for my case. Thank you anyways..

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


Paul
Paul 2023년 4월 28일
I don't think there's a function for numerically integrating an arrayvalued function of two variables. Here's a loop approach to integrating each element of A individually using integral2
syms x y
A = [1 x^2+y^2;x-y x^2+y^2];
for ii = 1:2,
for jj = 1:2
Afun = matlabFunction(A(ii,jj),'vars',{'x' 'y'});
% add 0*x to ensure proper dimension when integrating A(1,1)
result(ii,jj) = integral2(@(x,y) Afun(x,y)+0*x,0,10,0,15);
end
end
format short e
result
result = 2×2
1.0e+00 * 1.5000e+02 1.6250e+04 -3.7500e+02 1.6250e+04
  댓글 수: 2
Aninda pal
Aninda pal 2023년 4월 29일
Thank you sir for your kind contribution, however for larger matrices using the loop is very much time taking. That is why I am searching for a another way.
Paul
Paul 2023년 4월 29일
I'd be surprised if vpaintegral is faster than integral2 for the same tolerances. Let's try it.
syms x y
A = [1 x^2+y^2;x-y x^2+y^2];
tic
for kk = 1:100
result = nan(2,2);
for ii = 1:2,
for jj = 1:2
Afun = matlabFunction(A(ii,jj),'vars',{'x' 'y'});
% add 0*x to ensure proper dimension when integrating A(1,1)
result(ii,jj) = integral2(@(x,y) Afun(x,y)+0*x,0,10,0,15);
end
end
end
toc
Elapsed time is 4.600858 seconds.
tic
for kk = 1:100
result = vpaintegral(vpaintegral(A, x, 0, 10), y, 0, 15);
end
toc
Elapsed time is 20.426502 seconds.

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

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by