Warning: Matrix is singular to working precision. Help
이전 댓글 표시
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개)
카테고리
도움말 센터 및 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!