Cell contents assignment to a non-cell array object.
显示 更早的评论
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 个评论
Mahdi
2014-5-29
Why are you defining the variables in a cell when you want to perform calculations on them? Why not just use matrices and then convert the result into a cell?
James Tursa
2014-5-29
编辑:James Tursa
2014-5-29
How many iterations do you expect this to take before the break happens? If the iterations go all the way to 10000000000, that will take about 2.7 terabytes of memory just to hold the variable header information (60 bytes each), and probably a gazillion hours of time since you are increasing the size of these cell arrays within a loop.
José
2014-5-29
José-Luis
2014-5-29
Have you tried the debugger?
回答(2 个)
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 个评论
Also, change the for statement to be:
for k=2:10000000000;
If your goal is to populate the elements after the first one you inputted.
Even then, I don't think it will work because you'll get NaN's as outputs.
Azzi Abdelmalek
2014-5-29
Have you cleared your variable x?
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 个评论
José
2014-5-29
Udit Gupta
2014-5-29
In the same lines as before?
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
类别
在 帮助中心 和 File Exchange 中查找有关 Holidays / Seasons 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!