how do i fix inline function error?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Riccardo Scorretti
2022-4-1
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!