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;
Best Answer