Maple 18 Questions and Posts

These are Posts and Questions associated with the product, Maple 18

Cannot calculate derivative (gradient) of a procedure returned by dsolve.

Say, I solve the equation:

S1 := dsolve([diff(y(x), x$2)-1.0325*diff(y(x), x)+1.36*y(x)=sin(2*x), y(0)=0, y(1)=1], numeric, y(x), 'output' = listprocedure);

Its solution easily can be retrieved and looks fine:

H:=rhs(S1[2]); 

plot(H(t), t = 0..1, thickness = 4);

3

But when I try to calculate the gradient of H, I receive the error:

H1 := codegen[GRADIENT](H);

Error, (in intrep/statement) unable to translate Array(1..4, {(1) = proc (outpoint) local X, Y, YP, yout, errproc, L, V, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; X := Vector(8, {(1) = .0, (2) = .14817993189456188, (3) = .31785812820433257, (4) = .47163479035679234, (5) = .6130306894371967, (6) = .7460958115245858, (7) = .8741894219027533, (8) = 1.0}, datatype = float[8], order = C_order); Y := Matrix(8, 2, {(1, 1) = .0, (1, 2) = .47692145669848085, (2, 1) = 0.7710429970702501e-1, (2, 2) = .5707930170882397, (3, 1) = .1866916935738028, (3, 2) = .7299040171277492, (4, 1) = .3128649714509215, (4, 2) = .9171936...

Gradient of procedures defined by  ":= proc()" is calculated properly.

files.mw

From art of problem solving ws: "Jamal wants to save 30 files onto disks, each with 1.44 MB space. 3 of the files take up 0.8 MB, 12 of the files take up 0.7 MB, and the rest take up 0.4 MB. It is not possible to split a file onto 2 different disks. What is the smallest number of disks needed to store all 30 files?"

The answer is 13: 3*[0.4,0.8]+6*[0.7,0.7]+4*[0.4,0.4,0.4]

How to accomplish this in maple? my attempt doesnt work, unsurprisingly...


I am trying to do a substitution as shown in the attached document. I know variants of this question have been asked before but dont quiet get what to do. It is problem with algsubs and how it handles denominators I think. Can get substiturion to work for simple fractions but more complicated ones fail. Would appreciate any guidance here.

restart 

``

``

CR := proc (a, b, c, d) options operator, arrow; (a-c)*(b-d)/((a-d)*(b-c)) end proc

proc (a, b, c, d) options operator, arrow; (a-c)*(b-d)/((a-d)*(b-c)) end proc

(1)

eqns := CR(a, b, c, d)

(a-c)*(b-d)/((a-d)*(b-c))

(2)

e1 := CR(b, a, c, d)

(b-c)*(a-d)/((b-d)*(a-c))

(3)

simplify(e1, {(a-c)*(b-d)/((a-d)*(b-c)) = lambda})

(a*b-a*c-b*d+c*d)/(a*b-a*d-b*c+c*d)

(4)

e1

(b-c)*(a-d)/((b-d)*(a-c))

(5)

``

lambda

lambda

(6)

applyrule((a-c)*(b-d)/((a-d)*(b-c)) = lambda, e1)

(b-c)*(a-d)/((b-d)*(a-c))

(7)

alias(lambda = (a-c)*(b-d)/((a-d)*(b-c)))

lambda

(8)

e1

(b-c)*(a-d)/((b-d)*(a-c))

(9)

``

NULL

``

f := a/b

a/b

(10)

``

f := algsubs(a/b = alpha, f)

alpha

(11)

f

alpha

(12)

algsubs((a-c)*(b-d)/((a-d)*(b-c)) = lambda, e1)

Error, (in algsubs) cannot compute degree of pattern in a

 

``

 

Download UHG5_substitution.mw

 

Is there a way with Maple 18 to place a bracket as shown below to contain two DE's? I am not trying to solve them. Only for note-taking purposes. If there is can you please share how to do it?

 

 

DE

Hi 

I'm having a problem with the statements inside a for-loop somehow being read in a different way than outside the loop. 

I've defined some functions earlier, and then I need to perform an integration using these functions, while I change one variable a little for each loop of the for-loop. 

The problem is that IN the for-loop, I get the same value from my integration for all loops. But when I execute the exsact same code OUTSIDE of the loop, I get the correct values, which are changing whenever i change the one variable. 

Here is the loop:

for i from 0 to 42 do

rotorshift := evalf[6](2*((1/180)* *Pi*((1/2)*Ø[gap]))/N[m]-1/2*(tau[p]-tau[s]));

PMmmf_func := x-> proc (x) if type(x-rotorshift, nonnegative) then if type(trunc((x-rotorshift)/tau[p]), odd) = true then -H[c]*l[m] else H[c]*l[m] end if else if type(trunc((x-rotorshift)/tau[p]), odd) = true then H[c]*l[m] else -H[c]*l[m] end if end if end proc

B[g] := proc (x) -> 1000*mu[0]*(PMmmf_func(x)+MMF_func(x))/d[eff, stator](x) end proc;

Flux(i+1) := (int(B[g](x), 0 .. tau[s])+int(B[g](x), 3*tau[s] .. 4*tau[s])+int(B[g](x), 6*tau[s] .. 7*tau[s])+int(B[g](x), 9*tau[s] .. 10*tau[s]))*10^(-3)*L[ro];

end do;

And for all the values in the "Flux" vector, I get the same value. But when I remove the loop, and change the value of manually, I get the correct (changing) values of flux!! 

Any ideas why this may be? This is really dricing me nuts. I've spent the beter part of the day on this, and I just can't seem to find a workaround, much less a reason for this behaviour.

many thanks!

I have generated an 8x8 Jacobian, containing a few variables and several zeros as elements. I would like to translate this to LaTeX code. How can I first simplify what I have, to make it tractable?

Here is the Maple code:

eq_1 := Lambda-mu*S-(beta*(H+C+C1+C2)*S+tau*(T+C)*S)/(S+T+H+C+C1+C2+C1M+C2M);
eq_2 := (-beta*(H+C+C1+C2)*T+tau*(T+C)*S)/(S+T+H+C+C1+C2+C1M+C2M)-(mu+mu[T])*T;
eq_3 := (beta*(H+C+C1+C2)*S-tau*(T+C)*H)/(S+T+H+C+C1+C2+C1M+C2M)-(mu+mu[A])*H;
eq_4 := (beta*(H+C+C1+C2)*T+tau*(T+C)*H)/(S+T+H+C+C1+C2+C1M+C2M)-(mu+mu[T]+mu[A]+lambda[T])*C;
eq_5 := lambda[T]*C-(mu+mu[A]+rho[1]+eta[1])*C1;
eq_6 := rho[1]*C1-(mu+mu[A]+rho[2]+eta[2])*C2;
eq_7 := eta[1]*C1-(mu+rho[1]+gamma)*C1M;
eq_8 := eta[2]*C2+rho[1]*C1M-(mu+rho[2]+gamma*rho[1]/(rho[1]+rho[2]))*C2M;
J := VectorCalculus:-Jacobian([eq_1, eq_2, eq_3, eq_4, eq_5, eq_6, eq_7, eq_8], [S, T, H, C, C1, C2, C1M, C2M]);

JQDFE := eval(J, [S = Lambda/(beta-mu[A]), T = 0, H = Lambda*(beta/(mu+mu[A])-1)/(beta-mu[A]), C = 0, C1 = 0, C2 = 0, C1M = 0, C2M = 0]);

Thanks.

Hi,

I use the VectorCalculus package to calcutate derivative formula for geometric functions, and met difficulity simplifying the result expression.

For example, I define some vectors P, S, V like below:

P:=<Px, Py, Pz>, S:=<Sx, Sy, Sz>, V:=<Vx, Vy, Vz>

then define an intermediate variable Q:=P - S,

then define a function d:= sqrt(DotProduct(Q, Q)-(DotProuct(Q,V))^2)

by calculating the function's derivative w.r.t Px I got a very complex result expression:

dpx:=1/2 * (2Px - 2Sx - 2 ( (Px - Sx) Vx + (Py - Sy) Vy + (Pz - Sz)Vz )Vx ) / (sqrt( (Px-Sx)^2 + (Py-Sy)^2 + (Pz-Sz)^2 - .....)

 

Apparently this expression can be simplified by substituting its sub-expression with pre-defined variables like Q and d.

I know I can use subs, eval, and subsalg to do it manually:

subs(1/(sqrt( (Px-Sx)^2 + (Py-Sy)^2 + (Pz-Sz)^2 - .....) = 1/dv, dfdpx)

subs((Px - Sx) Vx + (Py - Sy) Vy + (Pz - Sz)Vz = dotproduct_q_v, dfdpx)

and I can get a simplified expression like this:

(qx-dotproduct_q_v*vx)/d

 

But it's like my brain does the simplification first, and Maple only does the text substitution for me.

Is there any way to do it automatically?

 

Thanks,

-Kai

 

I experienced strange operation of "union" for sets of vectors.

Mt1:=Matrix(2, 4, [[ 0,1, 0, 0], [ 0,  0,  1, 1]]); Ms := Vector[column](4, [8,4,2,1]); St1 := {}:

St1:= `union`(St1, {Mt1 . Ms});

I am surprised, because each execution of union adds new and the same vector <4 | 3> to set St1:

1

But after copying any set in the clipboard and pasting the set St1 has only one instance of vector <4 | 3>:

2

What does it mean?

Does anyone know how to incorporate the tetrad with the directional derivative? I tried using the SumOverIndices, but get crazy results. I know Maple can find the answer easily because I have done the same thing by hand. What am I missing?

The directional derivative should take the form f,1 = eaμ df/dxμ . The answer is Y,1 = dY/dζ – Ybar dY/du.  I obviously do not get this result.

 


restart; with(Physics); with(Tetrads)

0, "%1 is not a command in the %2 package", Tetrads, Physics

(1)

`#msup(mi("ds",mathcolor = "#af00af"),mn("2",mathcolor = "#af00af"))` := Physics:-`*`(Physics:-`*`(2, dzeta), dzetabar)+Physics:-`*`(Physics:-`*`(2, du), dv)+Physics:-`*`(Physics:-`*`(2, H(zetabar, zeta, v, u)), (du+Physics:-`*`(Ybar(zetabar, zeta, v, u), dzeta)+Physics:-`*`(Y(zetabar, zeta, v, u), dzetabar)-Physics:-`*`(Physics:-`*`(Y(zetabar, zeta, v, u), Ybar(zetabar, zeta, v, u)), dv))^2)

2*dzeta*dzetabar+2*du*dv+2*H(zetabar, zeta, v, u)*(du+Ybar(zetabar, zeta, v, u)*dzeta+Y(zetabar, zeta, v, u)*dzetabar-Y(zetabar, zeta, v, u)*Ybar(zetabar, zeta, v, u)*dv)^2

(2)

X = [zetabar, zeta, v, u]

X = [zetabar, zeta, v, u]

(3)

PDEtools:-declare(`#msup(mi("ds",mathcolor = "#af00af"),mn("2",mathcolor = "#af00af"))`)

Ybar(zetabar, zeta, v, u)*`will now be displayed as`*Ybar

(4)

Setup(automaticsimplification = true, coordinatesystems = (X = [zetabar, zeta, v, u]), metric = 2*dzeta*dzetabar+2*du*dv+2*H(zetabar, zeta, v, u)*(du+Ybar(zetabar, zeta, v, u)*dzeta+Y(zetabar, zeta, v, u)*dzetabar-Y(zetabar, zeta, v, u)*Ybar(zetabar, zeta, v, u)*dv)^2)

[automaticsimplification = true, coordinatesystems = {X}, metric = {(1, 1) = 2*H(X)*Y(X)^2, (1, 2) = 1+2*H(X)*Y(X)*Ybar(X), (1, 3) = -2*H(X)*Y(X)^2*Ybar(X), (1, 4) = 2*H(X)*Y(X), (2, 2) = 2*H(X)*Ybar(X)^2, (2, 3) = -2*H(X)*Ybar(X)^2*Y(X), (2, 4) = 2*H(X)*Ybar(X), (3, 3) = 2*H(X)*Y(X)^2*Ybar(X)^2, (3, 4) = 1-2*H(X)*Y(X)*Ybar(X), (4, 4) = 2*H(X)}]

(5)

g_[]

g_[mu, nu] = (Matrix(4, 4, {(1, 1) = 2*H(X)*Y(X)^2, (1, 2) = 1+2*H(X)*Y(X)*Ybar(X), (1, 3) = -2*H(X)*Y(X)^2*Ybar(X), (1, 4) = 2*H(X)*Y(X), (2, 1) = 1+2*H(X)*Y(X)*Ybar(X), (2, 2) = 2*H(X)*Ybar(X)^2, (2, 3) = -2*H(X)*Ybar(X)^2*Y(X), (2, 4) = 2*H(X)*Ybar(X), (3, 1) = -2*H(X)*Y(X)^2*Ybar(X), (3, 2) = -2*H(X)*Ybar(X)^2*Y(X), (3, 3) = 2*H(X)*Y(X)^2*Ybar(X)^2, (3, 4) = 1-2*H(X)*Y(X)*Ybar(X), (4, 1) = 2*H(X)*Y(X), (4, 2) = 2*H(X)*Ybar(X), (4, 3) = 1-2*H(X)*Y(X)*Ybar(X), (4, 4) = 2*H(X)}))

(6)

``

NULL

NULL

eqn3 := SumOverRepeatedIndices(Physics:-`*`(d_[mu](Y(X)), e_[1, `~mu`]))

((Y(X)*Ybar(X)-1)*(diff(Y(X), zetabar))+(Y(X)*Ybar(X)-1)*(diff(Y(X), zeta))+(diff(Y(X), u)+diff(Y(X), v))*(Y(X)+Ybar(X)))*2^(1/2)/((-(Ybar(X)^2+1)*(Y(X)^2+1)/(Y(X)+Ybar(X))^2)^(1/2)*(2*Y(X)+2*Ybar(X)))

(7)

NULL

``

NULL


Download Directional_Derivative.mw

I am using the SumOverRepeatedIndices and get a Length of Output Exceeded error. Sometimes if I close the file and restart the program then I get a result and no error.  However, if I recalculate then I get the error.

 


restart; with(Physics); with(Tetrads)

[e_, eta_, gamma_, l_, lambda_, m_, mb_, n_]

(1)

`#msup(mi("ds",mathcolor = "#af00af"),mn("2",mathcolor = "#af00af"))` := Physics:-`*`(Physics:-`*`(2, dzeta), dzetabar)+Physics:-`*`(Physics:-`*`(2, du), dv)+Physics:-`*`(Physics:-`*`(2, H(zeta, zetabar, u, v)), (du+Physics:-`*`(Ybar(zeta, zetabar, u, v), dzeta)+Physics:-`*`(Y(zeta, zetabar, u, v), dzetabar)-Physics:-`*`(Physics:-`*`(Y(zeta, zetabar, u, v), Ybar(zeta, zetabar, u, v)), dv))^2)

2*dzeta*dzetabar+2*du*dv+2*H(zeta, zetabar, u, v)*(du+Ybar(zeta, zetabar, u, v)*dzeta+Y(zeta, zetabar, u, v)*dzetabar-Y(zeta, zetabar, u, v)*Ybar(zeta, zetabar, u, v)*dv)^2

(2)

X = [zeta, zetabar, u, v]

X = [zeta, zetabar, u, v]

(3)

PDEtools:-declare(`#msup(mi("ds",mathcolor = "#af00af"),mn("2",mathcolor = "#af00af"))`)

Ybar(zeta, zetabar, u, v)*`will now be displayed as`*Ybar

(4)

Setup(coordinates = (X = [zeta, zetabar, u, v]), metric = 2*dzeta*dzetabar+2*du*dv+2*H(zeta, zetabar, u, v)*(du+Ybar(zeta, zetabar, u, v)*dzeta+Y(zeta, zetabar, u, v)*dzetabar-Y(zeta, zetabar, u, v)*Ybar(zeta, zetabar, u, v)*dv)^2)

[coordinatesystems = {X}, metric = {(1, 1) = 2*H(X)*Ybar(X)^2, (1, 2) = 1+2*H(X)*Ybar(X)*Y(X), (1, 3) = 2*H(X)*Ybar(X), (1, 4) = -2*H(X)*Ybar(X)^2*Y(X), (2, 2) = 2*H(X)*Y(X)^2, (2, 3) = 2*H(X)*Y(X), (2, 4) = -2*H(X)*Y(X)^2*Ybar(X), (3, 3) = 2*H(X), (3, 4) = 1-2*H(X)*Ybar(X)*Y(X), (4, 4) = 2*H(X)*Y(X)^2*Ybar(X)^2}]

(5)

g_[]

g_[mu, nu] = (Matrix(4, 4, {(1, 1) = 2*H(X)*Ybar(X)^2, (1, 2) = 1+2*H(X)*Ybar(X)*Y(X), (1, 3) = 2*H(X)*Ybar(X), (1, 4) = -2*H(X)*Ybar(X)^2*Y(X), (2, 1) = 1+2*H(X)*Ybar(X)*Y(X), (2, 2) = 2*H(X)*Y(X)^2, (2, 3) = 2*H(X)*Y(X), (2, 4) = -2*H(X)*Y(X)^2*Ybar(X), (3, 1) = 2*H(X)*Ybar(X), (3, 2) = 2*H(X)*Y(X), (3, 3) = 2*H(X), (3, 4) = 1-2*H(X)*Ybar(X)*Y(X), (4, 1) = -2*H(X)*Ybar(X)^2*Y(X), (4, 2) = -2*H(X)*Y(X)^2*Ybar(X), (4, 3) = 1-2*H(X)*Ybar(X)*Y(X), (4, 4) = 2*H(X)*Y(X)^2*Ybar(X)^2}))

(6)

NULL

``

eqn1 := SumOverRepeatedIndices(Physics:-`*`(d_[mu](Y(Zeta, zetabar, u, v)), e_[1, `~mu`])) = 0

`[Length of output exceeds limit of 1000000]`

(7)

eqn2 := SumOverRepeatedIndices(Physics:-`*`(d_[mu](Y(Zeta, zetabar, u, v)), e_[2, `~mu`])) = 0

`[Length of output exceeds limit of 1000000]`

(8)

eqn3 := SumOverRepeatedIndices(Physics:-`*`(d_[mu](Y(Zeta, zetabar, u, v)), e_[4, `~mu`])) = x

(1/2)*(-(diff(Y(Zeta, zetabar, u, v), zetabar))*(Y(X)*Ybar(X)+1)*2^(1/2)+(diff(Y(Zeta, zetabar, u, v), u))*2^(1/2)*(Y(X)-Ybar(X))-(diff(Y(Zeta, zetabar, u, v), v))*2^(1/2)*(Y(X)-Ybar(X)))/((-(Ybar(X)^2+1)*(Y(X)^2+1)/(Y(X)-Ybar(X))^2)^(1/2)*(Y(X)-Ybar(X))) = x

(9)

eqn1 := `[Length of output exceeds limit of 1000000]` = 0

`[Length of output exceeds limit of 1000000]` = 0

(10)

algsubs(`[Length of output exceeds limit of 1000000]` = 0, `[Length of output exceeds limit of 1000000]`)

0

(11)

``

simplify(`[Length of output exceeds limit of 1000000]`)

``


Download Derive_Eq_4.4.mw

Hey!

I have this MATLAB script, but as I work in Maple, I'll need to translate it to Maple. 
I know how to define symbols and functions, but I don't know which Maple commands to use, of if it needs to be done in another way, so the problem is translating from " dZ = [dx; dy; ax; ay; dm];" and down.

Any help would truly be greatly appreciated! Thank you!  



This is the script:

function dZ = meteor_step(~, Z)

  P = 1.2; % initial atmospheric pressure
  H = 1.39E-4; % scale height of atm pressure
  E = 8.11131859E6; % evaporation energy
  D = 1; % drag constant
  G = 9.814; % acceleration due to gravity
  PM = 3.3E3; % density of the meteor
  
  S = 3.986E14; % standard gravitational parameter of Earth (G*M)
  R = 6.3674447E6; % radius of the Earth (meters)

  x = Z(1);  
  y = Z(2);
  dx = Z(3);
  dy = Z(4);
  m = Z(5);
  
  atm = P*exp(-y*H);

  v = sqrt(dx^2+dy^2);

  area = pi * ( (3*m)/(4*PM) )^(2/3);

  dist = sqrt(x^2+y^2);
  Gv = -9.8;

  accel = -(D*atm*area)/m*v;
  ax = accel * dx;
  ay = accel * dy + Gv;
  

  dm = -(atm*v^3*area)/(2*E);
  
  dZ = [dx; dy; ax; ay; dm];
  
end

 

 

 

 

[t, R] = ode45(@meteor_step, [0 250], [0, 100000, 100, -300, 25]);

x = R(:,1);
y = R(:,2);

dx = R(:,3);
dy = R(:,4);

v = (dx.^2+dy.^2).^(1/2);

m = R(:,5);

figure(1);
plot(t, y);
  title('Meteor Kinematics: Height vs Time');
  xlabel('Time elapsed (s)');
  ylabel('Height (m)');

figure(2);
plot(x, y);
  title('Meteor Kinematics: Horizontal vs Vertical Position');
  xlabel('Horizontal (m)');
  ylabel('Vertical (m)');

figure(3);
plot(t, v);
  title('Meteor Kinematics: Speed vs Time');
  xlabel('Time elapsed (s)');
  ylabel('Absolute speed (m/s)');

figure(4);
plot(t, m);
  title('Meteor Kinematics: Mass vs Time');
  xlabel('Time elapsed (s)');
  ylabel('Mass (kg)');

  
figure(5);
plot(t, dy);
  title('Vertical Velocity vs Time');
  xlabel('Time elapsed (s)');
  ylabel('Vertical velocity (m/s)');

temp = abs(y - 52900);
[~, index] = min(temp);
  
t(index)
dx(index)/1000
dy(index)/1000

I am just starting with Maple 18 on Windows 8.1. I did not like the default color palette for 2D graphs and tried another one. So I edited my maple.ini file, which was in 

Excuse me,

 

  I have the following input

***

fff:=x1^k;
int(fff,x1=0..x2);

***

I would like to obtain

1/(k+1)* (x2^(k+1)), k<>-1

 

but maple gives me just the same integral. Is there any way to get the expression?

 

Thank you!

 

 

 

First 70 71 72 73 74 75 76 Last Page 72 of 88