Warning: Matrix is singular to working precision. Help

2 visualizaciones (últimos 30 días)
Kyle
Kyle el 28 de Feb. de 2013
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Feb. de 2013
You never set any value in the last row or last column of A, so it cannot be full rank.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by