Taylor Series expansion error

조회 수: 6 (최근 30일)
PJS KUMAR
PJS KUMAR 2018년 9월 29일
답변: Walter Roberson 2018년 9월 29일
I have the following code for taylor series expansion.
function [sol]=Taylor(fn,a,b,y0,h,nd)
syms x y(x);
xd = a:h:b;
yd(1) = y0;
for i = 1:numel(xd)-1
fstart= fn;
fold = fstart;
D(1) = subs(fold,{x,y},{xd(i),yd(i)});
for j=2:nd
fnew = subs(diff(fold,x),diff(y(x),x),fstart);
D(j) = subs(fnew,{x,y},{xd(i),yd(i)});
fold = fnew;
end
yd(i+1) = yd(i)+h*D(1)+h^2/2*D(2)+h^3/6*D(3)+h^4/24*D(4)+h^5/120*D(5);
end
sol=[xd' yd'];
end
It is giving correct output in one system. But giving the following errors in some other systems. Suggest me the solution to get the output.
>> syms x y(x)
>> f=x+y
f(x) =
x + y(x)
>> taylor(f,1,3,0.8,0.5,5)
Error using sym/taylor (line 99)
The value of 'x' is invalid. It must satisfy the function: @(x)isvector(x)&&isAllVars(x).

답변 (1개)

Walter Roberson
Walter Roberson 2018년 9월 29일
You accidentally invoked MATLAB's taylor() function instead of your Taylor() function.

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by