How can i solve the error in the code given below? I'm getting the following error In an assignment A(:) = B, the number of elements in A and B must be the same.
2 ビュー (過去 30 日間)
古いコメントを表示
Aqeel Mohammed Abdul Mageeth
2017 年 11 月 6 日
コメント済み: Aqeel Mohammed Abdul Mageeth
2017 年 11 月 6 日
syms T
h=1.054*(10^-34);
T=[1:20:1001];
kb=1.38*(10^-23);
g=1.1;
vd=6703.3;
M=4.6637*(10^-26);
td=355.33;
A=(h*(g^2)*(kb^2))/(M*(vd^2)*td*(h^2));
c=((kb^4).*(T.^3))/(2*(pi^2)*vd*(h^3));
g1=2*(10^-4);
V=2.0024*(10^-29);
syms x xd
syms ru(x) ru1(x) ru2(x) f(x) f1(x) q kc
ru(x)=(1./(A.*exp(-td./(3.*T)).*(T.^3)*(x^2)));
ru1(x)=(4*pi*(vd^3)*(h^4))./(g1*V*(kb^4)*(T.^4)*(x^4));
ru2=ru+ru1;
f(x)=((x^2)*exp(x))/((exp(x)-1)^2);
f1=ru2*f;
k=matlabFunction(f1);
xd=td./T ;
q=0;
kc=0;
for i=1:1:length(xd)
q(i)=integral(k,0,xd(i),'ArrayValued',true);
kc(i)=c(i).*q(i)
end
I'm getting the following error
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in hw4 (line 26)
q(i)=integral(k,0,xd(i),'ArrayValued',true);
2 件のコメント
回答 (1 件)
Robert
2017 年 11 月 6 日
Your function k returns 51 outputs. MATLAB issues that error when your code asks to store the 51 corresponding integrals in the one spot you have named: q(i). Instead, you could pre-allocate an array for q and kc and fill the rows with each iteration of the for loop.
q = nan(length(k(0)), length(xd));
kc = q;
for i=1:length(xd) % if step ~= 1, you will need to change size of q and kc
I = integral(k,0,xd(i),'ArrayValued',true);
q(i, :) = I;
kc(i, :) = c(i) .* I;
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!