how do i fix inline function error?

1 view (last 30 days)
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

Accepted Answer

Riccardo Scorretti
Riccardo Scorretti on 1 Apr 2022
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.

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!