0

Below I have a function for a A Taylor Polynomial calculator in Matlab

function j= taylor(f,a,b,n)
syms p d x;
p=0;
d=f;
for i=[0:n];
    p=p+subs(d,a)*((x-a)^i)/(factorial(i));
    d=diff(d);
end
j=subs(p,b);

When I test it with this: taylor(@(x) exp(x),0,2,5), it returns errors. but it does not return errors when I test it like this taylor(x,exp(x),0,2,5)

How can I fix it so there are no errors when I use a anonymous function in this format: @(x) as input?

user1011332
  • 773
  • 12
  • 27
  • 3
    See this discussion regrading anonymous functions and for loops , http://stackoverflow.com/questions/14739538/using-for-while-loops-in-anonymous-functions-in-matlab – bla Mar 11 '13 at 20:09
  • 1
    Shouldn't you transform your anonymous function to symbolic? See [this question](http://stackoverflow.com/questions/11322295/how-do-i-convert-an-anonymous-function-to-a-symbolic-function-in-matlab) – Dmitry Galchinsky Mar 11 '13 at 23:13

0 Answers0