Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

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.

1 visualización (últimos 30 días)
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 comentarios
C.P.
C.P. el 29 de En. de 2017
Editada: Walter Roberson el 29 de En. de 2017
copy of error message:
??? Subscripted assignment dimension mismatch.
Error in ==> Main at 89
s(1,i) = e+r+ suma11 ;
function y=g_func(t)
y = ((3*exp(1)-1)/(3*exp(1)))*exp(-t);
function y=h_func(t,s)
y=((1-s)*exp(-t))/3;
end
function y=fi_func(s)
y = s/2;
function y=f_func(t1,t2,t3)
y = t3*t3;
Jan
Jan el 29 de En. de 2017
Editada: Jan el 29 de En. de 2017
nchoosek(q,1)? Writing q is much easier.
Now the original code is hidden inside a comment, while the code in the question is outdated, as far as I understand. Please post the actual code inside the question, where readers expect it. Thanks.

Respuestas (2)

Sergey Kasyanov
Sergey Kasyanov el 27 de En. de 2017
As I understand, you assign vector to cell of matrix s.

Walter Roberson
Walter Roberson el 29 de En. de 2017
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.

La pregunta está cerrada.

Community Treasure Hunt

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

Start Hunting!

Translated by