Making polynomial in matlab causes infinite loop
이전 댓글 표시
I am trying to make a polynomial function for several different coefficients. The problem is, something is wrong with my loop and matlab says
Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
I think the loop might be running infinitely, but I'm not sure how to fix this. I know matlab has a similar example for makeParabola, but I tried out their code and I get the same error.
function p = makePolynomial(a,b,c,d)
p = @polynomial
function y = polynomial(x)
y = a*x.^3 + b*x.^2 + c*x + d;
end
firstp = makePolynomial(0,1,0,0);
secondp = makePolynomial(1,-3,0,1);
thirdp = makePolynomial(0,0,1,-1);
range = [-4,4];
figure;
hold on
fplot(firstp, range);
fplot(secondp, range, 'r:');
fplot(thirdp, range, 'ko');
hold off
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!