Making polynomial in matlab causes infinite loop
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Loops and Conditional Statements 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!