how do i fix inline function error?
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Riccardo Scorretti
on 1 Apr 2022
Hi,
you can try this:
work5(0.5)
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)
See Also
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!