HP Forums
Multivariable Taylor series - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Multivariable Taylor series (/thread-12713.html)



Multivariable Taylor series - fakuivan - 03-31-2019 11:01 AM

Is it possible to compute an i-order taylor series for an n-variable function using the built in library? We learned about higher order differentials in calc 2 yesterday, I tried using the ``taylor`` function but the output I got didn't make much sense to me.


RE: Multivariable Taylor series - parisse - 03-31-2019 02:03 PM

Example:
Code:
series(subst(sin(x+y)+cos(y*x),[x,y],h*[x,y]),h=0,6,polynom)(h=1)



RE: Multivariable Taylor series - fakuivan - 03-31-2019 03:44 PM

Thank you very much for that hint, sadly I'm not yet that familiar with the HP CAS as to fully understand what that expression does. Here are some questions:

1. What does ``polynom`` mean in that context? from the documentation I can see the ``series`` function takes only two arguments.
2. Where is the center of the approximation defined? I assumed it's being defined at the origin, like the maclaurin series. If this is true, would there be a way to define the approximation at some arbitrary point?

I tried wrapping the statements in a single function. Would this be a correct way to do it? From limited testing I can say both the function and the expression return the same expressions
Code:

maclaurin_ord(expr_rep,vars,order):=(series(expr_rep(vars = (reserved*vars)),reserved = 0,order,polynom))(reserved = 1)

Also if it's not too much to ask I'd love if you could explain the meaning behind the substitution ``x=h*x`` and ``y=h*y``.


RE: Multivariable Taylor series - parisse - 03-31-2019 06:47 PM

series does univariate series expansion. subst does a change of scale on x and y in order to have a univariate series expansion at x=y=0 (h=0). If you want a series expansion in (u,v) at (x0,y0) you will do subst(...,[x,y],[x0+h*u,y0+h*v]).
polynom is an optional arg to series to remove the remainder term.


RE: Multivariable Taylor series - fakuivan - 03-31-2019 11:46 PM

So these are the functions I was able to come up with:

Code:
maclaurin_mv(expr_rep,vars,order):=(series(expr_rep(vars = (reserved*vars)),reserved = 0,order,polynom))(reserved = 1)
taylor_mv(expr_rep,vars,order,center_rep):=(maclaurin_mv(expr_rep(vars = (vars+center_rep)),vars,order)))(vars = (vars-center_rep))

The taylor version simply moves the origin of the function to ``center_rep``, expands the maclaurin series and then offsets the function back to its origin.

If you have any comments on my solution, like how I could improve it, please do post them. I'm open to criticism.


RE: Multivariable Taylor series - fakuivan - 04-02-2019 08:04 PM

I'm getting these "Running non recursive evaluator" warnings whenever I call the ``taylor_mv`` or the ``maclaurin_mv`` functions I posted above. Evaluating the ``series(...)`` expression does not bring up the warning though. This would not happen at the time of making the previous post, I did not alter the functions but for some reason the calculator thinks it's appropriate to warn me about this now, I purged all of the user-defined variables (except for these two function definitions) but the warning persists. The result for these functions is still the same thought, the warnings do not seem to affect the output.

[attachment=7094]
Results in:

[attachment=7093]


RE: Multivariable Taylor series - parisse - 04-03-2019 06:45 AM

Try this CAS program (you can paste it directly on the CAS commandline on the emulator)
Code:
tay(f,v,l,o):=begin
  local k,r;
  purge(r);
  k:=subst(f,v,r*v+l);
  k:=series(k,r=0,o,polynom);
  k:=subst(k,r=1);
  return k;
end:;



RE: Multivariable Taylor series - parisse - 04-04-2019 05:55 PM

Well, I just looked at the source code and found that multivariate series expansion is already implemented :-) For example:
series(sin(x+y),[x,y],[1,2],5)


RE: Multivariable Taylor series - fakuivan - 04-05-2019 11:09 AM

Oh that's great! Thanks for all the help. Also this source code you're talking about. Is it the calculator source code? Is it open source?


RE: Multivariable Taylor series - chromos - 04-05-2019 12:19 PM

I don't know if you're aware of it, but Mr. Bernard Parisse is CAS developer, so he has access to source code for sure. :-)


RE: Multivariable Taylor series - parisse - 04-06-2019 05:24 AM

The source code of the CAS is based on giac, and giac is open source. You can find a tarball on my webpage, or look at Geogebra giac source tree https://dev.geogebra.org/trac/browser/trunk/geogebra/giac/src/giac