1D Poisson Solver Warning: Matrix is singular to working precision
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I can't not see any problem with the matrix but can't fix the problem.
%
x_min = 0; % min(domain)
x_max = 1; % max(domain)
H=10;
h=(x_max-x_min)/H;
x1 =(x_min:h:x_max)';
ureal=@(x) -x.^3+7;
ua = ureal(x_min); % Dirichlet condition at x=x_min
ub = ureal(x_max);
f=@(x) 6.*x;
n = length(x1);
b = -f(x1);
A = 2 * eye(n);
A = A + diag(-1*ones(n-1,1), 1) + diag(-1*ones(n-1,1), -1);
A = (1/h) * A;
A(1,:) = 0; A(1,1) = 0;
A(end,:) = 0; A(end,end) = 0;
b(1)=ua;
b(end)=ub;
u = A\b;
%%Plotting results
figure(1);
plot(x1,ureal(x1),'or');
hold on
plot(x1,u,'--.b');
xlabel('x');
ylabel('u');
legend('Exact Solution','Approximate Solution');
axis square tight; box on; grid on;
Thanks for the help:)
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!