quad2d: Reached the maximum number of function evaluations

4 vues (au cours des 30 derniers jours)
Jinsoo
Jinsoo le 16 Jan 2013
Commenté : Walter Roberson le 31 Juil 2017
I'm trying to find the error in the following code. I want to iterate:
for iter = 1:10
% uallA = Int_GLA.*(-Int_GC - Int_GB) + Int_GA;
uallA = Int_GLA.*(-uallC - uallB) + Int_GA;
uallB = Int_GLB.*(-uallC - uallB) + Int_GB;
uallC = Int_GLC.*(-uallC - uallB) + Int_GC;
end
However, I receive the following error:
Warning: Reached the maximum number of function evaluations (2000). The result fails the global error test.
This is my code:
clc; clear all; close all;
x = linspace(-10, 10, 51);
t = linspace(0.1, 5, 51);
nx = length(x);
nt = length(t);
Wx = x(2) - x(1);
Wt = t(2) - t(1);
f = @(x) exp(-x.^2);
%%A right
for mx = 1:nx
for mt = 1:nt
GA = @(xi) 1./sqrt(4*pi*(t(mt))).*exp(-(x(mx) - xi).^2./(4*(t(mt)))).*exp(-xi.^2);
funGA = quad(GA, x(1), x(end));
Int_GA(mx, mt) = funGA;
end
end
figure(1)
surf(t,x, Int_GA)
xlabel('t')
ylabel('x')
zlabel('u')
%%B right
for mx = 1:nx
for mt = 1:nt
GB = @(xi) 1./sqrt(4*pi*(t(mt))).*exp(-(x(mx) - xi).^2./(4*(t(mt))))...
.*(-(x(mx) - xi)/(2*t(mt))).*exp(-xi.^2);
funGB = quad(GB, x(1), x(end));
Int_GB(mx, mt) = funGB;
end
end
figure(2)
surf(t,x, Int_GB)
xlabel('t')
ylabel('x')
zlabel('u')
%%C right
for mx = 1:nx
for mt = 1:nt
GC = @(xi) 1./sqrt(4*pi*(t(mt))).*exp(-(x(mx) - xi).^2./(4*(t(mt))))...
.*((x(mx)-xi).^2/(4*t(mt).^2) - 1./(2*t(mt))).*exp(-xi.^2);
funGC = quad(GC, x(1), x(end));
Int_GC(mx, mt) = funGC;
end
end
figure(3)
surf(t,x, Int_GC)
xlabel('t')
ylabel('x')
zlabel('u')
%%A left
for mt1 = 1:nt
for mx1 = 1:nx
GLA = @(xi, ta) 1./sqrt(4*pi*(t(mt1)-ta)).*exp(-(x(mx1) - xi).^2 ...
./(4*(t(mt1)-ta)));
funGLA = quad2d(GLA, x(1), x(end), t(1), t(mt1), 'AbsTol',1e-4, 'FailurePlot',true);
Int_GLA(mx1, mt1) = funGLA;
end
end
figure(4)
surf(t,x, Int_GLA)
xlabel('t')
ylabel('x')
zlabel('u')
%%B left
for mt2 = 1:nt
for mx2 = 1:nx
GLB = @(xi, ta) -(x(mx2) - xi)./(2*(t(mt2) - ta))./sqrt(4*pi*(t(mt2)-ta))...
.*exp(-(x(mx2) - xi).^2 ./(4*(t(mt2)-ta)));
funGLB = quad2d(GLB, x(1), x(end), t(1), t(mt2), 'AbsTol',1e-4, 'FailurePlot',true);
Int_GLB(mx2, mt2) = funGLB;
end
end
%%C left
for mt3 = 1:nt
for mx3 = 1:nx
GLC = @(xi, ta) 1./(4*(t(mt3)-ta).^2).*((x(mx3) - xi).^2 - ...
2*(t(mt3)-ta))./sqrt(4*pi*(t(mt3)-ta)).*exp(-(x(mx3) - xi).^2 ...
./(4*(t(mt3)-ta)));
funGLC = quad2d(GLC, x(1), x(end), t(1), t(mt3), 'AbsTol',1e-4, 'FailurePlot',true);
Int_GLC(mx3, mt3) = funGLC;
end
end
uallB = zeros(nx, nt);
uallC = zeros(nx, nt);
for iter = 1:10
% uallA = Int_GLA.*(-Int_GC - Int_GB) + Int_GA;
uallA = Int_GLA.*(-uallC - uallB) + Int_GA;
uallB = Int_GLB.*(-uallC - uallB) + Int_GB;
uallC = Int_GLC.*(-uallC - uallB) + Int_GC;
end
% uallA1 = Int_GA;
% uallB1 = Int_GB;
% uallC1 = Int_GC;
% uallA = Int_GLA.*(-uallC1 - uallB1) + Int_GA;
figure(5)
surf(t,x, uallA)
xlabel('t')
ylabel('x')
zlabel('u')

Réponse acceptée

Walter Roberson
Walter Roberson le 16 Jan 2013
The problem is not occurring in the "for iter" loop that you point out: it is occurring in the quad2d() call.
You should add a MaxFunEvals parameter to your quad2d() call.
Also you should be examining your failure plot.
  4 commentaires
Torsten
Torsten le 31 Juil 2017
Please show your code.
Best wishes
Torsten.
Walter Roberson
Walter Roberson le 31 Juil 2017
I think you missed the ' marks around MaxFunEvals

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by