[go: up one dir, main page]

Items tagged with differentiation

Feed App Center

I’m currently working on a Maple project involving the symbolic differentiation of a user-defined potential energy function, which I then use in a system of differential equations. To implement this, I've been using placeholders like 'Un' when taking derivatives to substitute later during numerical calculations.

While this approach using placeholders works, I find it cumbersome and would prefer a more straightforward way to handle this symbolic differentiation without having to rely on intermediate placeholders like 'Un'.

Does anyone know if there is a more elegant way in Maple to achieve this functionality?

Specific Requirements:

  • I want to symbolically differentiate the user-defined function W directly.
  • The goal is to use this derivative in a system of differential equations for numerical solving.

Any suggestions on simplifying this process would be much appreciated!

Thanks in advance.

restart

NULL
W := proc (Un) options operator, arrow; -(1/4)*(b*d-e*q)^2/(b^2*(e+b*Un^2))-(2*b*c*m^2+(1/4)*q^2)*Un^2/b+c*Un^4 end proc

proc (Un) options operator, arrow; -(1/4)*(b*d-e*q)^2/(b^2*(e+b*Un^2))-(2*b*c*m^2+(1/4)*q^2)*Un^2/b+c*Un^4 end proc

(1)

 

 

diff(W(Un), Un)

(1/2)*(b*d-e*q)^2*Un/(b*(Un^2*b+e)^2)-2*(2*b*c*m^2+(1/4)*q^2)*Un/b+4*c*Un^3

(2)

b := -0.3070816340e-3; c := .4461893869; d := 0.1142581922e-1; e := 0.7675000601e-3; q := -0.3704049149e-2; m := 1.423206983; plot(W(Un), Un = -10 .. 10, title = "Graph of Potential W for set 1", color = blue, axes = boxed)

 

with(plots); with(DEtools); delta := .5; b := -0.222159366e-3; c := 1.088046084; d := 0.1308858509e-2; e := 0.394423507e-3; q := -0.64844084e-3; m := 1.518466566; W := proc (Un) options operator, arrow; -(1/4)*(b*d-e*q)^2/(b^2*(e+b*Un^2))-(2*b*c*m^2+(1/4)*q^2)*Un^2/b+c*Un^4 end proc; Un_placeholder := 'Un'; Wprime := diff(W(Un_placeholder), Un_placeholder); sys := {diff(u(t), t) = v(t), diff(v(t), t) = -delta*v(t)+subs(Un_placeholder = u(t), Wprime)}; ics1 := {u(0) = 0.1e-1, v(0) = 0.1e-1}; sol := dsolve(`union`(sys, ics1), numeric, output = listprocedure); xrange := -0.10e-1 .. 0.11e-1; yrange := -0.3e-1 .. 0.3e-1; phase_plot := odeplot(sol, [u(t), v(t)], 0 .. 100, title = "Phase Plot (Velocity vs Displacement)", numpoints = 8000, color = red, labels = ["u(t)", "v(t)"], axes = boxed, labeldirections = [horizontal, vertical]); vectorfield_plot1 := fieldplot([v, -delta*v+subs(Un_placeholder = u, Wprime)], u = xrange, v = yrange, arrows = medium, color = blue, axes = boxed); display([vectorfield_plot1, phase_plot], title = "Combined Phase Plot and Vector Field", labels = ["u(t)", "v(t)"], axes = boxed)

 

NULL

Download proteins.mw

i have solution of ODE but again i want take derivative from solution function F then i want take reciprocal of derivative
if F'=G then i want 1/F'=1/G like that i want all solution by list and if possible don't give the parameter a sequence  it will be better

thanks for any help

K := diff(G(xi), xi $ 2) = -lambda*diff(G(xi), xi) - mu;
                 2                                    
                d                    / d        \     
          K := ----- G(xi) = -lambda |---- G(xi)| - mu
                   2                 \ dxi      /     
                dxi                                   

V:= [seq](-1..1, 1/2);
                          [    -1     1   ]
                     V := [-1, --, 0, -, 1]
                          [    2      2   ]

interface(rtablesize= nops(V)^3):
DataFrame(
    <seq(seq(<a | b | rhs(dsolve(eval(K, [lambda,mu]=~ [a,b])))>, a= V), b= V)>,
    columns= [lambda, mu, F]
);

loading

Error occurred during PDF generation. Please refresh the page and try again

Hello

I am struggling to translate an old Maple V3 package to work with the latest version of Maple. Although I have received help from members of this list and managed to resolve some problems on my own, I am at a loss as to how to fix the following Maple code. 

# differentiation
ddf := proc(f)
    local j;
    print(f):
    sum('expand(eval(subs(diff = 0,diff(f,indets(f)[j])))*(indets(f)[j]))','j' = 1 .. nops(indets(f)))
end proc:

Suppose that 

f:=x;

ddf(f);
                               x

Error, (in SumTools:-DefiniteSum:-ClosedForm) summand is singular in the interval of summation

Any help in figuring out what the author was going for would be really appreciated.

Obs.: An example taken from the old Maple v3 help file.  If f:=z^2+y, the output is 2*z*z'+y'.

restart

``

B := (sum(a__n*exp(n*x), n = -c .. p))/(sum(b__m*exp(m*x), m = -d .. q))

(exp((p+1)*x)/(exp(x)-1)-exp(-c*x)/(exp(x)-1))*a__n/((exp((q+1)*x)/(exp(x)-1)-exp(-d*x)/(exp(x)-1))*b__m)

(1)

 

NULL

Download open_series_and_take_derivative.mw

i am writing code for an iterative process at the end i want to evaluate the summation expression with two loops but it is not evaluating kindly help me out here automatic_differentiation.mw
 

restart

v := 1; a := 2; t := 0.1e-2; dt := 0.1e-3; N := 40; h := 1/40; K := 4

NULL

NULL

for i from 0 to N do x[i] := i*h end do

x[5]

1/8

(1)

initial_condition := []; for i to N do initial_condition := [op(initial_condition), evalf(2*v*Pi*sin(Pi*x[i])/(a+cos(Pi*x[i])))] end do

u := proc (i) local u_x, u_xx, expr, j; u_x := (1/2)*(u[i+1]-u[i-1])/h; u_xx := (u[i-1]-2*u[i]+u[i+1])/h^2; expr := -alpha*u[i]*u_x+v*u_xx; expr end proc
NULL

NULL

odes := [seq(u(i, [seq(u[j], j = 1 .. N-1)]), i = 1 .. N-1)]

for i to N-1 do assign(o[i] = odes[i]) end do

for i to N-1 do printf("u_%d = %s\n", i, convert(u(i), string)) end do

u_1 = -alpha*u[1]*(20*u[2]-20*u[0])+1600*u[0]-3200*u[1]+1600*u[2]
u_2 = -alpha*u[2]*(20*u[3]-20*u[1])+1600*u[1]-3200*u[2]+1600*u[3]
u_3 = -alpha*u[3]*(20*u[4]-20*u[2])+1600*u[2]-3200*u[3]+1600*u[4]
u_4 = -alpha*u[4]*(20*u[5]-20*u[3])+1600*u[3]-3200*u[4]+1600*u[5]
u_5 = -alpha*u[5]*(20*u[6]-20*u[4])+1600*u[4]-3200*u[5]+1600*u[6]
u_6 = -alpha*u[6]*(20*u[7]-20*u[5])+1600*u[5]-3200*u[6]+1600*u[7]
u_7 = -alpha*u[7]*(20*u[8]-20*u[6])+1600*u[6]-3200*u[7]+1600*u[8]
u_8 = -alpha*u[8]*(20*u[9]-20*u[7])+1600*u[7]-3200*u[8]+1600*u[9]
u_9 = -alpha*u[9]*(20*u[10]-20*u[8])+1600*u[8]-3200*u[9]+1600*u[10]
u_10 = -alpha*u[10]*(20*u[11]-20*u[9])+1600*u[9]-3200*u[10]+1600*u[11]
u_11 = -alpha*u[11]*(20*u[12]-20*u[10])+1600*u[10]-3200*u[11]+1600*u[12]
u_12 = -alpha*u[12]*(20*u[13]-20*u[11])+1600*u[11]-3200*u[12]+1600*u[13]
u_13 = -alpha*u[13]*(20*u[14]-20*u[12])+1600*u[12]-3200*u[13]+1600*u[14]
u_14 = -alpha*u[14]*(20*u[15]-20*u[13])+1600*u[13]-3200*u[14]+1600*u[15]
u_15 = -alpha*u[15]*(20*u[16]-20*u[14])+1600*u[14]-3200*u[15]+1600*u[16]
u_16 = -alpha*u[16]*(20*u[17]-20*u[15])+1600*u[15]-3200*u[16]+1600*u[17]
u_17 = -alpha*u[17]*(20*u[18]-20*u[16])+1600*u[16]-3200*u[17]+1600*u[18]
u_18 = -alpha*u[18]*(20*u[19]-20*u[17])+1600*u[17]-3200*u[18]+1600*u[19]
u_19 = -alpha*u[19]*(20*u[20]-20*u[18])+1600*u[18]-3200*u[19]+1600*u[20]
u_20 = -alpha*u[20]*(20*u[21]-20*u[19])+1600*u[19]-3200*u[20]+1600*u[21]
u_21 = -alpha*u[21]*(20*u[22]-20*u[20])+1600*u[20]-3200*u[21]+1600*u[22]
u_22 = -alpha*u[22]*(20*u[23]-20*u[21])+1600*u[21]-3200*u[22]+1600*u[23]
u_23 = -alpha*u[23]*(20*u[24]-20*u[22])+1600*u[22]-3200*u[23]+1600*u[24]
u_24 = -alpha*u[24]*(20*u[25]-20*u[23])+1600*u[23]-3200*u[24]+1600*u[25]
u_25 = -alpha*u[25]*(20*u[26]-20*u[24])+1600*u[24]-3200*u[25]+1600*u[26]
u_26 = -alpha*u[26]*(20*u[27]-20*u[25])+1600*u[25]-3200*u[26]+1600*u[27]
u_27 = -alpha*u[27]*(20*u[28]-20*u[26])+1600*u[26]-3200*u[27]+1600*u[28]
u_28 = -alpha*u[28]*(20*u[29]-20*u[27])+1600*u[27]-3200*u[28]+1600*u[29]
u_29 = -alpha*u[29]*(20*u[30]-20*u[28])+1600*u[28]-3200*u[29]+1600*u[30]
u_30 = -alpha*u[30]*(20*u[31]-20*u[29])+1600*u[29]-3200*u[30]+1600*u[31]
u_31 = -alpha*u[31]*(20*u[32]-20*u[30])+1600*u[30]-3200*u[31]+1600*u[32]
u_32 = -alpha*u[32]*(20*u[33]-20*u[31])+1600*u[31]-3200*u[32]+1600*u[33]
u_33 = -alpha*u[33]*(20*u[34]-20*u[32])+1600*u[32]-3200*u[33]+1600*u[34]
u_34 = -alpha*u[34]*(20*u[35]-20*u[33])+1600*u[33]-3200*u[34]+1600*u[35]
u_35 = -alpha*u[35]*(20*u[36]-20*u[34])+1600*u[34]-3200*u[35]+1600*u[36]
u_36 = -alpha*u[36]*(20*u[37]-20*u[35])+1600*u[35]-3200*u[36]+1600*u[37]
u_37 = -alpha*u[37]*(20*u[38]-20*u[36])+1600*u[36]-3200*u[37]+1600*u[38]
u_38 = -alpha*u[38]*(20*u[39]-20*u[37])+1600*u[37]-3200*u[38]+1600*u[39]
u_39 = -alpha*u[39]*(20*u[40]-20*u[38])+1600*u[38]-3200*u[39]+1600*u[40]

 

initial_conditions := [.1644933719, .3289856976, .4934717144, .6579375992, .8223563570, .9866828090, 1.150848028, 1.314753051, 1.478261707, 1.641192349, 1.803308276, 1.964306617, 2.123805434, 2.281328760, 2.436289364, 2.587968970, 2.735495794, 2.877819368, 3.013682762, 3.141592654, 3.259788188, 3.366210070, 3.458472370, 3.533840560, 3.589220824, 3.621167336, 3.625916040, 3.599455182, 3.537643690, 3.436388151, 3.291886154, 3.100937330, 2.861312732, 2.572157998, 2.234388242, 1.851015873, 1.427342882, .9709526944, .4914580366, 0.]; u := table(); for i to N do u[i] := initial_conditions[i] end do

.1644933719

 

.3289856976

 

.4934717144

 

.6579375992

 

.8223563570

 

.9866828090

 

1.150848028

 

1.314753051

 

1.478261707

 

1.641192349

 

1.803308276

 

1.964306617

 

2.123805434

 

2.281328760

 

2.436289364

 

2.587968970

 

2.735495794

 

2.877819368

 

3.013682762

 

3.141592654

 

3.259788188

 

3.366210070

 

3.458472370

 

3.533840560

 

3.589220824

 

3.621167336

 

3.625916040

 

3.599455182

 

3.537643690

 

3.436388151

 

3.291886154

 

3.100937330

 

2.861312732

 

2.572157998

 

2.234388242

 

1.851015873

 

1.427342882

 

.9709526944

 

.4914580366

 

0.

(2)

for i from 2 to N-1 do T1[i] := (u[i+1]-u[i-1])/(2*h); T2[i] := u[i]*T1[i]; T3[i] := (u[i-1]-2*u[i]+u[i+1])/h^2; uN[i][1] := v*T3[i]-T2[i] end do

6.579566850

 

2.164583390

 

-0.100942400e-1

 

-2.174677630

 

6.579038030

 

3.246569176

 

-0.322112000e-1

 

-3.278780376

 

6.577692850

 

4.327711442

 

-0.754025600e-1

 

-4.403114002

 

6.574904195

 

5.406914261

 

-.1476892800

 

-5.554603541

 

6.569833420

 

6.482341694

 

-.257972800

 

-6.740314494

 

6.561404840

 

7.551179821

 

-.416313600

 

-7.967493421

 

6.548273580

 

8.609362668

 

-.634187200

 

-9.243549868

 

6.528785960

 

9.651254278

 

-.924822400

 

-10.57607668

 

6.500931380

 

10.66927884

 

-1.303544000

 

-11.97282284

 

6.462285360

 

11.65349267

 

-1.788137600

 

-13.44163027

 

6.409943160

 

12.59109376

 

-2.399238400

 

-14.99033216

 

6.340442860

 

13.46586700

 

-3.160785600

 

-16.62665260

 

6.249678600

 

14.25757153

 

-4.100355200

 

-18.35792673

 

6.132804200

 

14.94128564

 

-5.249596800

 

-20.19088244

 

5.984128600

 

15.48673913

 

-6.644451200

 

-22.13119033

 

5.797007960

 

15.85769089

 

-8.325200000

 

-24.18289089

 

5.563739360

 

16.01143689

 

-10.33628800

 

-26.34772489

 

5.275465720

 

15.89858010

 

-12.72560320

 

-28.62418330

 

4.922108520

 

15.46325997

 

-15.54297280

 

-31.00623277

 

4.492348320

 

14.64410399

 

-18.83784320

 

-33.48194719

 

3.973683640

 

13.37625388

 

-22.65533120

 

-36.03158508

 

3.352609800

 

11.59490836

 

-27.03057600

 

-38.62548436

 

2.614969080

 

9.240883798

 

-31.98068160

 

-41.22156540

 

1.746535520

 

6.268701658

 

-37.49400320

 

-43.76270486

 

.7339043200

 

2.657590351

 

-43.51649280

 

-46.17408315

 

-.4342430800

 

-1.574528949

 

-49.93529920

 

-48.36077025

 

-1.765447000

 

-6.354647353

 

-56.56101440

 

-50.20636705

 

-3.261340620

 

-11.53746107

 

-63.11047520

 

-51.57301413

 

-4.915150720

 

-16.89036569

 

-69.19433280

 

-52.30396711

 

-6.709016420

 

-22.08531826

 

-74.31492320

 

-52.22960494

 

-8.611468440

 

-26.70362395

 

-77.88123840

 

-51.17761445

 

-10.57558664

 

-30.26006070

 

-79.24821760

 

-48.98815690

 

-12.53848980

 

-32.25097682

 

-77.78403520

 

-45.53305838

 

-14.42284250

 

-32.22622970

 

-72.96418080

 

-40.73795110

 

-16.14090720

 

-29.87707543

 

-64.48099520

 

-34.60391977

 

-17.60126357

 

-25.12303827

 

-52.34751456

 

-27.22447629

 

-18.71769691

 

-18.17399825

 

-36.96715264

 

-18.79315439

 

-19.41905389

 

-9.543650097

 

-19.14140608

 

-9.597755983

(3)

for i from 3 to N do for k to 4 do T1[i][k] := (uN[i+1][k]-uN[i-1][k])/(2*h); T2[i][k] := 0; for j from 0 to k do T2[i][k] := T1[i][k-j]*uN[i][j]+T2[i][k] end do; T3[i][k] := (uN[i-1][k]-2*uN[i][k]+uN[i+1][k])/h^2; uN[i][k+1] := (-T2[i][k]+T3[i][k])/(k+1) end do end do

NULL

NULL

NULL

NULL

NULL

NULL

NULL

"for i from1 to N do          for j  from 1 to 10  do      uNew[i]:=sum(uN[i][k] *( j*dt)^(k), k=0..K);      end do;      end do;"

Error, controlling variable of for loop must be a name or sequence of 2 names

"for i from1 to N do         for j  from 1 to 10  do  uNew[i]:=sum(uN[i][k] * j*dt, k=0..K);      end do;    end do;"

 

NULL

NULL

NULL

NULL

NULL

NULL

NULL


 

Download automatic_differentiation.mw

 

Function X__2(y1,y2) is a function of X__1(y1,y2). How do I express (implicitly) d(X__2)/d(y1) and d(X__2)/d(y2) in terms of d(X__1)/d(y1) and d(X__1)/d(y2) and perhaps of X__1 and X__2 themselves?

I illustrate what I mean with an example for X__1(y1,y2), where d(X__1)/d(y1) and d(X__1)/d(y2) are written in a relatively compact form in terms of X__1 itself:
 

restart;

X1 := RootOf((8*y__1^14 + 32*y__1^12*y__2^2 + 48*y__1^10*y__2^4 + 32*y__1^8*y__2^6 + 8*y__1^6*y__2^8 + 16*y__1^12 + 80*y__1^10*y__2^2 + 160*y__1^8*y__2^4 + 160*y__1^6*y__2^6 + 80*y__1^4*y__2^8 + 16*y__1^2*y__2^10)*_Z^10 + (40*y__1^13*y__2^2 + 120*y__1^11*y__2^4 + 120*y__1^9*y__2^6 + 40*y__1^7*y__2^8 + 16*y__1^13 + 176*y__1^11*y__2^2 + 544*y__1^9*y__2^4 + 736*y__1^7*y__2^6 + 464*y__1^5*y__2^8 + 112*y__1^3*y__2^10)*_Z^9 + (84*y__1^12*y__2^4 + 168*y__1^10*y__2^6 + 84*y__1^8*y__2^8 - 20*y__1^14 + 28*y__1^12*y__2^2 + 552*y__1^10*y__2^4 + 1288*y__1^8*y__2^6 + 1132*y__1^6*y__2^8 + 348*y__1^4*y__2^10 - 48*y__1^12 - 192*y__1^10*y__2^2 - 272*y__1^8*y__2^4 - 128*y__1^6*y__2^6 + 48*y__1^4*y__2^8 + 64*y__1^2*y__2^10 + 16*y__2^12)*_Z^8 + (88*y__1^11*y__2^6 + 88*y__1^9*y__2^8 - 80*y__1^13*y__2^2 + 56*y__1^11*y__2^4 + 960*y__1^9*y__2^6 + 1432*y__1^7*y__2^8 + 608*y__1^5*y__2^10 - 48*y__1^13 - 416*y__1^11*y__2^2 - 944*y__1^9*y__2^4 - 736*y__1^7*y__2^6 + 16*y__1^5*y__2^8 + 256*y__1^3*y__2^10 + 80*y__1*y__2^12)*_Z^7 + (40*y__1^10*y__2^8 - 128*y__1^12*y__2^4 + 168*y__1^10*y__2^6 + 928*y__1^8*y__2^8 + 632*y__1^6*y__2^10 + 12*y__1^14 - 192*y__1^12*y__2^2 - 1084*y__1^10*y__2^4 - 1472*y__1^8*y__2^6 - 340*y__1^6*y__2^8 + 432*y__1^4*y__2^10 + 180*y__1^2*y__2^12 + 48*y__1^12 + 144*y__1^10*y__2^2 + 112*y__1^8*y__2^4 - 48*y__1^6*y__2^6 - 96*y__1^4*y__2^8 - 32*y__1^2*y__2^10)*_Z^6 + (-92*y__1^11*y__2^6 + 228*y__1^9*y__2^8 + 368*y__1^7*y__2^10 + 32*y__1^13*y__2^2 - 384*y__1^11*y__2^4 - 1272*y__1^9*y__2^6 - 704*y__1^7*y__2^8 + 376*y__1^5*y__2^10 + 224*y__1^3*y__2^12 + 48*y__1^13 + 304*y__1^11*y__2^2 + 432*y__1^9*y__2^4 + 16*y__1^7*y__2^6 - 288*y__1^5*y__2^8 - 128*y__1^3*y__2^10)*_Z^5 + (-24*y__1^10*y__2^8 + 96*y__1^8*y__2^10 + 24*y__1^12*y__2^4 - 412*y__1^10*y__2^6 - 576*y__1^8*y__2^8 + 164*y__1^6*y__2^10 + 160*y__1^4*y__2^12 + 4*y__1^14 + 172*y__1^12*y__2^2 + 532*y__1^10*y__2^4 + 252*y__1^8*y__2^6 - 328*y__1^6*y__2^8 - 216*y__1^4*y__2^10 - 16*y__1^12 - 32*y__1^10*y__2^2 + 32*y__1^6*y__2^6 + 16*y__1^4*y__2^8)*_Z^4 + (-8*y__1^11*y__2^6 - 192*y__1^9*y__2^8 + 28*y__1^7*y__2^10 + 60*y__1^5*y__2^12 + 16*y__1^13*y__2^2 + 232*y__1^11*y__2^4 + 296*y__1^9*y__2^6 - 168*y__1^7*y__2^8 - 184*y__1^5*y__2^10 - 16*y__1^13 - 64*y__1^11*y__2^2 - 32*y__1^9*y__2^4 + 64*y__1^7*y__2^6 + 48*y__1^5*y__2^8)*_Z^3 + (-15*y__1^10*y__2^8 + 9*y__1^6*y__2^12 + 24*y__1^12*y__2^4 + 116*y__1^10*y__2^6 - 36*y__1^8*y__2^8 - 80*y__1^6*y__2^10 - 4*y__1^14 - 40*y__1^12*y__2^2 - 48*y__1^10*y__2^4 + 40*y__1^8*y__2^6 + 52*y__1^6*y__2^8)*_Z^2 + (12*y__1^11*y__2^6 - 4*y__1^9*y__2^8 - 16*y__1^7*y__2^10 - 8*y__1^13*y__2^2 - 24*y__1^11*y__2^4 + 8*y__1^9*y__2^6 + 24*y__1^7*y__2^8)*_Z - y__1^10*y__2^8 - y__1^8*y__2^10 - 4*y__1^12*y__2^4 + 4*y__1^8*y__2^8):

alias(X__1=X1);

X__2 := -y__1*y__2^2*X__1*(8*X__1^7*y__1^10 + 24*X__1^7*y__1^8*y__2^2 + 24*X__1^7*y__1^6*y__2^4 + 8*X__1^7*y__1^4*y__2^6 + 24*X__1^6*y__1^9*y__2^2 + 48*X__1^6*y__1^7*y__2^4 + 24*X__1^6*y__1^5*y__2^6 + 26*X__1^5*y__1^8*y__2^4 + 26*X__1^5*y__1^6*y__2^6 + 8*X__1^4*y__1^7*y__2^6 + 32*X__1^7*y__1^8 + 128*X__1^7*y__1^6*y__2^2 + 192*X__1^7*y__1^4*y__2^4 + 128*X__1^7*y__1^2*y__2^6 + 32*X__1^7*y__2^8 + 16*X__1^6*y__1^9 + 192*X__1^6*y__1^7*y__2^2 + 480*X__1^6*y__1^5*y__2^4 + 448*X__1^6*y__1^3*y__2^6 + 144*X__1^6*y__1*y__2^8 - 16*X__1^5*y__1^10 + 32*X__1^5*y__1^8*y__2^2 + 392*X__1^5*y__1^6*y__2^4 + 624*X__1^5*y__1^4*y__2^6 + 280*X__1^5*y__1^2*y__2^8 - 36*X__1^4*y__1^9*y__2^2 + 72*X__1^4*y__1^7*y__2^4 + 396*X__1^4*y__1^5*y__2^6 + 288*X__1^4*y__1^3*y__2^8 - 28*X__1^3*y__1^8*y__2^4 + 84*X__1^3*y__1^6*y__2^6 + 156*X__1^3*y__1^4*y__2^8 - 7*X__1^2*y__1^7*y__2^6 + 33*X__1^2*y__1^5*y__2^8 - 64*X__1^5*y__1^8 - 192*X__1^5*y__1^6*y__2^2 - 192*X__1^5*y__1^4*y__2^4 - 64*X__1^5*y__1^2*y__2^6 - 32*X__1^4*y__1^9 - 288*X__1^4*y__1^7*y__2^2 - 480*X__1^4*y__1^5*y__2^4 - 224*X__1^4*y__1^3*y__2^6 + 8*X__1^3*y__1^10 - 88*X__1^3*y__1^8*y__2^2 - 408*X__1^3*y__1^6*y__2^4 - 312*X__1^3*y__1^4*y__2^6 + 12*X__1^2*y__1^9*y__2^2 - 108*X__1^2*y__1^7*y__2^4 - 196*X__1^2*y__1^5*y__2^6 + 4*X__1^2*y__1^3*y__2^8 + 2*X__1*y__1^8*y__2^4 - 46*X__1*y__1^6*y__2^6 + 4*X__1*y__1^4*y__2^8 - y__1^7*y__2^6 + y__1^5*y__2^8 + 32*X__1^3*y__1^8 + 64*X__1^3*y__1^6*y__2^2 + 32*X__1^3*y__1^4*y__2^4 + 16*X__1^2*y__1^9 + 96*X__1^2*y__1^7*y__2^2 + 80*X__1^2*y__1^5*y__2^4 + 32*X__1*y__1^8*y__2^2 + 64*X__1*y__1^6*y__2^4 + 16*y__1^7*y__2^4)/(-8*X__1^7*y__1^11*y__2^2 - 24*X__1^7*y__1^9*y__2^4 - 24*X__1^7*y__1^7*y__2^6 - 8*X__1^7*y__1^5*y__2^8 - 32*X__1^6*y__1^10*y__2^4 - 64*X__1^6*y__1^8*y__2^6 - 32*X__1^6*y__1^6*y__2^8 - 50*X__1^5*y__1^9*y__2^6 - 50*X__1^5*y__1^7*y__2^8 - 28*X__1^4*y__1^8*y__2^8 + 32*X__1^8*y__1^10 + 160*X__1^8*y__1^8*y__2^2 + 320*X__1^8*y__1^6*y__2^4 + 320*X__1^8*y__1^4*y__2^6 + 160*X__1^8*y__1^2*y__2^8 + 32*X__1^8*y__2^10 + 160*X__1^7*y__1^9*y__2^2 + 640*X__1^7*y__1^7*y__2^4 + 960*X__1^7*y__1^5*y__2^6 + 640*X__1^7*y__1^3*y__2^8 + 160*X__1^7*y__1*y__2^10 - 8*X__1^6*y__1^12 - 24*X__1^6*y__1^10*y__2^2 + 328*X__1^6*y__1^8*y__2^4 + 1048*X__1^6*y__1^6*y__2^6 + 1056*X__1^6*y__1^4*y__2^8 + 352*X__1^6*y__1^2*y__2^10 - 24*X__1^5*y__1^11*y__2^2 - 48*X__1^5*y__1^9*y__2^4 + 400*X__1^5*y__1^7*y__2^6 + 848*X__1^5*y__1^5*y__2^8 + 424*X__1^5*y__1^3*y__2^10 - 38*X__1^4*y__1^10*y__2^4 - 54*X__1^4*y__1^8*y__2^6 + 274*X__1^4*y__1^6*y__2^8 + 290*X__1^4*y__1^4*y__2^10 - 44*X__1^3*y__1^9*y__2^6 - 32*X__1^3*y__1^7*y__2^8 + 104*X__1^3*y__1^5*y__2^10 - 27*X__1^2*y__1^8*y__2^8 + 15*X__1^2*y__1^6*y__2^10 - 64*X__1^6*y__1^10 - 256*X__1^6*y__1^8*y__2^2 - 384*X__1^6*y__1^6*y__2^4 - 256*X__1^6*y__1^4*y__2^6 - 64*X__1^6*y__1^2*y__2^8 - 256*X__1^5*y__1^9*y__2^2 - 768*X__1^5*y__1^7*y__2^4 - 768*X__1^5*y__1^5*y__2^6 - 256*X__1^5*y__1^3*y__2^8 + 16*X__1^4*y__1^12 + 32*X__1^4*y__1^10*y__2^2 - 408*X__1^4*y__1^8*y__2^4 - 848*X__1^4*y__1^6*y__2^6 - 424*X__1^4*y__1^4*y__2^8 + 48*X__1^3*y__1^11*y__2^2 + 48*X__1^3*y__1^9*y__2^4 - 352*X__1^3*y__1^7*y__2^6 - 352*X__1^3*y__1^5*y__2^8 + 54*X__1^2*y__1^10*y__2^4 - 150*X__1^2*y__1^6*y__2^8 + 22*X__1*y__1^9*y__2^6 - 30*X__1*y__1^7*y__2^8 - 2*y__1^8*y__2^8 + 32*X__1^4*y__1^10 + 96*X__1^4*y__1^8*y__2^2 + 96*X__1^4*y__1^6*y__2^4 + 32*X__1^4*y__1^4*y__2^6 + 96*X__1^3*y__1^9*y__2^2 + 192*X__1^3*y__1^7*y__2^4 + 96*X__1^3*y__1^5*y__2^6 - 8*X__1^2*y__1^12 - 8*X__1^2*y__1^10*y__2^2 + 104*X__1^2*y__1^8*y__2^4 + 104*X__1^2*y__1^6*y__2^6 - 16*X__1*y__1^11*y__2^2 + 48*X__1*y__1^7*y__2^6 - 8*y__1^10*y__2^4 + 8*y__1^8*y__2^6):


Synthetic representation of derivatives


derivatives for X__1 okay: written in terms of y__1, y__2, and X__1 itself.

derX1_y1 := diff(X1, y__1):
derX1_y2 := diff(X1, y__2):

Diff('X__1(y__1,y__2)', y__1) = collect~(normal(eval(derX1_y1, X1 = 'X__1(y__1,y__2)')), 'X__1(y__1,y__2)');
Diff('X__1(y__1,y__2)', y__2) = collect~(normal(eval(derX1_y2, X1 = 'X__1(y__1,y__2)')), 'X__1(y__1,y__2)');


derivatives for X__2 not okay (X__2 is itself a function of X__1): how do I write them in terms of y__1, y__2, X__1 AND the derivatives for X__1 just found? What's the most compact way to express these two derivatives below?

derX2_y1 := diff(X__2, y__1):
derX2_y2 := diff(X__2, y__2):

Diff('X__2(y__1,y__2)', y__1) = collect~(normal(eval(eval(derX2_y1, derX1_y1='Diff('X__1(y__1,y__2)', y__1)'), X__1 = 'X__1(y__1,y__2)')), 'X__1(y__1,y__2)');
Diff('X__2(y__1,y__2)', y__2) = collect~(normal(eval(derX2_y2, X__1 = 'X__1(y__1,y__2)')), 'X__1(y__1,y__2)');

``

 

Download compact_derivatives.mw


Thank you for the help.

i am trying to make code for automatic differentiation method. kindly help me out with that. i have asked chatgpt too. i am going to attach my file alongwith chatgpt code kindly help meautomatic_differentiation.mw
 

restart

v := 1; a := 2; t := 0.1e-2; dt := 0.1e-3; N := 40; h := 1/40; K := 4

NULL

NULL

for i from 0 to N do x[i] := i*h end do

NULL

initial_conditions := []; for i to N do initial_conditions := [op(initial_conditions), 2*v*Pi*sin(Pi*x[i])/(a+cos(Pi*x[i]))] end do

u := proc (i) local u_x, u_xx, expr, j; u_x := (1/2)*(u[i+1]-u[i-1])/h; u_xx := (u[i-1]-2*u[i]+u[i+1])/h^2; expr := -alpha*u[i]*u_x+v*u_xx; expr end proc
NULL

NULL

odes := [seq(u(i, [seq(u[j], j = 1 .. N-1)]), i = 1 .. N-1)]

for i to N-1 do assign(o[i] = odes[i]) end do

for i to N-1 do printf("u_%d = %s\n", i, convert(u(i), string)) end do

u_1 = -alpha*u[1]*(20*u[2]-20*u[0])+1600*u[0]-3200*u[1]+1600*u[2]
u_2 = -alpha*u[2]*(20*u[3]-20*u[1])+1600*u[1]-3200*u[2]+1600*u[3]
u_3 = -alpha*u[3]*(20*u[4]-20*u[2])+1600*u[2]-3200*u[3]+1600*u[4]
u_4 = -alpha*u[4]*(20*u[5]-20*u[3])+1600*u[3]-3200*u[4]+1600*u[5]
u_5 = -alpha*u[5]*(20*u[6]-20*u[4])+1600*u[4]-3200*u[5]+1600*u[6]
u_6 = -alpha*u[6]*(20*u[7]-20*u[5])+1600*u[5]-3200*u[6]+1600*u[7]
u_7 = -alpha*u[7]*(20*u[8]-20*u[6])+1600*u[6]-3200*u[7]+1600*u[8]
u_8 = -alpha*u[8]*(20*u[9]-20*u[7])+1600*u[7]-3200*u[8]+1600*u[9]
u_9 = -alpha*u[9]*(20*u[10]-20*u[8])+1600*u[8]-3200*u[9]+1600*u[10]
u_10 = -alpha*u[10]*(20*u[11]-20*u[9])+1600*u[9]-3200*u[10]+1600*u[11]
u_11 = -alpha*u[11]*(20*u[12]-20*u[10])+1600*u[10]-3200*u[11]+1600*u[12]
u_12 = -alpha*u[12]*(20*u[13]-20*u[11])+1600*u[11]-3200*u[12]+1600*u[13]
u_13 = -alpha*u[13]*(20*u[14]-20*u[12])+1600*u[12]-3200*u[13]+1600*u[14]
u_14 = -alpha*u[14]*(20*u[15]-20*u[13])+1600*u[13]-3200*u[14]+1600*u[15]
u_15 = -alpha*u[15]*(20*u[16]-20*u[14])+1600*u[14]-3200*u[15]+1600*u[16]
u_16 = -alpha*u[16]*(20*u[17]-20*u[15])+1600*u[15]-3200*u[16]+1600*u[17]
u_17 = -alpha*u[17]*(20*u[18]-20*u[16])+1600*u[16]-3200*u[17]+1600*u[18]
u_18 = -alpha*u[18]*(20*u[19]-20*u[17])+1600*u[17]-3200*u[18]+1600*u[19]
u_19 = -alpha*u[19]*(20*u[20]-20*u[18])+1600*u[18]-3200*u[19]+1600*u[20]
u_20 = -alpha*u[20]*(20*u[21]-20*u[19])+1600*u[19]-3200*u[20]+1600*u[21]
u_21 = -alpha*u[21]*(20*u[22]-20*u[20])+1600*u[20]-3200*u[21]+1600*u[22]
u_22 = -alpha*u[22]*(20*u[23]-20*u[21])+1600*u[21]-3200*u[22]+1600*u[23]
u_23 = -alpha*u[23]*(20*u[24]-20*u[22])+1600*u[22]-3200*u[23]+1600*u[24]
u_24 = -alpha*u[24]*(20*u[25]-20*u[23])+1600*u[23]-3200*u[24]+1600*u[25]
u_25 = -alpha*u[25]*(20*u[26]-20*u[24])+1600*u[24]-3200*u[25]+1600*u[26]
u_26 = -alpha*u[26]*(20*u[27]-20*u[25])+1600*u[25]-3200*u[26]+1600*u[27]
u_27 = -alpha*u[27]*(20*u[28]-20*u[26])+1600*u[26]-3200*u[27]+1600*u[28]
u_28 = -alpha*u[28]*(20*u[29]-20*u[27])+1600*u[27]-3200*u[28]+1600*u[29]
u_29 = -alpha*u[29]*(20*u[30]-20*u[28])+1600*u[28]-3200*u[29]+1600*u[30]
u_30 = -alpha*u[30]*(20*u[31]-20*u[29])+1600*u[29]-3200*u[30]+1600*u[31]
u_31 = -alpha*u[31]*(20*u[32]-20*u[30])+1600*u[30]-3200*u[31]+1600*u[32]
u_32 = -alpha*u[32]*(20*u[33]-20*u[31])+1600*u[31]-3200*u[32]+1600*u[33]
u_33 = -alpha*u[33]*(20*u[34]-20*u[32])+1600*u[32]-3200*u[33]+1600*u[34]
u_34 = -alpha*u[34]*(20*u[35]-20*u[33])+1600*u[33]-3200*u[34]+1600*u[35]
u_35 = -alpha*u[35]*(20*u[36]-20*u[34])+1600*u[34]-3200*u[35]+1600*u[36]
u_36 = -alpha*u[36]*(20*u[37]-20*u[35])+1600*u[35]-3200*u[36]+1600*u[37]
u_37 = -alpha*u[37]*(20*u[38]-20*u[36])+1600*u[36]-3200*u[37]+1600*u[38]
u_38 = -alpha*u[38]*(20*u[39]-20*u[37])+1600*u[37]-3200*u[38]+1600*u[39]
u_39 = -alpha*u[39]*(20*u[40]-20*u[38])+1600*u[38]-3200*u[39]+1600*u[40]

 

eval_derivatives := proc (k, u) local T1i, T2i, T3i, T1ik, T2ik, T3ik, ui_k, i, j; T1i := Array(0 .. N); T2i := Array(0 .. N); T3i := Array(0 .. N); ui_k := Array(0 .. N); for i to N-1 do T1i[i] := (1/2)*(u[i+1]-u[i-1])/h; T2i[i] := u[i]*T1i[i]; T3i[i] := (u[i-1]-2*u[i]+u[i+1])/h^2; ui_k[i] := v*T3i[i]-T2i[i] end do; T1ik := Array(0 .. N); T2ik := Array(0 .. N); T3ik := Array(0 .. N); for i to N-1 do T1ik[i] := (1/2)*(u[i+1, k]-u[i-1, k])/h; T2ik[i] := add(u[i, j]*T1i[i, k-j], j = 0 .. k); T3ik[i] := (u[i-1, k]-2*u[i, k]+u[i+1, k])/h^2; ui_k[i] := (v*T3ik[i]-T2ik[i])/(k+1) end do; return ui_k end proc
``

proc (k, u) local T1i, T2i, T3i, T1ik, T2ik, T3ik, ui_k, i, j; T1i := Array(0 .. N); T2i := Array(0 .. N); T3i := Array(0 .. N); ui_k := Array(0 .. N); for i to N-1 do T1i[i] := (1/2)*(u[i+1]-u[i-1])/h; T2i[i] := u[i]*T1i[i]; T3i[i] := (u[i-1]-2*u[i]+u[i+1])/h^2; ui_k[i] := v*T3i[i]-T2i[i] end do; T1ik := Array(0 .. N); T2ik := Array(0 .. N); T3ik := Array(0 .. N); for i to N-1 do T1ik[i] := (1/2)*(u[i+1, k]-u[i-1, k])/h; T2ik[i] := add(u[i, j]*T1i[i, k-j], j = 0 .. k); T3ik[i] := (u[i-1, k]-2*u[i, k]+u[i+1, k])/h^2; ui_k[i] := (v*T3ik[i]-T2ik[i])/(k+1) end do; return ui_k end proc

(1)

u := Array(1 .. N, 0 .. K); for i to N do u[i, 0] := evalf(initial_conditions[i]) end do

Array(%id = 36893489585014251020)

 

.1644933719

 

.3289856976

 

.4934717144

 

.6579375992

 

.8223563570

 

.9866828090

 

1.150848028

 

1.314753051

 

1.478261707

 

1.641192349

 

1.803308276

 

1.964306617

 

2.123805434

 

2.281328760

 

2.436289364

 

2.587968970

 

2.735495794

 

2.877819368

 

3.013682762

 

3.141592654

 

3.259788188

 

3.366210070

 

3.458472370

 

3.533840560

 

3.589220824

 

3.621167336

 

3.625916040

 

3.599455182

 

3.537643690

 

3.436388151

 

3.291886154

 

3.100937330

 

2.861312732

 

2.572157998

 

2.234388242

 

1.851015873

 

1.427342882

 

.9709526944

 

.4914580366

 

0.

(2)

for k to K do ui_k := eval_derivatives(k, u); for i to N-1 do u[i, k] := ui_k[i] end do end do

Error, (in eval_derivatives) Array index out of range

 

NULL

"     local u_new, i, k;      u_new := Array(1..N);      for i from 1 to N do          u_new[i] := evalf(add(u[i, k] * dt^k / factorial(k), k = 0 .. K));      end do;      return u_new;  end proc;"

Error, unable to parse

"     local u_new, i, k;   u_new := Array(1..N);      for i from 1 to N do   u_new[i] := evalf(add(u[i, k] * dt^k / factorial(k), k = 0 .. K));      end do;   return u_new;  end proc;"

 

num_steps := round(0.1e-2/dt); for step to num_steps do u_new := advance_solution(t, dt, K, u); for i to N do u[i, 0] := u_new[i] end do; for k to K do ui_k := eval_derivatives(k, u); for i to N do u[i, k] := ui_k[i] end do end do; t := t+dt end do; print(u_new)

num_steps := 10

 

advance_solution(0.1e-2, 0.1e-3, 4, Array(%id = 36893489585014251020))

(3)

NULL


 

Download automatic_differentiation.mw

resolve the issue

What exactly is the difference between the differential operator d_[] from the physics package and diff() ? Why is it not possible for me to differentiate a scalar function g or a coordinate r with the help of the operator? d_[1] should correspond to d/dx (X = (x, y, z, t)) or not? 

restart

with(Physics)

with(Vectors)NULL

Setup(coordinates = cartesian)

[coordinatesystems = {X}]

(1)

r = sqrt(x^2+y^2+z^2)

r = (x^2+y^2+z^2)^(1/2)

(2)

d_[1](g(r))

0

(3)

diff(g(r), x)

(D(g))((x^2+y^2+z^2)^(1/2))*x/(x^2+y^2+z^2)^(1/2)

(4)

d_[1](r)

0

(5)

diff(r, x)

x/(x^2+y^2+z^2)^(1/2)

(6)

d_[1](x)

1

(7)

diff(x, x)

1

(8)

NULL

Download example_d_[].mw

I want to obtain the partial derivative of a piecewise function. How it is possible to calculate  the derivative in (0,0) with diff?

I should get, as answer,  a new piecewise function

with(student);
f := (x, y) -> piecewise((x, y) = (0, 0), 0, (x^3*y - x*y^3)/(y^2 + x^2));
 f := proc (x, y) options operator, arrow; piecewise((x, y) = 

    (0, 0), 0, (x^3*y-x*y^3)/(y^2+x^2)) end proc

fx := (x, y) -> diff(f(x, y), x);
fx := proc (x, y) options operator, arrow; diff(f(x, y), x) end 

   proc

fx(0, 0);
Error, (in fx) invalid input: diff received 0, which is not valid for its 2nd argument

but i obtain an error

anna rita

Hi everyone...
if f(x,y)=x+y
How can I calculate the following expressions for derivative of y(i) where i=1...n?

using diff command to find  partial dervative of function g give zero in maple...it shouldn't be zero...how to fix itpartial_dervative.mw

restart:

 

sigma_t:= map(epsilon-> E_0[90]*epsilon_dot*((epsilon/epsilon_dot)-(sum(p[i], i = 1 .. 3)*(epsilon/epsilon_dot))+(sum(p[i]*tau[i],i=1..3))-(sum(p[i]*tau[i]*exp(-(epsilon/(epsilon_dot*tau[i]))),i=1..3))),true_strain):

 g:= sum(( sigma[j]-sigma_t[j])^2,j=1..10):

diff(g,p[1]);

0

(1)
 

 

Download partial_dervative.mw

I have a complicated bivariate function f(Gamma,rho) that is a RootOf of a quartic. I know that it is strictly positive (one of the four roots at least) for Gamma=0..10 and rho in (-1,+1), with bounds excluded.

I need to find the signs of its first and second derivatives (wrt to Gamma and wrt to rho: 4 derivatives in total).

I encounter numerical issues when I plot3d the derivatives using D[]() vs. fdiff() (numerical function evaluations of the RootOf). I was hoping for the two commands to produce the same output, but they don't it seems. What's going on?

Script:

restart;
_quartic := RootOf(-8*(rho + 1)^4*_Z^4 + 12*(rho + 1)^3*Gamma*(rho - 1)*_Z^3 - 5*(rho + 1)^2*(-4/5 + Gamma^2*rho^2 + 2*(-2/5 - Gamma^2)*rho + Gamma^2)*_Z^2 - 4*(rho + 1)*Gamma*(rho^2 - 1)*_Z + Gamma^2*(rho + 1)*(rho - 1)^2);
convert(_quartic,radical):
f(Gamma,rho) := simplify(%):

RootOf((8*rho^3+24*rho^2+24*rho+8)*_Z^4+(-12*Gamma*rho^3-12*Gamma*rho^2+12*Gamma*rho+12*Gamma)*_Z^3+(5*Gamma^2*rho^3-5*Gamma^2*rho^2-5*Gamma^2*rho+5*Gamma^2-4*rho^2-8*rho-4)*_Z^2+(4*Gamma*rho^2-4*Gamma)*_Z-Gamma^2*rho^2+2*rho*Gamma^2-Gamma^2)

(1)


Synthetic representation of derivatives

der1_Gamma := diff(_quartic, Gamma):
der1_rho := diff(_quartic, rho):

Diff('f(Gamma,rho)', Gamma) = collect~(normal(eval(der1_Gamma, _quartic = 'f(Gamma,rho)')), 'f(Gamma,rho)');
Diff('f(Gamma,rho)', rho) = collect~(normal(eval(der1_rho, _quartic = 'f(Gamma,rho)')), 'f(Gamma,rho)');

der2_Gamma := diff(der1_Gamma, Gamma):
der2_rho := diff(der1_rho, rho):

Diff('f(Gamma,rho)', Gamma$2) = collect~(normal(eval(der2_Gamma, _quartic = 'f(Gamma,rho)')), 'f(Gamma,rho)');
Diff('f(Gamma,rho)', rho$2) = collect~(normal(eval(der2_rho, _quartic = 'f(Gamma,rho)')), 'f(Gamma,rho)');

Diff(f(Gamma, rho), Gamma) = -((-6*rho^3-6*rho^2+6*rho+6)*f(Gamma, rho)^3+(5*Gamma*rho^3-5*Gamma*rho^2-5*Gamma*rho+5*Gamma)*f(Gamma, rho)^2+(2*rho^2-2)*f(Gamma, rho)-Gamma*rho^2+2*Gamma*rho-Gamma)/((16*rho^3+48*rho^2+48*rho+16)*f(Gamma, rho)^3+(-18*Gamma*rho^3-18*Gamma*rho^2+18*Gamma*rho+18*Gamma)*f(Gamma, rho)^2+(5*Gamma^2*rho^3-5*Gamma^2*rho^2-5*Gamma^2*rho+5*Gamma^2-4*rho^2-8*rho-4)*f(Gamma, rho)+2*Gamma*rho^2-2*Gamma)

 

Diff(f(Gamma, rho), rho) = -(1/2)*((24*rho^2+48*rho+24)*f(Gamma, rho)^4+(-36*Gamma*rho^2-24*Gamma*rho+12*Gamma)*f(Gamma, rho)^3+(15*Gamma^2*rho^2-10*Gamma^2*rho-5*Gamma^2-8*rho-8)*f(Gamma, rho)^2+8*Gamma*rho*f(Gamma, rho)-2*rho*Gamma^2+2*Gamma^2)/((16*rho^3+48*rho^2+48*rho+16)*f(Gamma, rho)^3+(-18*Gamma*rho^3-18*Gamma*rho^2+18*Gamma*rho+18*Gamma)*f(Gamma, rho)^2+(5*Gamma^2*rho^3-5*Gamma^2*rho^2-5*Gamma^2*rho+5*Gamma^2-4*rho^2-8*rho-4)*f(Gamma, rho)+2*Gamma*rho^2-2*Gamma)

 

Diff(f(Gamma, rho), Gamma, Gamma) = ((448*rho^8+1792*rho^7+1792*rho^6-1792*rho^5-4480*rho^4-1792*rho^3+1792*rho^2+1792*rho+448)*f(Gamma, rho)^8+(-1632*Gamma*rho^8-3264*Gamma*rho^7+3264*Gamma*rho^6+9792*Gamma*rho^5-9792*Gamma*rho^3-3264*Gamma*rho^2+3264*Gamma*rho+1632*Gamma)*f(Gamma, rho)^7+(2120*Gamma^2*rho^8-8480*Gamma^2*rho^6-208*rho^7+12720*Gamma^2*rho^4-624*rho^6-208*rho^5-8480*Gamma^2*rho^2+1040*rho^4+1040*rho^3+2120*Gamma^2-208*rho^2-624*rho-208)*f(Gamma, rho)^6+(-1200*Gamma^3*rho^8+2400*Gamma^3*rho^7+2400*Gamma^3*rho^6-7200*Gamma^3*rho^5+640*Gamma*rho^7+640*Gamma*rho^6+7200*Gamma^3*rho^3-1920*Gamma*rho^5-2400*Gamma^3*rho^2-1920*Gamma*rho^4-2400*Gamma^3*rho+1920*Gamma*rho^3+1200*Gamma^3+1920*Gamma*rho^2-640*Gamma*rho-640*Gamma)*f(Gamma, rho)^5+(250*Gamma^4*rho^8-1000*Gamma^4*rho^7+1000*Gamma^4*rho^6+1000*Gamma^4*rho^5-632*Gamma^2*rho^7-2500*Gamma^4*rho^4+632*Gamma^2*rho^6+1000*Gamma^4*rho^3+1896*Gamma^2*rho^5+1000*Gamma^4*rho^2-1896*Gamma^2*rho^4+16*rho^6-1000*Gamma^4*rho-1896*Gamma^2*rho^3+32*rho^5+250*Gamma^4+1896*Gamma^2*rho^2-16*rho^4+632*Gamma^2*rho-64*rho^3-632*Gamma^2-16*rho^2+32*rho+16)*f(Gamma, rho)^4+(240*Gamma^3*rho^7-720*Gamma^3*rho^6+240*Gamma^3*rho^5+1200*Gamma^3*rho^4-32*Gamma*rho^6-1200*Gamma^3*rho^3-240*Gamma^3*rho^2+96*Gamma*rho^4+720*Gamma^3*rho-240*Gamma^3-96*Gamma*rho^2+32*Gamma)*f(Gamma, rho)^3+(-25*Gamma^4*rho^7+125*Gamma^4*rho^6-225*Gamma^4*rho^5+125*Gamma^4*rho^4+125*Gamma^4*rho^3-225*Gamma^4*rho^2+125*Gamma^4*rho-25*Gamma^4)*f(Gamma, rho)^2+(16*Gamma^3*rho^6-64*Gamma^3*rho^5+80*Gamma^3*rho^4-80*Gamma^3*rho^2+64*Gamma^3*rho-16*Gamma^3)*f(Gamma, rho)-5*Gamma^4*rho^6+30*Gamma^4*rho^5-75*Gamma^4*rho^4+100*Gamma^4*rho^3-75*Gamma^4*rho^2+30*Gamma^4*rho-5*Gamma^4)/(((16*rho^2+32*rho+16)*f(Gamma, rho)^3+(-18*Gamma*rho^2+18*Gamma)*f(Gamma, rho)^2+(5*Gamma^2*rho^2-10*Gamma^2*rho+5*Gamma^2-4*rho-4)*f(Gamma, rho)+2*Gamma*rho-2*Gamma)*((16*rho^3+48*rho^2+48*rho+16)*f(Gamma, rho)^3+(-18*Gamma*rho^3-18*Gamma*rho^2+18*Gamma*rho+18*Gamma)*f(Gamma, rho)^2+(5*Gamma^2*rho^3-5*Gamma^2*rho^2-5*Gamma^2*rho+5*Gamma^2-4*rho^2-8*rho-4)*f(Gamma, rho)+2*Gamma*rho^2-2*Gamma)^2)

 

Diff(f(Gamma, rho), rho, rho) = (1/4)*((21504*rho^6+129024*rho^5+322560*rho^4+430080*rho^3+322560*rho^2+129024*rho+21504)*f(Gamma, rho)^10+(-80640*Gamma*rho^6-347136*Gamma*rho^5-526080*Gamma*rho^4-245760*Gamma*rho^3+157440*Gamma*rho^2+199680*Gamma*rho+56064*Gamma)*f(Gamma, rho)^9+(127680*Gamma^2*rho^6+336512*Gamma^2*rho^5+122944*Gamma^2*rho^4-319744*Gamma^2*rho^3-18176*rho^5-246976*Gamma^2*rho^2-90880*rho^4+40576*Gamma^2*rho-181760*rho^3+53696*Gamma^2-181760*rho^2-90880*rho-18176)*f(Gamma, rho)^8+(-110016*Gamma^3*rho^6-112128*Gamma^3*rho^5+191808*Gamma^3*rho^4+172032*Gamma^3*rho^3+57344*Gamma*rho^5-105792*Gamma^3*rho^2+191488*Gamma*rho^4-59904*Gamma^3*rho+192512*Gamma*rho^3+24000*Gamma^3+2048*Gamma*rho^2-94208*Gamma*rho-37888*Gamma)*f(Gamma, rho)^7+(54960*Gamma^4*rho^6-28480*Gamma^4*rho^5-102480*Gamma^4*rho^4+56960*Gamma^4*rho^3-74176*Gamma^2*rho^5+40080*Gamma^4*rho^2-126144*Gamma^2*rho^4-28480*Gamma^4*rho+41088*Gamma^2*rho^3+7440*Gamma^4+138368*Gamma^2*rho^2+5120*rho^4+19776*Gamma^2*rho+20480*rho^3-25536*Gamma^2+30720*rho^2+20480*rho+5120)*f(Gamma, rho)^6+(-15300*Gamma^5*rho^6+30000*Gamma^5*rho^5-2100*Gamma^5*rho^4-24000*Gamma^5*rho^3+50048*Gamma^3*rho^5+14100*Gamma^5*rho^2+5632*Gamma^3*rho^4-6000*Gamma^5*rho-89856*Gamma^3*rho^3+3300*Gamma^5-1024*Gamma^3*rho^2-13056*Gamma*rho^4+39808*Gamma^3*rho-31232*Gamma*rho^3-4608*Gamma^3-15360*Gamma*rho^2+10752*Gamma*rho+7936*Gamma)*f(Gamma, rho)^5+(1875*Gamma^6*rho^6-6250*Gamma^6*rho^5+7125*Gamma^6*rho^4-3500*Gamma^6*rho^3-18316*Gamma^4*rho^5+2125*Gamma^6*rho^2+25540*Gamma^4*rho^4-2250*Gamma^6*rho+12072*Gamma^4*rho^3+875*Gamma^6-26520*Gamma^4*rho^2+12992*Gamma^2*rho^4+6244*Gamma^4*rho+10240*Gamma^2*rho^3+980*Gamma^4-15488*Gamma^2*rho^2-9728*Gamma^2*rho-512*rho^3+3008*Gamma^2-1536*rho^2-1536*rho-512)*f(Gamma, rho)^4+(3320*Gamma^5*rho^5-9240*Gamma^5*rho^4+7600*Gamma^5*rho^3-560*Gamma^5*rho^2-6144*Gamma^3*rho^4-1320*Gamma^5*rho+4992*Gamma^3*rho^3+200*Gamma^5+6784*Gamma^3*rho^2-4992*Gamma^3*rho+1024*Gamma*rho^3-640*Gamma^3+1536*Gamma*rho^2-512*Gamma)*f(Gamma, rho)^3+(-200*Gamma^6*rho^5+800*Gamma^6*rho^4-1200*Gamma^6*rho^3+800*Gamma^6*rho^2+1248*Gamma^4*rho^4-200*Gamma^6*rho-3136*Gamma^4*rho^3+1920*Gamma^4*rho^2+576*Gamma^4*rho-768*Gamma^2*rho^3-608*Gamma^4+768*Gamma^2*rho)*f(Gamma, rho)^2+(-16*Gamma^5*rho^4+192*Gamma^5*rho^3-480*Gamma^5*rho^2+448*Gamma^5*rho+256*Gamma^3*rho^3-144*Gamma^5-384*Gamma^3*rho^2+128*Gamma^3)*f(Gamma, rho)-20*Gamma^6*rho^4+80*Gamma^6*rho^3-120*Gamma^6*rho^2+80*Gamma^6*rho-32*Gamma^4*rho^3-20*Gamma^6+96*Gamma^4*rho^2-96*Gamma^4*rho+32*Gamma^4)/(((16*rho^2+32*rho+16)*f(Gamma, rho)^3+(-18*Gamma*rho^2+18*Gamma)*f(Gamma, rho)^2+(5*Gamma^2*rho^2-10*Gamma^2*rho+5*Gamma^2-4*rho-4)*f(Gamma, rho)+2*Gamma*rho-2*Gamma)*((16*rho^3+48*rho^2+48*rho+16)*f(Gamma, rho)^3+(-18*Gamma*rho^3-18*Gamma*rho^2+18*Gamma*rho+18*Gamma)*f(Gamma, rho)^2+(5*Gamma^2*rho^3-5*Gamma^2*rho^2-5*Gamma^2*rho+5*Gamma^2-4*rho^2-8*rho-4)*f(Gamma, rho)+2*Gamma*rho^2-2*Gamma)^2)

(2)


Signs of derivatives: fdiff (numerical function evaluations of the RootOf) vs. D[]()

restart;
with(plots):

_quartic := RootOf(-8*(rho + 1)^4*_Z^4 + 12*(rho + 1)^3*Gamma*(rho - 1)*_Z^3 - 5*(rho + 1)^2*(-4/5 + Gamma^2*rho^2 + 2*(-2/5 - Gamma^2)*rho + Gamma^2)*_Z^2 - 4*(rho + 1)*Gamma*(rho^2 - 1)*_Z + Gamma^2*(rho + 1)*(rho - 1)^2):

plot3d(_quartic, Gamma=0..10, rho=-1..+1, labels=[Gamma,rho,Lambda(Gamma,rho)],axesfont=["helvetica","roman",20],labelfont=["helvetica","roman",30]);
 

 

Define it as a f and test it for Gamma=1 and rho=0.5

f := (Gamma,rho) -> RootOf(-8*(rho + 1)^4*_Z^4 + 12*(rho + 1)^3*Gamma*(rho - 1)*_Z^3 - 5*(rho + 1)^2*(-4/5 + Gamma^2*rho^2 + 2*(-2/5 - Gamma^2)*rho + Gamma^2)*_Z^2 - 4*(rho + 1)*Gamma*(rho^2 - 1)*_Z + Gamma^2*(rho + 1)*(rho - 1)^2):
evalf(f(1.0,0.5));

HFloat(0.5110796212870378)

(3)

Value at zero:

f(0,0):
allvalues(%):
fl := select(is, [allvalues(f(0,0))], positive)[];evalf(%);

(1/2)*2^(1/2)

 

.7071067810

(4)

Value at infinity (commented out because too slow)

#limit(f(x,y), {x = infinity, y = 0}):
#fh := select(is, [allvalues(%)], positive)[];evalf(%);

Derivative at zero:

allvalues([D[1](f)(0,0)]):
Dfl := %[1][];

-1/4

(5)

Derivative at a point, evaluated, vs numerical derivative at a point:

D[1](f)(1,0.5):
evalf(%);
fdiff(f(x,y), x, {x = 1.0, y = 0.5});
fdiff(f, [1], [1.0,0.5]);

D[2](f)(1,0.5):
evalf(%);
fdiff(f(x,y), y, {x = 1.0, y = 0.5});
fdiff(f, [2], [1.0,0.5]);

HFloat(-0.05086932918910799)

 

-0.5086932919e-1

 

-0.5086932919e-1

 

HFloat(-0.05166477232109392)

 

-0.5166477232e-1

 

-0.5166477232e-1

(6)

Can make a function out of fdiff

fDfG := (Gamma,rho) -> fdiff(f, [1], [Gamma,rho]);
fDfr := (Gamma,rho) -> fdiff(f, [2], [Gamma,rho]);

proc (Gamma, rho) options operator, arrow; fdiff(f, [1], [Gamma, rho]) end proc

 

proc (Gamma, rho) options operator, arrow; fdiff(f, [2], [Gamma, rho]) end proc

(7)

Check for numerical values close to thresholds:

Digits := 15:
evalf('D[1]'(f)(0.1e-8,0.5));fdiff(f, [1], [0.1e-8,0.5]);
evalf('D[1]'(f)(0.1e-7,0.5));fdiff(f, [1], [0.1e-7,0.5]);
evalf('D[1]'(f)(0.1e-5,0.5));fdiff(f, [1], [0.1e-5,0.5]);
evalf('D[1]'(f)(0.00001,0.5));fdiff(f, [1], [0.00001,0.5]);
evalf('D[1]'(f)(0.001,0.5));fdiff(f, [1], [0.001,0.5]);


evalf('D[2]'(f)(1,-0.99));fdiff(f, [2], [1,-0.99]);
evalf('D[2]'(f)(1,-0.97));fdiff(f, [2], [1,-0.97]);
evalf('D[2]'(f)(1,-0.1));fdiff(f, [2], [1,-0.1]);
evalf('D[2]'(f)(1,0.98));fdiff(f, [2], [1,0.98]);
evalf('D[2]'(f)(1,-0.99));fdiff(f, [2], [1,-0.99]);

57735026.8022959

 

57735026.8022959

 

-0.833333329724894e-1

 

-0.833333329724894e-1

 

-0.833332972489415e-1

 

-0.833332972489415e-1

 

-0.833329724894151e-1

 

-0.833329724894151e-1

 

-0.832972489466445e-1

 

-0.832972489466445e-1

 

-223.615892086941

 

-223.615892086941

 

-43.0236130145893

 

-43.0236130145893

 

-.212392503268663

 

-.212392503268663

 

-0.127828146340716e-2

 

-0.127828146340716e-2

 

-223.615892086941

 

-223.615892086941

(8)

Compare with D (vertical range here to prevent effect of large values from fdiff near zero):

d1G := plot3d([D[1](f), fDfG], 0..10, -0.95..+0.95, view=-0.3..0, color = [red, blue]);
d1r := plot3d([D[2](f), fDfr], 0..10, -0.95..+0.95, color = [red, blue]);

 

 

 

Second derivatives:

evalf('D[1,1]'(f)(1.0,0.5));
fdiff(f, [1, 1], [1.0,0.5]);

evalf('D[2,2]'(f)(1.0,0.5));
fdiff(f, [2, 2], [1.0,0.5]);

fD2fG := (Gamma,rho) -> fdiff(f, [1, 1], [Gamma]);
fD2fr := (Gamma,rho) -> fdiff(f, [2, 2], [Gamma]);

0.266607527050519e-1

 

0.266607527050519e-1

 

.151600577769391

 

.151600577769391

 

proc (Gamma, rho) options operator, arrow; fdiff(f, [1, 1], [Gamma]) end proc

 

proc (Gamma, rho) options operator, arrow; fdiff(f, [2, 2], [Gamma]) end proc

(9)

d2G:= plot3d([D[1,1](f), fD2fG], 0..10, -0.9..+0.9, color = [red, blue]);
d2r:= plot3d([D[2,2](f), fD2fr], 0..10, -0.9..+0.9, color = [red, blue]);
 

Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct

 

 

Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct

 

 

d1d2G := plot3d([fDfG, fD2fG], 0.1e-6 .. 10, -0.98 .. +0.98, axesfont=["helvetica","roman",20],labelfont=["helvetica","roman",30], size=[1000,1000]);
d1d2r := plot3d([fDfr, fD2fr], 0.1e-6 .. 10, -0.98 .. +0.98, axesfont=["helvetica","roman",20],labelfont=["helvetica","roman",30], size=[1000,1000]);

Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct

 

 

Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct

 

 
 

NULL

Download signs_derivatves_bivariate.mw

I fail to understand from the manual how to do total differentiation.

e.g let's say I have a trivial transform defined as

u=t(x,y)-s(x,y);

then I should get

du=diff(t,x)dx+diff(t,y)dy ...etc

Apparently the operator D_Dx should be able to perform the total derivative, but somehow I cant see this is possible.

What do I miss ?

How do we define a matrix or a vector of the partial differential operator?
 

Could someone help me fix this loop.

It is printing the expressions without evaluating but it is evaluating it before appending it to the list.
I do not want to apriori define the functional dependence i.e. f(t).

lis := [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10];
L := [];
for i in lis do
    print(subs(f = i, 'diff(f, t)'));
    L := [op(L), subs(f = i, 'diff(f, t)')];
end do;
print(L);

1 2 3 4 5 6 7 Last Page 1 of 13