Carl Love

## 27187 Reputation

11 years, 342 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

## := vs. =...

You are mixing up the assignment operator := with the equality operator =. The code sample that you gave could not possibly work like you said because the parser will immediatey reject a statement beginning if a:= with the message "Error, `:=` unexpected."

You can have any number of statements between the then and elif, else, or end if as long as they are separated with colons or semicolons.

if a = 3 then   # = not :=
b:= 4;
c:= 2032;
h:= 7
elif a = 4 then
b:= 5;  c:= 1003;  h:= 42
else
b, c, h:= 7, 25, 62
end if;

After the else I've shown a multiple assignment statement.

## eliminate...

I doubt that the Asker was looking for any solution with r^4 appearing on the right side.

I prefer to use eliminate over isolate when possible. It handles multiple solutions nicely.

 > restart:
 > eq1:= (r^2*sin(t)^2+r^2*cos(t)^2)^2 = a^2*(r^2*cos(t)^2-r^2*sin(t)^2):
 > eq2:= algsubs(r^2= R, eq1);

Regular subs would have worked in this very particular case, but not on an expanded version.

 > Sol:= eliminate({eq2}, R);

 > eq3:= subs(R= r^2, Sol[2][1][]);

 > eq4:= combine(%);

 >

## op, lhs, rhs...

how to get x and y from left side f(x,y)

op(lhs(a));

and get y and x from right side f(y,x)?

op(rhs(a));

Regarding your title: There is a subtle difference between arguments and parameters. The x and y is this case are arguments. In a procedure definition such as

f:= (x,y)-> x+y

the x and y are parameters.

## tables...

Yes, when you assign to an indexed expression as in

A[k]:= x;

where A has not been otherwise defined, you create a hashtable. It can also be explicitly created by

A:= table().

It is one of the most important data structures in Maple. See ?table , ?indices , and ?entries .

## Plotting it...

Here's how to plot the solutions. In the commands inside the loop that I gave you before, change Sol to Sol[T]:

Sol[T]:= fsolve(sys3,{a,b,c,d,e,k1,k2,k3}):
print('T'= T, map(c-> 'X[c]'= eval(X[c], Sol[T]), [CH4, CO2, H2O, H2, CO]))
end do:

plots:-display(
`<|>`(seq(
plot([seq]([T, eval(X[c], Sol[T])], T= 600..1200, 50), title= c),
c= [CH4, CO2, H2O, H2, CO]
))
);

## Use a comma, not `and` in eval....

You have three eval statements of the form

eval(f, x= 0 and diff(x,x)= 0);

Those should be of the form

eval(f, [x= 0, diff(f(x), x)= 0]);

Note that in addition to getting rid of the and, I changed diff(x,x) to diff(f(x), x). You may have intended that to be diff(f1(x), x). You also may have intended for the initial f to be ODE, as in eval(ODE, [x= ...]).

## eval...

The basic technique is

1. Assign fsolve's result to a variable:
Sol:= fsolve(...);
2. Use eval to evaluate an expression with respect to the solution:
eval(X[CO2], Sol);

You assigned fsolve's solution to l, but I don't like that because it is difficult to distiguish from 1 or I in many fonts. So I used Sol instead. Make the last three lines of your for loop this:

Sol:= fsolve(sys3,{a,b,c,d,e,k1,k2,k3}):
print('T'= T, map(c-> 'X[c]'= eval(X[c], Sol), [CH4, CO2, H2O, H2, CO]))
end do:

and you will get one line of output for each loop iteration, each line like this (but it will all fit on one line):

I know that that is somewhat cryptic, so please let me know if it works for you and if you understand.

## Several representations of a group of ma...

From your questions of a few days ago, I know that you are getting to this point from a group of matrices. In particular, you think that there is some correspondence between

1  1  2
1  2  2

and the matrix

1  1
0  1.

Here, I will generate several representations of a small group of matrices, the 2x2 matrices with determinant 1 over the finite field Z2. The above matrix is in this group. Since I think that you don't have Maple 17, I won't use the new GroupTheory package.

 > restart:

Generate all 2x2 matrices of determinant 1 in Z2.

 > G:= table():
 > for i to 2 do for j to 2 do for k to 2 do for m to 2 do      A:= < < i, j > | < k, m > > mod 2;      if Det(A) mod 2 = 1 then G[A]:= [][] fi od od od od:
 > G:= [{indices}(G, nolist)[]];

Convert matrices to listlist form because member (like other normal equality tests) doesn't work on matrices.

 > G1:= map(convert, G, listlist);

This is a multplication operator for G where each element is represented by its index in the list.

 > Gmul:= proc(i,j)      local z,p;      z:= convert(G[i].G[j] mod 2, listlist);      member(z,G1,'p');      p end proc:

Use that to generate a multiplication table (also called a Cayley table) for the group.

 > C:= Matrix(6, 6, Gmul);

So, C[i,j] is the index of  G[i].G[j].

Each row (and each column, for that matter) of the table is a permutation of the six elements of the group.

The first row is a permutation of order 3.

 > x1:= convert(convert(C[1,..], list), disjcyc);

That corresponds to G[1] having order 3.

 > G[1]^2 mod 2, G[1]^3 mod 2;

The second row has order 2.

 > y1:= convert(convert(C[2,..], list), disjcyc);

 > G[2]^2 mod 2;

An element of order 3 and an element of order 2 must generate a group of order at least lcm(2,3) = 6, so in this case they must generate the whole group.

 > G2:= permgroup(6, {x= x1, y= y1}):
 > group:-grouporder(G2);

Now let's look at "words" constructed from the group generators.

 > convert([x], disjcyc, G2);

 > convert([x,x], disjcyc, G2);

 > convert([x,y], disjcyc, G2);

 > convert([x,x,y], disjcyc, G2);

 > convert([y,x], disjcyc, G2);

So xxy = yx. Thus xxyx^(-1)y^(-1) = e, the identity element. This gives us enough information to represent this as a "finitely presented" group.

 > G3:= grelgroup({X,Y}, {[X,X,X], [Y,Y], [X,X,Y,1/X,1/Y]}):

Represent the trivial identity subgroup so that we can get its cosets.

 > E:= subgrel({e= []}, G3):

Thus the following is another permutation representation of the same group.

 > G4:= group:-permrep(E, G3);

 >

## Merging column vectors...

You can merge an arbitrary sequence of m column Vectors into a Matrix like this:

A:= `<|>`(seq(`&varphi;`[1,k], k= 1..m));

## evalc...

If making an assumption about g is appropriate for your situation, then use evalc (which assumes that g is real) and assume g > -4.

`ex:= -(1/2*I)*(I*Pi*ln(2) - I*Pi*ln(g+4) - 2*ln(2)^2      + 2*ln(2)*ln(g+4) - 2*ln(2)*ln(-1/2*I) + ln(g+4)*ln(-1/2*I)       - ln(g+4)*ln(2*I) + ln(-1/2*I)*ln(4-g) + ln(4-g)*ln(2*I))     /Pi:evalc(ex) assuming g>-4;                    Pi ln(2) - Pi ln(g + 4)                    -----------------------                              Pi           combine(%);                             /1      \                          -ln|- g + 2|                             \2      /`

## Symbolic solution...

Surprisingly, Maple can get the symbolic solution to this very quickly if you give it just a tiny bit of help. It is trivial to solve ode1 for V(t) and substitute that into ode2. Then dsolve solves it in a few seconds.

 > restart:
 > ode1:= diff(L(t),t)*(V(t))=0.682*10^(-7);

 > SolV:= solve(ode1, {V(t)})[];

 > ode2:= 137*10^6*diff(V(t),t)*V(t)=(1/(4*3.14))*1.66*10^(-10)*L(t)^2*(3.5*10^3-V(t))^2;

 > ode:= eval(ode2, SolV);

 > ode:= solve(ode, {diff(L(t),t\$2)})[];

 > ic1:=V(0)=0.01;

 > ic2:=L(0)=0;

 > ic3:= subs(V(t)= eval(V(0), ic1), ode1);

 > ic3:= D(L)(0) = solve(ic3, diff(L(t), t));

 > Sol:= dsolve({ode, ic3, ic2}, {L(t),V(t)}, convert_to_exact= false);

 > SolL:= eval(Sol);

 > SolV:= eval(SolV, SolL);

 > Sol:= {SolV,SolL}:
 > plot(eval(L(t), Sol), t= 0..100);

 > plot(eval(V(t), Sol), t= 0..100);

 >

## rtable_eval...

This is not a problem with LinearAlgebra:-Equal.

When a Matrix (or other rtable) contains a symbolic (the a in your case) and that symbolic is changed, the Matrix is not automatically updated. One can force the update with rtable_eval:

A := Matrix([[a, 0], [0, 0]]);
for a from 0 to 10 do
A1:= rtable_eval(A);
if LinearAlgebra:-Equal(A1^2, A1) then print(a, A1) end if
end do;

I consider it a bad programming practice to use a for loop's index variable as a symbolic. However, Maple does allow it. So I'd rewrite the code as

A:= < < a, 0 > | < 0, 0 > >:
for k from 0 to 10 do
A1:= eval(A, a= k);
if LinearAlgebra:-Equal(A1^2, A1) then print(k, A1) end if
end do:

## Why they aren't working for you...

Why the method labelled "PROCEDURE" isn't working for you:

In this method, you've just moved the global/parameter conflict to an earlier procedure. In your procedure named qpercentagedifference, the parameter height is not the same as the global height that is "in" the variables qtotal and qpresent. Note that expressions created with the arrow (->) and with proc are essentially the same to Maple--they are both considered procedures.

In order to use this method, you have to be consistent "down through the chain" and make every expression using height a procedure with height as a parameter.

Why the method labelled "SUBS" isn't working for you:

The subs does not change the expression being substituted; rather it creates a new expression. For example, subs(x= _x, y) does not change y. There are several things that you can do to fix this.

(1)
modalmasspedestriansfail:= proc(subsheight)
if subs(height= subsheight, qpercentagedifference) >= 5/100 then
subs(height= subsheight, modalmasswithpedestrians)
else
subs(height= subsheight, modalmasswithoutpedestrians)
end if
end proc:

(2)modalmasspedestriansfail:= proc(subsheight)
local A, B, C;
A,B,C:= subs(
height= subsheight,
[qpercentagedifference,
modalmasswithpedestrians,
modalmasswithoutpedestrians
]

)[];
if A >= 5/100 then B else C end if
end proc

(3)
modalmasspedestriansfail:= proc(subsheight)
subs(
height= subsheight,
`if`(
qpercentagedifference >= 5/100
,
modalmasswithpedestrians,
modalmasswithoutpedestrians
)
)
end proc:

## variable used as parameter and global...

The problem has nothing to do with the if...then. In both of your examples, there are two different variables named height, one a global and one a procedure parameter. In your first example--the one the doesn't work--you are trying to use the global as the parameter. Here's a simplified version of your first example:

y:= x^2:
f:= proc(x) y end proc:

The x that is "in" y is not the same as the parameter x. This procedure won't plot.

There are several ways around this problem. One way is to make y a procedure:

y:= x-> x^2:
f:= proc(x) y(x) end proc:

A second way is to use a different name and subs one for the other:

y:= x^2:
f:= proc(_x) subs(x= _x, y)
end proc:

A third way is unapply:

y:= x^2:
Y:= unapply(y, x):
f:= proc(x) Y(x) end proc:

And there are several more ways.

In your second example, the one that works, the height appears explicitly in the procedure. But, as you probably realize, this is not a good way to do it because you had to copy the expression into the procedure. Copying sections of code is always undesirable.

## out of memory--use numeric...

It looks like Maple ran out of memory trying to solve your equation symbolically. Get a numeric solution instead.

 Sol:= dsolve({ode1,ode2,ic1,ic2},{V(t),L(t)}, numeric);

You can plot the solutions with plots:-odeplot. See ?dsolve,numeric and ?plots,odeplot .

Example: Plot t vs. L(t):

plots:-odeplot(Sol, [[t,L(t)]], t= 0..100)

 First 354 355 356 357 358 359 360 Last Page 356 of 389
﻿