Warning: Matrix is singular to working precision. Help
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
So I keep getting a problem with the variable u_disc. The funnction will plot the first graph but cannot plot the second one. The value for u_disc winds up being [NaN;NaN;NaN;Inf]. Not sure why its going nuts because there isn't a problem with the dimensions of A or f_x. Please help. I used n=4.
function [delta_x] = Test_1_Prob_2_KG_real(n)
%Step size
delta_x = 1/n;
%Discretized Domain
x_disc = (0:1/n:1)';
A=zeros(n);
A(1,1)=1;
A(1,2)=-1;
for i=2:n-2
A(i,i-1)=-1-(delta_x/2);
A(i,i)=2;
A(i,i+1)=-1+(delta_x/2);
end
for i=n-1
A(i,i-1)=-1-(delta_x/2);
A(i,i)=2;
end
%The function
f=ones(1,n)';
f_x=((delta_x)^2)*f;
%Discrete Solution
u_disc = (A)\(f_x);
x_exact=x_disc;
%Exact solution
u_exact = -(x_exact(2:n)).^4+1;
x_exact = (0:1/500:1)';
u_exact = (x_exact)-(exp(x_exact))-1+exp(1);
%Plot of exact solution
plot(x_exact, u_exact, 'r')
hold on
%Discrete solution
plot(x_disc(2:n), u_disc, 'o')
hold off
end
0 commentaires
Réponse acceptée
Walter Roberson
le 28 Fév 2013
You never set any value in the last row or last column of A, so it cannot be full rank.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots 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!