Error using integral2

1 次查看(过去 30 天)
I have following expression with
x=[1 2 3 4 5]
y=[1 2 3 4 5]
L = 100; % Length of the box
p=1;
q=1;
Ui = @(x,y) sin(pi*x).*sin(pi*y); % An initial distribution for u, i.e. the u(x,y,0)
Vi = @(x,y) sin(pi*x).*sin(pi*y); % An initial distribution for v, i.e. the v(x,y,0)
Wi = Ui(x,y) + Vi(x,y); % Initial condition for w, i.e. w(x,y,0)
% Computation of the b-coefficients
if p < Ntrunc
if q < Ntrunc
my_integrand = @(x,y) 4*Wi.*sin(p.*x).*cos(q.*y)/L^2;
bd(p,q) = integral2(my_integrand(x,y),0,L,0,L);
q = q+1;
end
p = p+1;
end
I got following error,
Error using integral2Calc>integral2t/tensor (line 231)
Input function must return 'double' or 'single' values. Found 'function_handle'.
Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral2 (line 106)
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
Correction will be highly appreciated.

采纳的回答

Star Strider
Star Strider 2018-11-15
编辑:Star Strider 2018-11-15
This works, although it throws a warning:
Ntrunc = 100;
L = 100; % Length of the box
p=1;
q=1;
Ui = @(x,y) sin(pi*x).*sin(pi*y); % An initial distribution for u, i.e. the u(x,y,0)
Vi = @(x,y) sin(pi*x).*sin(pi*y); % An initial distribution for v, i.e. the v(x,y,0)
Wi = @(x,y) Ui(x,y) + Vi(x,y); % Initial condition for w, i.e. w(x,y,0)
% Computation of the b-coefficients
if p < Ntrunc
if q < Ntrunc
my_integrand = @(x,y) 4*Wi(x,y).*sin(p.*x).*cos(q.*y)/L^2;
bd(p,q) = integral2(@(x,y)my_integrand(x,y),0,L,0,L);
q = q+1;
end
p = p+1;
end
I defer to you to correct the problem that produces the warning.
EDIT — Corrected typographical error.
  10 个评论
Shahid Hasnain
Shahid Hasnain 2018-12-3
Sorry for being late.
I am trying to solve Gray Scott Model in 2 dimension by analytical technique. the code I attached few days back, it was a try to find analytical solution.
Here is the system
u_t = u_{xx} + u_{yy} - uv^2 + 1 - u
v_t = v_{xx} + v_{yy} + uv^2 - v
I do not have analytical solution to this problem, thats why we choose another way to find.
w=u+v (wexact_Patrick, it was mentioned in previous posts) working
d=u-v (it was mentioned in previous posts) half working still.
Still working to rearrange integral3 which create problems.
Star Strider
Star Strider 2018-12-3
No worries about a delayed reply.
Do you want to integrate a system of partial differential equations? If so, please post this as a new Question. My experience with the Partial Diufferential Equation Toolbox is limited, although Torsten and some others here likely have significant experience with it. I have not worked with it in a while, so it would take some time for me to provide you with a response.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by