how do i fix inline function error?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ann Lee
el 1 de Abr. de 2022
Comentada: Ann Lee
el 1 de Abr. de 2022
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 comentarios
Respuesta aceptada
Riccardo Scorretti
el 1 de Abr. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!