## 21438 Reputation

15 years, 115 days

## VectorCalculus:-Jacobian and arbitrary n...

@DoingMath2018 If your input procedure doesn't have conditionals and branching (ie. are simple operators that utilize a formula) then handling an arbitrary number of dependent variables and instead using an expression doesn't seem to present great difficulty.

For example (noticing that the dummy variable of integration, r, is correctly skipped and is not one of the independent variables):

 > restart;
 > expr := [x^2-y^2+a*z+Int(cos(q*r*s),r=0..1)];

 > vars := [op(indets(expr,And(name,Non(constant),satisfies(u->depends(expr,u)))))];

 > exprJ := unapply(VectorCalculus:-Jacobian( expr, vars ), vars):
 > evalf(exprJ(0.1,0.2,0.3,0.4,0.5,0.6));

 > # check map(diff~,expr,vars); evalf(eval(%, Equate(vars,[0.1,0.2,0.3,0.4,0.5,0.6])));

 >

Above I have constructed a single Vector-valued procedure rather than a Vector of procedures. I'm not sure which you want.

If you really do prefer to use an input operator rather than an input expression then you could look over my Answer above.

I think it would be easier to learn how to leverage Maple's functionality than it would be to implement your own basic CAS.

It is still unclear to me how you plan to subsequently utilize this Jacobian-thing that you're after. Providing more details of the input example class and also how the result will be subsequently utilized should surely be a core part of the question.

## Student:-Calculus1...

Have a look at the Help pages for the Student:-Calculus1 package.

## operators vs expressions...

@tomleslie The OP made it quite clear in his Question that he wanted to act on operators/procedures rather than expressions. That was the central point of the Question.

Your code deals with function calls which evaluate to expressions prior to Jacobuan being called. So your suggestion is not what was requested.

One could map unapply over an expression-based solution like yours, after the fact, to get a result with operators. But that is a kludge generally weaker than using D (which also has some abilities to deal with conditionals and code branching within the procedure, and that otherwise mostly gets wrecked/ignored by a function call to produce an expression result).

## good idea...

@tomleslie Investigating the older behavior is a good idea. But the following does not agree with one of your examples (even if put in a single execution group).

 > restart;
 > kernelopts(version);

 > with(VectorCalculus):
 > # assume(x, 'real'); # assume(y, 'real');
 > D[1]((x, y) ->x^2-y^2);

 >

## yes, it does...

@Carl Love The example that I showed produces the same results in my Maple 2019.0 as it did in what I posted from Maple 2018.0.

I suspect that you have not noticed the key aspects of my two alternatives. One uses procedure f defined before loading the package, and the other used unapply afterwards. I did not claim that :-D would work on the operator defined literally as you have it, after loading the full VectorCalculus package and placing the assumptions (which is literally similar to what the OP had).

 > restart;
 > kernelopts(version);

 > with(VectorCalculus):
 > assume(x, 'real'); assume(y, 'real');
 > :-D[1]( unapply(x^2-y^2, [x,y]) );

 > :-D[2]( unapply(x^2-y^2, [x,y]) );

 > restart;
 > kernelopts(version);

 > f := (x, y) -> x^2-y^2;

 > with(VectorCalculus):
 > assume(x, 'real'); assume(y, 'real');
 > :-D[1](f);

 > :-D[2](f);

 > :-D[1]( unapply(x^2-y^2, [x,y]) );

 > :-D[2]( unapply(x^2-y^2, [x,y]) );

 >

VCD_M2019.0.mw

Trying to export package "overloads" of kernel builtins is difficult to get exactly right (and not always possible).  If Tom is correct and this is a regression breakage then I do not yet know whether the bug is Library-side or kernel-side.[/edit]

## Groebner...

@Carl Love Yes, simplify with side-relations can just do this:

```restart;

G:=Groebner:-Basis({a+b+c-1,a^2+b^2+c^2-2,a^3+b^3+c^3-3},
plex(c,b,a),characteristic=0,output="basislm"):

lprint(G);
[[6, a^3, 6*a^3-6*a^2-3*a-1], [2, b^2, 2*a^2+2*a*b+2*b^2-2*a-2*b-1],
[1, c, a+b+c-1]]

Groebner:-NormalForm(a^4+b^4+c^4,G,plex(c,b,a),characteristic=0);

25/6```

## was it a challenge problem?...

I suppose that this was originally intended for people to do without Maple, where they would concoct or notice that the target expressions can be obtained by a judicious expansion (with cancellation) of a polynomial of the original three expressions.

Perhaps the OP was shooting for something like this (just a guess as to intent):

 > restart;
 > eqs := [t1 = a+b+c,         t2 = a^2+b^2+c^2,         t3 = a^3+b^3+c^3]:
 > vals := [t1=1,t2=2,t3=3]:
 > R4 := 1/2*(t2-t1^2)^2-1/3*t1^4+4/3*t1*t3;

 > # Notice this subs(eqs, R4); expand(%);

 > expand(eval(R4, eqs)) = eval(R4, vals);

 > R5 := 1/6*(5*(t1^2+t2)*t3+t1^3*(t1^2-5*t2));

 > # Notice this subs(eqs, R5); expand(%);

 > expand(eval(R5, eqs)) = eval(R5, vals);

 >

So, is there some "easier" reformulation of R4 or R5 which might be concocted with more of an "aha!" moment?

## deft...

@Carl Love I wish I'd thought of it earlier.

## bug previously reported...

@Christopher2222 I submitted a bug report related to this a few years ago.

## essentially the same...

@tomleslie Yes, and now you've obtained a method that is essentially the same as what dharr showed earlier (as in the examples,Explore help page).

[I'm not suggesting that you haven't come up with this all by yourself. I think it's the natural way to approach it efficiently. I'm pretty sure I've seen Preben do the same thing. I've long wanted something like DEplot to offer the same flexibility+efficiency.]

## subscript/superscript...

To get the visual effect of subscripted text (but not as output) you might have to toggle into non-executing 2D Math input mode and manually flip off italics from the menubar.

## input...

@Christopher2222 It looks as if his question is about how to enter it as input, while your answer is only about how to produce output.

Moreover he seems to want a subscripted/superscripted bit of "text", which I interpret as meaning something formatted in upright roman font. So mi is not the right typesetting markup for that.

I don't see how your answer relates properly to this question at all.

## examples,Explore...

@dharr Vote up, because this shows dsolve being called only the one time.

The help page referred to is available in the Help system under the topic examples,Explore

 First 77 78 79 80 81 82 83 Last Page 79 of 450
﻿