You accidentally invoked MATLAB's taylor() function instead of your Taylor() function.
Taylor Series expansion error
2 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196784/image.jpeg)
>> 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).
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!