Subscripted assignment dimension mismatch. Error in main (line 17) [y(:,6), a6] = curvepoly(​x_heun,y_h​eun,6);

조회 수: 1 (최근 30일)
this worked for me fine yesterday, I haven't changed anything and today it says Subscripted assignment dimension mismatch.
Error in main (line 17)
[y(:,6), a6] = curvepoly(x_heun,y_heun,6);
Why? and how do I fix it?
fx = inline('(y - ((y.^2)./x)./x)','x','y');
x0 = 1;
xf = 5;
y0 = 1;
tol = 0.001;
N = [1:0.1:5];
for i = 1:length(N)
[y_heun, x_heun] = Heun(fx,x0,xf,y0,N(i),tol);
[y(:,2), a2] = curvepoly(x_heun,y_heun,2);
end
function [y,a] = curvepoly(x_heun,y_heun,order)
j = order;
for k = 1:j + 1;
for i = 1:j + 1;
A(k,i) = sum(x_heun.^((k+i-2)));
end
end
for i = 1:j + 1;
B(i,:) = sum(y_heun.*x_heun.^(i-1));
end
a = inv(A)*B;
y = 0;
for i = 1:j+1
y = y+a(i).*x_heun.^(i-1);
end

답변 (1개)

Matt J
Matt J 2013년 4월 26일
The line in your error message does not appear in your code. I do see the rather similar line
[y(:,2), a2] = curvepoly(x_heun,y_heun,2);
which makes rather little sense within a loop over i, since it will just repeatedly overwrite y(:,2) and a2.
Perhaps that's what you changed.
  댓글 수: 1
Matt J
Matt J 2013년 4월 26일
Aside from that, your function curvepoly returns a vector of length order+1. If size(y,1) does not match this, it would result in the error you've shown.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Functional Programming에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by