Error with matrix size
Afficher commentaires plus anciens
I have a very confusing problem when working on Matlab Web version, by checking that the matrix A has a size of 9x9 but when running the program, the compiler reports an error at line 43 that the size of the matrix A is is 1x0. Please help me. Thank.

Here is my entire code:
clear all
close all
h=0.1;
k=0.01;
x=0:h:1;
n=length(x);
t=0:k:0.01;
m=length(t);
c=1;
r=(c^2*k)/h^2;
%Khai báo hàm điều kiện đầu
f=@(x) sin(pi*x)+sin(3*pi*x);
%khai báo hàm điều kiện biên
g=@(t) 0;
%khởi tạo ma trận mạng lưới
u=zeros(m,n);
%Khai báo điều kiện đầu cho mạng lưới
for j=2:n-1
u(1,j)= f(x(j));
end
%Khai báo điều kiện biên cho 2 bên lưới
for i=1:m
u(i,1)= g(x(i));
u(i,n)= g(x(i));
end
d1=zeros(n-2,1);
d2=zeros(n-2,1);
for i=1:n-2
d2(i,1)=-1;
d1(i,1)=2/r+2;
end
A=spdiags([d2 d1 d2],-1:1,n-2,n-2);
B=zeros(m-1,n-2);
for i=2:11
for j=2:n-1
B(j-1,i-1)=r*u(i-1,j-1)+(2-2*r)*u(i-1,j)+r*u(i-1,j+1)+r*u(i,j-1);
end
u(i,2:(m-1))=A\B(:,i-1);
end
surf(u)
colorbar
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!