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?
답변 (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 ;
카테고리
도움말 센터 및 File Exchange에서 Motor Drives에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!