Taylor Series expansion error
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Walter Roberson
le 29 Sep 2018
You accidentally invoked MATLAB's taylor() function instead of your Taylor() function.
0 commentaires
Voir également
Catégories
En savoir plus sur Numbers and Precision dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!