Help with Not enough input arguments error
Show older comments
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?
Answers (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 ;
Categories
Find more on Motor Drives 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!