How to constuct Taylor expansion of arbitrary function in Matlab?

0

I am reading a book titled "Homotopy Analysis Method in Nonlinear Differential Equation" by Shijun Liao. In chapter 13 Application in Finance: American Put Option, there is appendix about mathematica code of the chapter. However, I do not have Mathematica butMatlab instead and I wish to rewrite the code in Matlab.

Here is the first part of the Mathematica code:

<<Calculus`Pade`;
<<Graphics`Graphics`;

(* Define approx[f] for Taylor expansion of f *)
approx[f_] := Module[{temp},
temp[0] = Series[f, {t, 0, OrderTaylor}]//Normal;
temp[1] = temp[0] /. t^(n_.)*Derivative[j_][DiracDelta][0] -> 0;
temp[2] = temp[1] /. t^(n_.)*DiracDelta[0] -> 0;
temp[3] = temp[2] /. DiracDelta[0] -> 0;
temp[4] = temp[3] /. Derivative[j_][DiracDelta][0] -> 0;
temp[5] = N[temp[4],60]//Expand;
If[KeyCutOff == 1, temp[5] = temp[5]//Chop];
temp[5]
];

I know from Wolfram Reference site that Series[f,{x,x0,n}] generates a power series expansion for f about the point x=x0 to order (x-x0)^n. Thus, I need to construct a power series of expansion for f. However, as far as I know, in matlab, we have to define the f first, for example f=cos(x), etc. So, my question is, How to constuct Taylor expansion of arbitrary function in Matlab?

Thanks in advance.

Monica Sendi Afa

Posted 2016-04-13T02:49:15.837

Reputation: 1

Try a matlab support forum, they have scientists and mathematicians. – barlop – 2016-06-19T23:28:49.803

Answers

0

If you want to use math in Matlab as is done in Mathematica, you will need the 'Symbolic Math Toolbox'.

With that toolbox, it is straightforward using the build-in tailor function

See the page about this function for syntax examples

Lucademicus

Posted 2016-04-13T02:49:15.837

Reputation: 103

Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change. – DavidPostill – 2016-09-16T21:28:35.503