matrix dimensions must agree error

1 vue (au cours des 30 derniers jours)
Alicia G
Alicia G le 24 Mai 2020
Commenté : Alicia G le 24 Mai 2020
Hello guys, I am trying to do this problem, but ı get matrix dimensions must agree error. Can you please help me with that?
a=0;
b=4;
ca=1;
cb=-3;
a1=@(x) 0.*x;
a0=@(x) (1+x);
g=@(x) 1-x.^2;
h=0.01;
N=round((b-a)/h);
x=linspace(a,b,N+1);
x=x';
G=g(x);
K=1/h^2*(2.*diag(ones(1,N+1))-diag(ones(1,N)-1)-diag(ones(1,N),1)); % heres the error 'Matrix dimensions must agree.'
A=diag(a0(x));
A(1,1)=0;
A(end,end)=0;
A1=a1(x);
B=1/(2*h)*(diag(A1(1:end-1),1)-diag(A1(2:end),-1));
B(1,2)=0;
B(end,end-1)=0;
G(1)=ca;
G(end)=cb;
K(1,1)=1;
K(1,2)=0;
K(end,end-1)=0;
K(endd,end)=1;
y=(K+B+A)\G;

Réponse acceptée

Matt J
Matt J le 24 Mai 2020
Possibly a missing comma here,
K=1/h^2*(2.*diag(ones(1,N+1))-diag(ones(1,N)-1)-diag(ones(1,N),1));
^
|
  2 commentaires
Matt J
Matt J le 24 Mai 2020
Also, a typo in this line
K(endd,end)=1;
Alicia G
Alicia G le 24 Mai 2020
thanks!! i didn't see that :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming 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!

Translated by