tomleslie

13876 Reputation

20 Badges

15 years, 182 days

MaplePrimes Activity


These are replies submitted by tomleslie

Obviously, your response solves the OP's problem, but a couple of things about this code bother me - because I think that they shouldn't work!

#################################

The first thing which botthers me, is that the OP's code (the way that the Append() command is used) appears to rely on the ability to modify a passed parameter. For example the command Append(Rx1, Q(i)) would appear to modify the formal parameter Rx1. I always thought that Maple did not permit modification of a passed parameter within a procedure body. For example, the 'toy' code

myPlus:=proc(a)
                         a:=a+1;
                         return a
                end proc;
myPlus(1);

will fail, with the error message: Error, (in myPlus) illegal use of a formal parameter. So why in (your modification of) the OP's code, can each of the formal parameters Rx1, Rx2, Rx3, Rx4, Ry1, Ry2, Ry3, Ry4, be successfully modified? Have I missed something?

#################################

The second thing which bothers me in the OP's code is the use of "round brackets" to select indexable entries in, for example

Q:=<0, 2, 4, 6, 7, 17, 27, 57, 67, 97>
Rx1 := Vector([Q(1)]);

when did Q(1) ( rather than Q[1] ) become an accptable way for selecting the first element of Q? Again, have I missed something?

I'd be very pragmatic on this point.

My operational hypothesis woud be that for "complicated" data structures (tables, rtables, Arrays, arrays, Matrix, matrix), then a simple assignment statement will always result in pass-by-reference. In other words, for the pseudocode sequence

define A
B:=A;
change A

the effect of the last command (ie change A) will result 'B' also changing, because 'B' is not a complete stand-alone copy of 'A', but a 'pointer' to 'A'.

For this reason I would suggest that if you need/want to create a stand-alone copy of 'A' in some sequence like the above then you should always use the appropriate copy() command, rather than a simple assignment

Fire up the Maple help facility, as in Help->Maple Help on the toolbar. In the left-hand pane of the resulting help window, somwhere near the bottom, there is an entry called "Manuals", within which there is a "User Manual", which covers the basics and a "Programming Guide" for more advanced stuff.

Essentially the same info is available in pdf format from the Maple documentation centre at

https://www.maplesoft.com/documentation_center

The whole issue of "pass-by-value" and "pass-by-reference" is subtler than I thought.

A table() always seems to be pass-by-reference (whihc is why your problem occurs), but for matrices and arrays, the behaviour is different depending on whether one uses Matrix(), Array() or the (admittedly deprecated) matrix(), array(). The former pair appear to be pass-by-value, whereas the latter appear to be pass-by-reference. This was news to me!

Contemplate the attached carefully

restart;
M:=Matrix(2,2, [[2,3],[4,5]]):
s:=M:
M:=sqrt~(M);
eval(s);
 

_rtable[18446744074351542390]

 

Matrix(%id = 18446744074351542270)

(1)

restart;
M:=matrix(2,2, [[2,3],[4,5]]):
s:=M:
M:=sqrt~(M);
eval(s);
 

M := Matrix(2, 2, {(1, 1) = sqrt(2), (1, 2) = sqrt(3), (2, 1) = 2, (2, 2) = sqrt(5)})

 

array( 1 .. 2, 1 .. 2, [( 1, 2 ) = (3^(1/2)), ( 1, 1 ) = (2^(1/2)), ( 2, 2 ) = (5^(1/2)), ( 2, 1 ) = (2)  ] )

(2)

restart;
M:=table( [2,3,4,5]):
s:=M:
M:=sqrt~(M);
eval(s);
 

table( [( 1 ) = 2^(1/2), ( 2 ) = 3^(1/2), ( 3 ) = 2, ( 4 ) = 5^(1/2) ] )

 

table( [( 1 ) = 2^(1/2), ( 2 ) = 3^(1/2), ( 3 ) = 2, ( 4 ) = 5^(1/2) ] )

(3)

restart;
M:=Array(1..2,1..2, [[2,3],[4,5]]):
s:=M:
M:=sqrt~(M);
eval(s);

_rtable[18446744074351542390]

 

Array(%id = 18446744074351542270)

(4)

restart;
M:=array(1..2,1..2, [[2,3],[4,5]]):
s:=M:
M:=sqrt~(M);
eval(s);

M := Matrix(2, 2, {(1, 1) = sqrt(2), (1, 2) = sqrt(3), (2, 1) = 2, (2, 2) = sqrt(5)})

 

array( 1 .. 2, 1 .. 2, [( 2, 1 ) = (2), ( 1, 2 ) = (3^(1/2)), ( 1, 1 ) = (2^(1/2)), ( 2, 2 ) = (5^(1/2))  ] )

(5)

 

Download pbvr.mw

As 'vv' has pointed out, in your original expression there is also the undefined variable sigma[s] mutiplying the whole expression. If I

  1. just ignore this - equivalent to setting sigma[s]=1, and
  2. do a quick search and replace so that every occurrence of y( in your original expression is replaced with y*(. This may not give the expression you want, becuase there are now places in the expresssion where one is completely dependent on operator precedence. But since you do not post the syntactically correct expression you are dealing with,...........

I ended up with

expr:=1/4-Int((BesselJ(1, y))^2/y*(1+y*(400*10^(-10)/a)^2+sqrt(1+y*(400*10^(-10)/a)^2)), y = 0 .. 10^4)

which I can evaluate for several values of 'a' using

seq( evalf( eval(expr, a=j)), j=1..10) ;

to get the answers

 -.7499363406, -.7499363406, -.7499363406, -.7499363406, -.7499363406, -.7499363406, -.7499363406, -.7499363406, -.7499363406, -.7499363406

which isn't really very interesting. One can plot this as a function of 'a', with

plot( evalf( eval(expr, a=j)), j=1..10);

which takes a while (~10secs on my machine) to execute, and produces a very boring "straight-line" plot

 

 

 

so it needs an unusual solution approach. Consider two of your boundary conditions

bc:=u(0,t)=-12*t^2,u(1,t)=1-12*t^2

Note that as t->infinity, both u(0,t) and u(1,t) head for -infinity: so as a "beam", neither of its ends is fixed to anything. A very unusual "beam"

Rouben's solution correctly replicates this behaviour, and also makes it clear that (the deflection?) u(x,t) forany value of x, 0<x<1, heads for -infinity as t->infinity

Systems with weird boundary conditions, sometimes need unconventional solution methods

you seem to be using 'y' as the variable of integration, and also as an (undefined!) function. For example, what is meant by

y(400*10^(-10)/a)^2   ??????

This is the square of the undefined function y(), with argument 400*10^(-10)/a.

Are you missing a few multiply signs ('*') in your original expression

The code

restart;
kernelopts(version);
Physics:-Version();
pde := diff(u(x, t), t, t) = diff(u(x, t), x, x)+5*sin(3*x);
bc := u(0, t) = 0, u(Pi, t) = 0;
ic := u(x, 0) = 0, (D[2](u))(x, 0) = 1;
sol1 := pdsolve({bc, ic, pde});
sol := pdsolve(pde, {bc, ic}, numeric); sol:-plot3d(x = 0 .. 1, t = 0 .. 1);

works correctly in Maple 18, Maple 2015 and Maple 2017, but throws an error in Maple 1016, although it still produces the required output plot!. (Version detials are given below) .Don't think I can help much with this kind of difference between Maple versions. Can only suggest that you update to the latest Maple version (ie 2017.3). Alternatively, since I'm guessing that you are using Maple 2016, ensure that you have the latest version. Furthermore you should probably download/install the latest "Physics" version for Maple 2016: ie from

https://www.maplesoft.com/products/maple/feature/physicsresearch.aspx.

suggest you download/install  Physics_DEs_MathFuncs_Maple2016.16.7.zip

#######################################################################################

Detailed version analysis

Your code executes correctly in Maple 18 with no warnngs or error messages. Returned version info for my installation from this code in Maple 18

Maple 18.02, X86 64 WINDOWS, Oct 20 2014, Build ID 991181
"C:\Program Files\Maple 18\lib\update.mla",  2014, October 21, 1:29 hours

 

Identical code executes correctly in Maple 2015 with no warnngs or error messages. Returned version info for my installation from this code in Maple 2015.2 is

Maple 2015.2, X86 64 WINDOWS, Dec 20 2015, Build ID 1097895
"C:\Program Files\Maple 2015\lib\update.mla", 2015, December 21, 1:19 hours

 

Identical code executes correctly in Maple 2017 with no warnngs or error messages. Returned version info for my installation from this code in Maple 2017.2 is

Maple 2017.3, X86 64 WINDOWS, Sep 13 2017, Build ID 1262472
"C:\Program Files\Maple 2017\lib\Physics2017.mla",2018, February 21, 18:0 hours

But in Maple 2016, the above code throws an Error message - but still seems to produce the required (correct?) output plot. The returned version info for my installation from this code in Maple 2016

Maple 2016.2, X86 64 WINDOWS, Jan 13 2017, Build ID 1194701
"C:\Program Files\Maple 2016\lib\update.mla", 2017, January 13, 5:18 hours

and it produces the "error" Error, (in PDEAdvisor/2nd_order/Series/WithSourceTerm) invalid input: rhs expects 1 argument, but received 2

 

 

and it would have taken me forever to get this analytically!

As one would expect, if I adjust the plot ranges to correspond to those you have used in the above, then the numeric version produces identical(?!) answers, as in

restart;
pde := diff(u(x, t), t, t) = diff(u(x, t), x, x)+5*sin(3*x);
bc := u(0, t) = 0, u(Pi, t) = 0;
ic := u(x, 0) = 0, (D[2](u))(x, 0) = 1;
sol1 := pdsolve({pde, bc, ic});
sol := pdsolve(pde, {bc, ic}, numeric);sol:-plot3d(x = 0 .. Pi, t = 0 .. Pi);

diff(diff(u(x, t), t), t) = diff(diff(u(x, t), x), x)+5*sin(3*x)

 

u(0, t) = 0, u(Pi, t) = 0

 

u(x, 0) = 0, (D[2](u))(x, 0) = 1

 

 

_m1116646880

 

 

 

Download pdeProb2.mw

The code you posted cannot be executed. I listed some of the reasons why.

If I can't execute your code, I can't help

The code above will not execute for a number of reasons

  1. needs a with(LinearAlgebra) statement
  2. 'Jesus[H]' is undefined, because 'H' is undefined and 'Jesus' is undefined
  3. 'tt' is undefined
  4. the function close3() is undefined
  5. and that is just for the first statement in the code you upload - htere may be more in subsequent statements, I couldn't be bothered to check

If you really want help, then upload something which executes and *clearly* demonstrates the problem

restart;
pde := diff(u(x, t), t, t) = diff(u(x, t), x, x)+5*sin(3*x);
bc := u(0, t) = 0, u(Pi, t) = 0;
ic := u(x, 0) = 0, (D[2](u))(x, 0) = 1;
sol1 := pdsolve(pde, {bc, ic});
sol := pdsolve(pde, {bc, ic}, numeric);
sol:-plot3d(x = 0 .. 1, t = 0 .. 1)

For reasons (which are a mystery to me) the pdsolve() calling sequence for  analytic solutions and numeric solutions is different!! For an attempt an analytic solution, the pde(s), ics, and bcs have to be grouped as a single list/set, whereas for a numeric solution, the pde and the bcs/ics have to be separate lists/sets. So instead of the above try

restart;
pde := diff(u(x, t), t, t) = diff(u(x, t), x, x)+5*sin(3*x);
bc := u(0, t) = 0, u(Pi, t) = 0;
ic := u(x, 0) = 0, (D[2](u))(x, 0) = 1;
sol1 := pdsolve({pde, bc, ic});
sol := pdsolve(pde, {bc, ic}, numeric);sol:-plot3d(x = 0 .. 1, t = 0 .. 1);

Note the differeetn argument groupings in the pdsolve() command

 

That's pretty much what I got when saving as EPS from Maple 18 - see my earlier response

First thing to remember is that when I executed your original worksheet, it completed with no errors. I used Maple2017.3 (my default).

The only thing I noticed which surprised me was that the autosave function was executing every couple of minutes, and the associated file saving was taking much longer (about 30secs) than I would have expected for a worksheet containing this amount of data+output. The only conclusion I could draw from this was that there was something "big" in the original worksheet which I couldn't see.

I'm not personally a big fan of using 2-D input - it adds an extra level of "parsing" before execution, and can be quite good at hiding problems which become obvious when using 1-D input, which you can think of as pretty much plaintext. So I converted the whole worksheet to 1D input. The only thing which looked odd about this was that the variable which appeared as Nu, suddenly became `&Nu;u` (including the backticks). I used simple search-and-replace to rename this variable to Nu. I may (or may not, can't remember) have changed a couple of other variable names in the same way.

The worksheet was still functional, but the autosave function was now so fast that I really didn't notice it happening. So far I didn't really think I had "fixed" anything. Then I noticed that you were using Maple 2015, so I tried my 1D input file in all Maple versions I currently have installed: it worked in all of them with no problems, so it didn't look like a version issue.

At this stage I was out of ideas, so I thought the best I could do would be to upload the 1D-input file, so that you could run it on your Maple installation: if it ran, then your Maple installation is almost certainly fine, and hence your original problem is some 2D-input artefact, which I (more-or-less) inadvertently fixed by converting it to 1D input and tidying up some variable names.

was "clean up" the file you originally posted.

I have no idea what you mean by the statement "It's ambiguous yet"

First 102 103 104 105 106 107 108 Last Page 104 of 207