Help with Not enough input arguments error
Mostrar comentarios más antiguos
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)
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 ;
Categorías
Más información sobre Motor Drives en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!