Error using integral2
3 次查看(过去 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.
3 个评论
采纳的回答
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 个评论
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 Center 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!