Warning: Matrix is singular to working precision. Help
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Walter Roberson
2013 年 2 月 28 日
You never set any value in the last row or last column of A, so it cannot be full rank.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!