## 70 Reputation

5 years, 273 days

## Saving Matrix rows (or columns) to a fil...

Maple

Hello,

So my questions is fairly simple but I am not sure if Maple can do this. I want to create a Matrix full of partial derivatives (Jacobian), but computing this Jacobian is maxing out my RAM. So I would like to create each row (or column) of the Jacobian seperately and save each row (or column) in a Matrix that has already been saved to a file. Basically I would like to store values in a file (in a loop) without overwriting the file.

## Problems with command alias and diff...

Maple

Hey all Maple experts, Kris here!

I could really use some help/clarfication on what is going on with alias, diff, and pointers for vectors.

A short description of what I want to do:
I have 4 equations with 4 variables. The first two equations and variables (1 and 2) are called private, and the last two (3 and 4) are called common. I want to establish an implicit dependence of common on private, namely that the private variables 1 and 2 depend on 3 and 4. Then I want to derivate the private equations with respect to the common variables.

Thus, I create pointers that point to the correct private or common equation or variables with the loop.
for i from 1 to 2 do
iP[i]:=i:
iC[i]:=i+2;
od:

So that for example, a set of four equations named "phi" phi[1..4] where phi[iP] is the first private equation, and phi[iC] is the first common equation. Hopefully so far I have been clear. I create an alias, and continue to derivate these equations. However, I notice that Maple does not recognize the functions in the diff command if the "pointer" notation is used. I will paste the entire code for you all to look at and maybe you can see where things get "weird". Namely if I write phi, is not the same as phi[iP], even though iP:=1 (Both are integers).

p.s. I have used implicitdiff. It is way too slow and memory inefficient for many equations (hundreds to thousands). So that is why I am trying to find a work-around.

restart:
Digits:=15:
with(LinearAlgebra):

for i from 1 to 2 do
iP[i]:=i:
iC[i]:=i+2;
od:

alias(seq(x[iP[i]]=x[iP[i]](seq(x[iC[j]],j=1..2)),i=1..2)):
alias(seq(seq(dPdC[i,iC[k]]=diff(x[iP[i]](seq(x[iC[j]],j=1..2)),x[iC[k]]),k=1..2),i=1..2));

# Define all (PRIVATE + COMMON) phi expressions.
# 1 and 2 are the PRIVATE equations.
# 3 and 4 are the COMMON equations.
phix:= x**2+x**2:
phix:= x   +x:
phix:= x   +x+x:
phix:= x   +x+x:

for i from 1 to 2   do
f[i]:=x[iP[i]]-phix[iP[i]]:
od:

f;

x-phix;

print(iP,iC);

print(x[iP]-phix[iP],x[iC]);

TEST1:=diff(x-phix,x);

TEST2:=diff(f,x);

TEST3:=diff(f,x[iC]);

TEST4:=diff(x[iP]-phix[iP],x[iC]);

The result is

-x^2  - x^2  + x
x - x^2  - x^2
1, 3

-x^2 - x^2  + x, x
dPdC[1, 3] - 2 x
-2 x
-2 x
-2 x
Where dPdC includes the implicit derivatives, which is the answer I want, but then I am forced to write by hand what the elements are. If I put the expression in a loop with the pointers, then I get the other "TEST" answers, and as you can see, the implicit dependence from alias has been ignored.

## Multivariable functions f(x1,x2,x3)...

Maple

Hi!

I am trying to convert expressions into functions, but the expressions have many variables x1, x2, x3.....xn.
The reason I am doing this is because I am hoping that differentiating functions in a large jacobian with large multivariable functions will go faster with functions than expressions. If it doesn't go faster then let me know.

What I am trying to do in a simplified code,

xv:=Vector(2,symbol=x):
f:=x+x;
f:=x-x;

f:=unapply(f,[xv,xv]);

Diff(f,x);

f1:=x + x
f2:=x - x
f1:=(x_1, x_2) -> x_1 + x_2
d
------ f
dx

How can I get this to work? And is it worth it? 1 2 3 Page 3 of 3
﻿