kfli

75 Reputation

4 Badges

8 years, 262 days

MaplePrimes Activity


These are questions asked by kfli

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.

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[1]] is the first private equation, and phi[iC[1]] 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[1], is not the same as phi[iP[1]], even though iP[1]:=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[1]:= x[3]**2+x[4]**2:
phix[2]:= x[1]   +x[4]:
phix[3]:= x[1]   +x[3]+x[1]:
phix[4]:= x[1]   +x[3]+x[1]:

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


f[1];

x[1]-phix[1];

print(iP[1],iC[1]);

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

TEST1:=diff(x[1]-phix[1],x[3]);

TEST2:=diff(f[1],x[3]);

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

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

The result is 
      
                     -x[3]^2  - x[4]^2  + x[1]
                      x[1] - x[3]^2  - x[4]^2 
                              1, 3
     
                  -x[3]^2 - x[4]^2  + x[1], x[3]
                      dPdC[1, 3] - 2 x[3]
                            -2 x[3]
                            -2 x[3]
                            -2 x[3]
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.
 

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[1]:=x[1]+x[2];
f[2]:=x[1]-x[2];

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

Diff(f[1],x[1]);



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

 

 

How can I get this to work? And is it worth it?

1 2 3 Page 3 of 3