Can anyone please debug the error

3 ビュー (過去 30 日間)
Kane0610
Kane0610 2014 年 5 月 20 日
回答済み: shimels gbre ab abebe 2021 年 6 月 20 日
My function is as follows
function F = myobjfun(x,y) syms i x y k F = symsum(((y(3).*x(i).*log(1+x(i))/symsum(x(k),k,0,9)-(y(2).*x(i))),i,0,9); end
when i am passing x=[1,2,....10], y=[0.5,0.5]
I am getting the following error
Error using mupadmex Error in MuPAD command: Index exceeds matrix dimensions.
Error in sym/subsref (line 1580) B = mupadmex('symobj::subsref',A.s,inds{:});
Error in myobjfun (line 4) F = symsum(((y(3).*x(i).*log(1+x(i)))-(y(2).*x(i))),i,0,9);

採用された回答

Pedro Villena
Pedro Villena 2014 年 5 月 20 日
編集済み: Pedro Villena 2014 年 5 月 20 日
You had made some errors:
  • symsum is a symbolic command for symbolic variables.
symsum(x(k),k,0,9) -> sum(x)
  • in matlab, don't exist the zero index, the first index is one.
  • you had miss one parenthesis some where.
  • the argument y, only have 2 elements.
y(3) -> y(1)
  • i think that you're confusing matlab script with another symbolic language like mathematica, cause you don't need symbolic toolbox.
function F = myobjfun(x,y)
n = numel(x);
i = 1;
F = y(1).*x(i).*log(1+x(i))/sum(x) - y(2).*x(i);
for i=2:n,
F = F + y(1).*x(i).*log(1+x(i))/sum(x) - y(2).*x(i);
end
  1 件のコメント
Kane0610
Kane0610 2014 年 5 月 20 日
Thank you. :)

サインインしてコメントする。

その他の回答 (1 件)

shimels gbre ab abebe
shimels gbre ab abebe 2021 年 6 月 20 日
Can any one please help me.How can I debg it...?
Num_of_user=round(1200/t*gaussm(k,t/4,t/2));

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by