HP Forums

Full Version: Multivariable Taylor series
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
Example:
Code:
series(subst(sin(x+y)+cos(y*x),[x,y],h*[x,y]),h=0,6,polynom)(h=1)
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``.
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.
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.
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]
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:;
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)
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?
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. :-)
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/tr...c/src/giac
Reference URL's