I'm getting the error 'Subscripted assignment dimension mismatch.' for this piece of code (the last line: s(1,i)). Could anyone help me to figure out what is wrong and how to fix it? Thank you very much.
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
for i=1:n
suma1 = 0;
b=(nchoosek(q,1))*(sa1_func(t));
c=((s2_func(t)));
f=(nchoosek(q,2))*(sa2_func(t));
g=s1_func(t);
suma1 = suma1 + (b.*c)*z(1,i,1)+(f.*g)*z(1,i,2) ;
s(1,i) = (1/(h^q))*((s_func(t))*x(1,i)+(sa_func(t))*x(1,i+1)+ suma1) ;
end;
댓글 수: 5
Stephen23
2017년 1월 19일
You do not tell us the values of n, q, sal_func, t, s2_func, and maybe some others, so we cannot run your code. You also do not tell us the complete error message (this means all of the red text).
Would you like us to rely on our magical crystal balls to read your computer screen?
C.P.
2017년 1월 28일
편집: Walter Roberson
2017년 1월 29일
Walter Roberson
2017년 1월 28일
No h_func or g function, no copy of error message...
C.P.
2017년 1월 29일
편집: Walter Roberson
2017년 1월 29일
답변 (2개)
Walter Roberson
2017년 1월 29일
You have
v = linspace(t(i),t(i+1),n);
so your v is a vector. Then
b=(nchoosek(q,j))*((v-t(i)).^j);
c=(t(i+1)-v).^(q-j);
Because v is a vector, b and c are going to be vectors.
suma11 = suma11 + (b.*c)*z(m-1,i,j);%+(f.*g)*z(1,i,2) ;
vector .* vector gives vector, so suma11 is going to be a vector.
e= (1/(h^q))*((t(i+1)-v).^q)*x(m-1,i);
r=(1/(h^q))*((v-t(i)).^q)*x(m-1,i+1);
v is a vector, so e and r are going to be vectors.
s(1,i) = e+r+ suma11 ; %here is the error
e and r and suma11 are vectors, so the right hand side is a vector. But the left hand side is one individual location. You cannot store a vector into an individual location. suma11=(1/(h^q))*suma11;
suma11 is already a vector and this just scales it, leaving it a vector.
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!