Cell contents assignment to a non-cell array object.

조회 수: 8 (최근 30일)
José
José 2014년 5월 29일
댓글: Udit Gupta 2014년 5월 29일
hi.
i dont know why in my code is keeping me sending this error anybody can help me please my code is:
A=input('Dame el sistema de ecuaciones expresado en forma matricial');
b=input('Dame el valor de b');
k=1;
x=input('Dame el valor x0 inicial');
x{1}=x;
r{k}=(A*x{k})-b;
p{k}=-(r{k});
for k=0:10000000000;
alfa{k}=(-(((r{k}')*r{k})/((p{k}')*(A*p{k}))));
x{k+1}=x{k}+(alfa{k}*p{k});
r{k+1}=r{k}+(alfa{k}*A*p{k});
beta{k+1}=((r{k+1})'*r{k})/((r{k}')*(r{k}));
p{k+1}=-(r{k+1})+(beta{k+1}*p{k});
k=k+1;
if (r{k}<=0)
break;
end
end
and the error is the next
*Cell contents assignment to a non-cell array object.*
*Error in gradientesconjugados (line 5)*
*x{1}=x;*
if anybody can help me i would apreciate so much.
  댓글 수: 5
José
José 2014년 5월 29일
i think that i understood you and now i change the code to this because i want to calculate matrices
A=input('Dame el sistema de ecuaciones expresado en forma matricial');
b=input('Dame el valor de b');
k=1;
x0=input('Dame el valor x0 inicial');
r(k)=(A*x0)-b;
p(k)=-(r{k});
but now i get this error
In an assignment A(I) = B, the number of elements in B and I must be the same
if anyone can help me i would apreciate so much.
José-Luis
José-Luis 2014년 5월 29일
Have you tried the debugger?

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

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 29일
Try this
clear
A=input('Dame el sistema de ecuaciones expresado en forma matricial');
b=input('Dame el valor de b');
k=1;
xx=input('Dame el valor x0 inicial');
x{1}=xx;
r{k}=(A*x{k})-b;
p{k}=-(r{k});
for k=0:10000000000;
alfa{k}=(-(((r{k}')*r{k})/((p{k}')*(A*p{k}))));
x{k+1}=x{k}+(alfa{k}*p{k});
r{k+1}=r{k}+(alfa{k}*A*p{k});
beta{k+1}=((r{k+1})'*r{k})/((r{k}')*(r{k}));
p{k+1}=-(r{k+1})+(beta{k+1}*p{k});
k=k+1;
if (r{k}<=0)
break;
end
end
  댓글 수: 3
José
José 2014년 5월 29일
편집: José 2014년 5월 29일
a change in the code the xx and the 2 but i get the same error
Cell contents assignment to a non-cell array object.
thanks for your time
Azzi Abdelmalek
Azzi Abdelmalek 2014년 5월 29일
Have you cleared your variable x?

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


Udit Gupta
Udit Gupta 2014년 5월 29일
Instead of
x=input('Dame el valor x0 inicial');
x{1}=x;
use
temp=input('Dame el valor x0 inicial');
x{1}=temp;
  댓글 수: 3
Udit Gupta
Udit Gupta 2014년 5월 29일
In the same lines as before?
Udit Gupta
Udit Gupta 2014년 5월 29일
I ran this code without any error. You need to start your loop from k=1 instead of k=0.
A=input('Dame el sistema de ecuaciones expresado en forma matricial');
b=input('Dame el valor de b');
k=1;
temp=input('Dame el valor x0 inicial');
x{1}=temp;
r{k}=(A*x{k})-b;
p{k}=-(r{k});
for k=1:10000000000;
alfa{k}=(-(((r{k}')*r{k})/((p{k}')*(A*p{k}))));
x{k+1}=x{k}+(alfa{k}*p{k});
r{k+1}=r{k}+(alfa{k}*A*p{k});
beta{k+1}=((r{k+1})'*r{k})/((r{k}')*(r{k}));
p{k+1}=-(r{k+1})+(beta{k+1}*p{k});
k=k+1;
if (r{k}<=0)
break;
end
end

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

카테고리

Help CenterFile Exchange에서 Holidays / Seasons에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by