how do i get the derivatives of the functions at "a" with out compromising my (x-a) terms any suggestions?

StackOverflow https://stackoverflow.com/questions/23182650

  •  06-07-2023
  •  | 
  •  

문제

i need the function to output a P nth degree taylor polynomial centered at a here is the code i have , it works almost perfect but im not sure how to get the derivatives of the functions at "a" with out compromising my (x-a) terms... from what i see the diff(f,k) computes the kth derivative of f, but can not plug in the a. looks my code will require another matlab function that will do the plugging any suggestions?

function [P] = mytaylor(f,a,n) 
  f = sym(f);
  syms x;
  terms = 0;
  for k = 0:n
    fk = diff(f,k);
    terms = terms + fk*(x-a)^(k)/factorial(k);   
  end
  P = terms;
end
도움이 되었습니까?

해결책

You need to use the subs function to evaluate your symbolic expression fk at a.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top