Sub function not replacing syms variable x with input number
Mostrar comentarios más antiguos
My code isn't finished yet, but this is what I have
function findTaylorSeries = TaylorCos0(valueForX,termNum)
%%formula for taylor series is sum of (n!)^-1* nth derivative of f(x)*(x-a)^2
%%where 'a' represents the center of the taylor series
%%here the taylor series is xNot = 0 = a
n = 0; %%starting at term = 0;
syms x; %%creating a symbolic variable x in order to calculate derivative of function wrt x
findTaylorSeries = 2*cos(4*x);
while n <= termNum
taylor = (factorial(n)^-1)*(diff(findTaylorSeries,n))*x^(n);
%%display(taylor);
n = n+1;
end
subs(taylor,valueForX); %%subs value for x with inputX number
display(taylor);
when I run it using another script m file, I use the inputs TaylorCos0(1,2). It iterates to the second term, which is good. My answer = -16*cos(4*x)*x^2. By using sub, I want to replace all the x values with 1 and evaluate my expression. However, the output I still receive is "-16*cos(4*x)*x^2." The symbolic x variable still remains, and I don't understand why or how to fix it.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Symbolic Variables, Expressions, Functions, and Settings 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!