MATLAB Answers

taylor series expansion with initial condition

9 views (last 30 days)
MINATI
MINATI on 4 Jan 2020
Commented: MINATI on 5 Jan 2020
syms x f(x) p
f1=taylor(f(x),x,'order',3)
(D(D(f))(0)=p; D(f)(0)=1; f(0)=0;
%%% I want to put initial conditios (D(D(f))(0)=p; D(f)(0)=1; f(0)=0; in f1 to
find f1=x+p*x^2/2 in symbolic form. Guide me please

  0 Comments

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 5 Jan 2020
Edited: John D'Errico on 5 Jan 2020
Why not try it! ??? Make an effort. For example, this seems the obvious thing to try. So what does this do?
syms x f(x) p
f1=taylor(f(x),x,'order',3)
f1 =
(D(D(f))(0)*x^2)/2 + D(f)(0)*x + f(0)
subs(f1,f(0),0)
ans =
(D(D(f))(0)*x^2)/2 + D(f)(0)*x
Can you finish the next two steps on your own?

  5 Comments

Show 2 older comments
MINATI
MINATI on 5 Jan 2020
Thanks for your effort
Actually I want to generalise my work of three functions (f , g, h) of taylor expansion
of order (3, 3, 2), so I am trying to change the code given below:
If you want to follow:
syms x f(x) p g(x) a q h(x) r f1 g1 h1
TE = taylor([f(x) g(x) h(x)],x,'order',3); %%%TAYLOR EXP
f0=subs(TE,x,0);fp = subs(diff(TE,x),0);,fpp= subs(diff(TE,x,2),0);
IC=[f0 fp fpp]; %%% INITIAL CONDITION
[f(1) g(1) h(1)] =subs(TE,IC,[0,0,1, 1,a,r, p,q,0])%%%%
RESULT should come as [f(1) g(1) h(1)]=[ x+p*x^2/2 a*x+q*x^2/2 1+r*x] ]
John D'Errico
John D'Errico on 5 Jan 2020
Yes, but you cannot do what you want.
syms x f(x) p g(x) a q h(x) r
f1 = taylor([f(x) g(x) h(x)],x,'order',[3 3 2]);
Error using sym/taylor (line 99)
The value of 'Order' is invalid. It must satisfy the function: isPositiveInteger.
The taylor function appears not to be vectorized in the sense that you can expand each term ot the vector of functions to a different order.
So this next is valid:
f1 = taylor([f(x) g(x) h(x)],x,'order',3);
And then you should be able to proceed further.
MINATI
MINATI on 5 Jan 2020
Now everything is OK
but can it be possible to bring
[ f(1) g(1) h(1) ] = [ x+p*x^2/2 a*x+q*x^2/2 1+r*x]
as I have to incorporate this in another code

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!