zenterix

400 Reputation

5 Badges

3 years, 0 days

MaplePrimes Activity


These are replies submitted by zenterix

@acer 

I just have a question about the use of "combine" with a single argument as is being done in the worksheet you sent with improvements.

Finally, consider the fourth boundary condition.

restart

NULL

`ψ__2,d` := proc (z) options operator, arrow; -A*s*sin(s*z)+B*s*cos(s*z) end proc = proc (z) options operator, arrow; -A*s*sin(s*z)+B*s*cos(s*z) end procNULL

`ψ__3,d` := proc (z) options operator, arrow; G*s__2*exp(s__2*z) end proc = proc (z) options operator, arrow; G*s__2*exp(s__2*z) end procNULL

expr3 := B = A*sqrt((V__0-E)/E) = B = A*((V__0-E)/E)^(1/2) 

NULL

 

Here is what is done in the original worksheet:

expr4 := combine(eval(isolate(`ψ__2,d`(l) = `ψ__3,d`(l), G), expr3))

G = A*s*((-(-V__0+E)/E)^(1/2)*cos(s*l)-sin(s*l))*exp(-s__2*l)/s__2

(1)

Let's redo in steps. First, we simply isolate G

isolate(`ψ__2,d`(l) = `ψ__3,d`(l), G)

G = -(A*s*sin(s*l)-B*s*cos(s*l))/(s__2*exp(s__2*l))

(2)

After isolating G, we sub in an expression for B.

result := eval(isolate(`ψ__2,d`(l) = `ψ__3,d`(l), G), expr3)

G = -(A*s*sin(s*l)-A*((V__0-E)/E)^(1/2)*s*cos(s*l))/(s__2*exp(s__2*l))

(3)

NULL

My question is about the command "combine".

combine(result)

G = A*s*((-(-V__0+E)/E)^(1/2)*cos(s*l)-sin(s*l))*exp(-s__2*l)/s__2

(4)

When we use combine like this, what does it try to do exactly? I read the documentation, and "combine" takes a second argument specifying a set of transformations to use. It doesn't mention if there is a default value for this parameter.

 

From the command above, "combine" simply factors out common factors. Is what combine tries to do when it is used with one argument always just this type of factorization?

Download combine.mw

@acer 

Okay, I understand that I need to consider signs in order to think about simplifications.

Once I understood that I tried to replace an entire square root.

expr:=A*sqrt(x*y)

A*(x*y)^(1/2)

(1)

simplify(expr,[x*y=z])

A*z^(1/2)

(2)

simplify(expr,[sqrt(x*y)=z])

Error, (in simplify/siderels:-simplify/siderels) side relations must be polynomials in (name or function) variables

 

eval(expr,sqrt(x*y)=z)

A*z

(3)

algsubs(sqrt(x*y)=z,expr)

Error, (in algsubs) no variables appearing rationally in pattern

 
 

NULL

Not clear to me why these don't work. I need to read the documentation again.

Download subs_square_root.mw

@acer 

It did occur to me that the issue might be with the sign of m_1. I used "assuming" with one single "simplify" command. 

It did not occur to me that I would need to use a second "simplify" command wrapping the first and only then use "assuming".

@Scot Gould 

In the documentation I see the parameters side1, side2, ..., as being optional sets or lists. 

But the second and third arguments are expressions.

@C_R 

Is there some part of the documentation, book, or tutorial that you know of that might teach me a bit more about this sort of thing?

I would not have thought of squaring and taking the square root to obtain the desired simplification.

@C_R 

Ok, so simplify takes as first argument an expression to be simplified. solve returns an expression sequence. Only the first element of this expression sequence is simplified. The other elements are basically ignored (simplify accepts additional parameters that are names, sets, lists, etc) but not other expressions. (Actually, I just saw another reply saying that this behavior is weird and possibly a bug)

I have an additional question.

Consider one of the non-zero elements in (5).

How can I get Maple to simplify by eliminating the 2 in the denominator?

I am reading all I can about simplify in the documentation and also about collect but can't seem to acccomplish this.

@acer 

That does work, thanks. I guess I was hoping for some single command to do it.

@dharr 

To give some context as to where n comes from consider the thermodynamic equation

PV=nRT

Suppose we have a P_1 and a T_1. Then

V_1=nRT_1/P_1

which is a function of n.

Next consider the following equation

PV^g=k

which is a relationship between P and V for a specific type of thermodynamic process, namely, a reversible adiabatic process.

When we sub in P_1 and V_1 the result will be a function of n.

If we have a final pressure P_2 then we can use this equation to compute V_2, a function of n.

Finally, consider the integral of -PdV for this adiabatic process, which is a work integral.

int(k/V^g. V=V_1..V_2)

The integration limits are numbers times the variable n.

This is the type of integral I am asking about.

@C_R I don't quite understand what is going on in your answer.

1) dim_V

In (3) you aren't doing an assignment, so I'm not sure why you wrote that expression. Is dim_V some special type of variable name? Seems not to be. I can use any variable name in (4) and it still works.

Ie

int(n/v, v=n/t [m^3]..m/t [m^3]

works.

What is happening when we divide by some arbitrary variable?

I found the answer:

export exportCsvMatrix := proc(m:: Or(Matrix, list(Matrix)), fileName:: string)

ExportMatrix(fileName, m, target=csv):

end:

The documentation for this is here.

Honestly, I found it confusing because it appears that I could also use [Matrix] instead of list(Matrix) from that documentation but it doesn't work.

@Carl Love 

Interesting, if using strings is better then I will use them from now on.

You are right, there is no need to export these variables. In fact, the only reason they were declared as local variables is because the procedure that I showed is one that I refactored. That is I didn't write it from scratch. I erased the use of the variables, but forgot to remove the declarations.

@acer 

acer to the rescue. You solved it. That was the problem.

Finally, let me just say that everything I am trying to do with tables above I can do with lists and it works. That is, instead of having tables firstChevrons and chevrons that have as keys the nicely readable chevron2A, chevron2B, ... and as values Arrays of size 50 x 3, I can just use lists of these Arrays.

I just find it less readable and maintainable for the future.

So, the algorithm I am using above is correct. This is all a question of Maple's table.

Here is yet another perspective on what is happening.

print(chevrons[1]) gives

 

Now I would like to access the value at key chevron2A.

print(chevrons[1][chevron2A]) gives

I've tried countless times to access the 50 x 3 Array that this is supposed to be but I always get this name with subscript.

 

 

Note that

@Carl Love @acer

Now, I've decided to write this second reply to show what my procedure actually does. In the explanation I gave above, I simply returned [chevrons, firstChevrons]. What I actually do is as follows

Again, I assign to a variable chevrons the result of calling Grid:-Map on computeChevrons. Thus, I get a list of tables, each table with keys like chevron2A, chevron2B, etc.

At this point, I run a third parallelization.

Let me try to explain what each run of this parallelization does. One single run is for, say, chevron2A, and we have

firstChevrons[chevron2A] is a 50 x 3 Array.

chevrons[1][chevron2A] is a 50 x 3 Array.

chevrons[2][chevron2A] is a 50 x 3 Array.

chevrons[3][chevron2A] is a 50 x 3 Array.

(...)

chevrons[5][chevron2A] is a 50 x 3 Array.

 

The procedure computeConcatenatedChevron should simply take each one of these and stack them on top of each other to form a huge array of size 300 x 3.

Each run of the parallelization is one call to this procedure. (Thus it is called with chevron2A, then chevron2B, and so on. 

The result of the call to Grid:-Map on line 175 is thus a list containing eight Arrays of 300 x 3.

However, the code above fails on any single run and the problem is that there is an error on line 169.

Here is the output of the procedure

As you can see the print statements on lines 162 and 166 do not work as I would expect.

I would expect them to produce 50 x 3 Arrays but all I see are names.

Note that I am trying to print out pieces of chevrons and firstChevrons. In the first post above, where I simply returned these two things in a list and tried to access them in a worksheet I had issues accessing firstChevrons.

Now, I am trying to access them inside of a procedure that is inside my original procedure, and the issue I have is the opposite: I can't seem to access chevrons.

 

Here are a few snippets from the commented out DEBUG line when I uncomment it

 

What does Array(1..2, [1,5]) mean?

 

And here is what happens if I put a debug statement inside of computeConcatenaedChevron

 

In the debugging session above, I am reproducing the error seen in the pink text further up in this post by trying to concatenate firstChevrons[chevron2A] and chevrons[1][chevron2B]. 

Each of these should be 50 x 3, however, the operation is not working because chevrons[1][chevron2B] is not returning an Array, it is returning an indexed type, which I am unfamiliar with and not sure why arises.

1 2 3 4 5 6 7 Page 1 of 7