how do i fix inline function error?

19 ビュー (過去 30 日間)
Ann Lee
Ann Lee 2022 年 4 月 1 日
コメント済み: Ann Lee 2022 年 4 月 1 日
i m trying to make matrix (4x16)
in forloop, three modifies of 'a' are series (1 to infinite)
it works untill i added 4th a series (which means inline function. i think this line makes error)
i should add inline function and show series's sum to 160 on 4th row in matrix A
and I got this error
>> work5(0.5)
error: sum: wrong type argument 'class'
function A=work5(x)
m=1;
for k=10:10:160
n=1:k;
a= sum(nthroot(n.^2,5)./((3.^n).*(n+1)));
A(1,m)=a;
a= sum((3*n.^2+n)/(2*n.^4+nthroot(n,2)));
A(2,m)=a;
a= sum((nthroot(37,2)*n.^3)/((2*n.^3)+(3*n.^2)));
A(3,m)=a;
a= sum(inline('log(n)./(n.^2)','n'));
A(4,m)=a;
m=m+1;
end

採用された回答

Riccardo Scorretti
Riccardo Scorretti 2022 年 4 月 1 日
Hi,
you can try this:
work5(0.5)
ans = 4×16
0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.2361 0.0183 0.0047 0.0021 0.0012 0.0008 0.0005 0.0004 0.0003 0.0002 0.0002 0.0002 0.0001 0.0001 0.0001 0.0001 0.0001 2.6037 2.8014 2.8760 2.9152 2.9394 2.9558 2.9677 2.9766 2.9837 2.9893 2.9939 2.9978 3.0011 3.0040 3.0064 3.0086 0.6185 0.7415 0.7927 0.8215 0.8401 0.8532 0.8630 0.8706 0.8767 0.8817 0.8859 0.8895 0.8926 0.8952 0.8976 0.8997
function A=work5(x)
m=1;
fun = @(n) log(n)./(n.^2); % ***
for k=10:10:160
n=1:k;
a= sum(nthroot(n.^2,5)./((3.^n).*(n+1)));
A(1,m)=a;
a= sum((3*n.^2+n)/(2*n.^4+nthroot(n,2)));
A(2,m)=a;
a= sum((nthroot(37,2)*n.^3)/((2*n.^3)+(3*n.^2)));
A(3,m)=a;
% a= sum(inline('log(n)./(n.^2)','n')); % ***
a = sum(fun(n));
A(4,m)=a;
m=m+1;
end
end
The problem seems to be related with the deprecated function inline.
  1 件のコメント
Ann Lee
Ann Lee 2022 年 4 月 1 日
thank you it worked!!! have a nice day!!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by