Help with Not enough input arguments error

I am trying to use a code that will approximate Sin(x) with its Maclaurin series. This is my code:
function smp = maclaurin_sin(x, n)
smp = 0;
deriv = [0 1 0 -1]';
for i = 0 : n-1
t(i+1, :) = deriv(1) * x.^(i) / factorial(i);
deriv = circshift(deriv, -1);
end
smp = sum(t);
And this is the error: Not enough input arguments.
Error in sine2 (line 4) for i = 0 : n-1
Can anyone please help?

Respuestas (1)

KSSV
KSSV el 10 de Abr. de 2018
Editada: KSSV el 10 de Abr. de 2018
I guess, you are directly running the function without giving any input. Call the function by giving some inputs:
x = pi/4 ;
n = 100 ;
smp = maclaurin_sin(x, n) ;
It gives:
smp = 0.7071 ;

Etiquetas

Preguntada:

el 10 de Abr. de 2018

Editada:

el 10 de Abr. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by