mmcdara

7891 Reputation

22 Badges

9 years, 59 days

MaplePrimes Activity


These are replies submitted by mmcdara

@acer 

Thanks, I will remember that

@love-algebra 

Probably not the simplest way to do this, but it works...

restart:
expr := 3*L*r/m/l/s+L/m:
MyRule := beta=L/m;

subs(L=solve(MyRule, L), expr);

eval(L[1, 1](r, theta), u__0(r, theta) = f[1, 1](r, theta));

# or

subs(u__0(r, theta) = f[1, 1](r, theta), L[1, 1](r, theta))

@Thomas Richard 

Answered from home, 

Thank you Thomas.

Since your optimization call succeeds both with method=ego and method=diffevol, there is probably no need to try other methods and options - apart from curiosity, which is okay. ;-)
Right, but the curiosity wasn't accidental: In my real application the solution of the ODE system depends on 10 parameters
(with quite different ranges of variation, but I normalized both of them between 0 and 1 to avoid numerical difficulties).
The first time I used GOT with diffevol I got an error message concerning the time limit.  Not the message you find in GetLastSolution help page, but an error message (I will be able to send it tomorrow) wich, from memory, said "error in convert/radical ... in < here some procedure, not always the same > ".
So I began to try other things.
Finally the problem was solved by setting the option "localrefinement" (sorry, I cite from memory) to false and by using diffevol ("ego" is much slower, so the idea to reduce the size of the design of experiments to build the response surfaces)

If you are interested I could post the true application tomorrow.

@zaidoun 

You're right, solz (output (5)) is the solution.

Please: note that the solution I obtained here was already found by Kitonum.

@zaidoun 

The command 

substitutes any occurences of z by exp(u), thus u becomes the "new variable".
The idea, following the initial remark Carl made, is to reduce the search range which extended to 5*10^10 to somethong smaller (z = 5*10^10 means u = log(5*10^10) ~25).
One problem is that your initial range for the imaginary part of z is -1000.. 5*10^10.
To cover this range with the change of variable z --> exp(u) is impossible. So, what I suggest you is:

  1. solve F(z) for a reasonable range: previous answers showed RootFinding works well for re=-1000..1000 and im=-1000..5000.
  2. Next solve G(u) on the extentendedrange  re=-1000..1000, im=log(5000)..log(5*10^10)


The command 

enables recovering z solutions solz from u solutions solu.
Remain solu is a list, so the command exp(solu) won,'t work. To recover solu you need:

  1. to build a loop over all the elements of solu and compute the exponential of each of them,
  2. or to apply exp to all the elements of solin a single shot:
    1. either by using the tilda symbol (see the corresponding help page for the tilda symbol)
    2. or by writing solz := map(exp, solu)

 

Finally the two last command evaluate G(u) for each u in solu and F(z) for each z in solz.
And YES, the result is (then 4 times the same, a thing that ought to be verified)
 

@zaidoun 

Maybe you could find some ideas here


 

restart; Digits := 20

r1 := sqrt(2^2-I*z);

(4-I*z)^(1/2)

(1)

r2 := sqrt(2^2+I*z);

(4+I*z)^(1/2)

(2)

F := -r2*(r1^2-(1/5)*2^2)^2*cosh((1/150)*r1*Pi)*sinh((1/150)*r2*Pi)+r1*(r2^2-(1/5)*2^2)^2*cosh((1/150)*r2*Pi)*sinh((1/150)*r1*Pi)+z*(-r1^2+r2^2)*cosh((1/150)*r1*Pi)*cosh((1/150)*r2*Pi)

-(4+I*z)^(1/2)*(16/5-I*z)^2*cosh((1/150)*(4-I*z)^(1/2)*Pi)*sinh((1/150)*(4+I*z)^(1/2)*Pi)+(4-I*z)^(1/2)*(16/5+I*z)^2*cosh((1/150)*(4+I*z)^(1/2)*Pi)*sinh((1/150)*(4-I*z)^(1/2)*Pi)+(2*I)*z^2*cosh((1/150)*(4-I*z)^(1/2)*Pi)*cosh((1/150)*(4+I*z)^(1/2)*Pi)

(3)

``

(4)

G := subs(z = exp(u), F);

-(4+I*exp(u))^(1/2)*(16/5-I*exp(u))^2*cosh((1/150)*(4-I*exp(u))^(1/2)*Pi)*sinh((1/150)*(4+I*exp(u))^(1/2)*Pi)+(4-I*exp(u))^(1/2)*(16/5+I*exp(u))^2*cosh((1/150)*(4+I*exp(u))^(1/2)*Pi)*sinh((1/150)*(4-I*exp(u))^(1/2)*Pi)+(2*I)*(exp(u))^2*cosh((1/150)*(4-I*exp(u))^(1/2)*Pi)*cosh((1/150)*(4+I*exp(u))^(1/2)*Pi)

 

[3.8593940676611702887+21.991148575128552669*I, 3.8593940676611702887+15.707963267948966192*I, 3.8593940676611702888+9.4247779607693797150*I, 3.8593940676611702887+3.1415926535897932385*I]

 

[-47.436599289272340540+0.11313803637424101255e-16*I, -47.436599289272340540+0.14857945353770406688e-16*I, -47.436599289272340545+0.18402087070116712123e-16*I, -47.436599289272340540-0.17720708581731527164e-17*I]

(5)

eval~(G, u=~sol__u);
eval~(F, z=~sol__z);

[-0.10688269926925727398e-14+0.1e-15*I, -0.14361096901711096670e-14+0.*I, -0.17178880581261977346e-14-0.7e-15*I, 0.10314134873926846362e-15+0.1e-15*I]

 

[-0.10688269926925727398e-14+0.1e-15*I, -0.14361096901711096670e-14+0.*I, -0.17178880581261977346e-14-0.7e-15*I, 0.10314134873926846362e-15+0.1e-15*I]

(6)

 


 

Download TryThis.mw

Don't have Maple 2018 right now, here is the result obtained with Maple 2015.2

 

restart:

interface(version);
sys := [diff(Y(x, t), t, t) = 0, Y(x, 0) = 0, (D[2](Y))(x, 1) = 0];
pdsolve(sys);

`Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895`

 

[diff(diff(Y(x, t), t), t) = 0, Y(x, 0) = 0, (D[2](Y))(x, 1) = 0]

 

Y(x, t) = 0

(1)

 


 

Download pde-2015.mw

@Carl Love 

It's the kind of thing you can do when there's nothing more interesting around here

  • I use to visit the site https://oeis.org/?language=english and I went to search if the sequence
    1, 28, 110, 384, 1316, 4496, 15352, 52416, 178960, 611008 ...  would not have interesting properties.
    Unfortunately this sequence is not identified, but, if you set f[1]=1 and f[2]=M, then f[n] = A[n]*M+B[n] where
    A = 0, 1, 4, 14, 48, 164, 560 ... and B = 1, 0, -2, -8, -28, -96, -328 ...
    Sequence A[n], from n> 1, is dubbed A007070
    Sequence B[n], from n> 2, is dubbed A106731
    They are both related and many characterizations for both of them, including generating functions and expansions of rational fractions are given.
    Unfortunately I wasn't capable to find any clue to prove the sequence generated with M=28 doesn't contain any square (except f[1] of course).
    Maybe you would be more successful?
     
  • So I had a little fun, here are a few results I got
     

    Download fun.mw

    Observations: 

    • For f[1]=1 only 25 values of f[2] in the range [2..675] contains (at least) one f[n] which is a square when n varies from 1 to 1000

    • The corresponding value of n is rather small... maybe it is even unique?

    • One also generate sequences with f[1]=p and f[2]=m (m>p). One finds that for some couples (m, p) there exist different values of n such that f[n] is a square


 

@Carl Love 

Thanks Carl.
I agree, these alse prompts "are a total nuisance to remove"

@phiost 

No problem.

In case you would be nevertheless interested in coloring "3D level curves" and identifying them by a legend you could find a few ideas here.

contourplot2.mw

@Carl Love 

Just a remark about the "prompt", 

If you copy-paste your first conditional sequence into a worksheet (worksheet mode) then its five line are preceeded with a prompt.
But, as they are in the same single execution group, the result is the one expected.
The prompts obtained by this copy-paste "are the same" as those you get when applying menu>edit>join on multiple groups.
Then it seems there are two kind of prompts, saying the "active" ones which begin a group and the "passive" ones inside a group.
So maybe it's notcompletely true to say "in other words, a single command prompt".
 

@vv 

Smart, as Iwrote to silvergasshoper I had done that years ago.
Your solution is definitely better, I thumb up.

A point of detail...

In the case where the thermal conductivity is discontinuous, your scheme doesn't guarantee the (physical) continuity of the thermal flux (unless the mesh size is adpated in a correct way left and right of the discontinuity points).
The classical method to avoid such unphysical solutions consists in deriving finite difference approximations that explicitely account for the continuity equations for the temperature and the thermal flux.
One can show that the correct thermal continuity at its points of disconinuity is the harmonic mean of its values left and right to these points.

On coarse grids the "harmonic" method is by far the better. On finer grids its superiority on the classical method (the one you used) tends to lessen. More of this the "harmonic" method is more time consuming and may be found complex to implement efficiently on unstructured meshes.
 

restart:

phi := x -> lambda(x)*diff(theta(x), x)

proc (x) options operator, arrow; lambda(x)*(diff(theta(x), x)) end proc

(1)

# let x = a a discontinuity point for lambda,
# for instance

lambda := x -> piecewise(x< a, lambda__L, lambda__R)

proc (x) options operator, arrow; piecewise(x < a, lambda__L, lambda__R) end proc

(2)

# for the heat equation, continuity equations for
# theta and flux phi  must be written :

theta__continuity := limit(theta(x), x=a, left) = limit(theta(x), x=a, right);
phi__continuity   := limit(phi(x), x=a, left) = limit(phi(x), x=a, right);

theta(a) = theta(a)

 

lambda__L*(D(theta))(a) = lambda__R*(D(theta))(a)

(3)

# finite difference approximation approximation :
#
# Let x__1 < .. < x__(i-1) < a=x__i < x__(i+1) < .. < x__N a cpllection of
# x points.
# Let omega__(k+1/2) the finite volume [x__k, x__(k+1)].
#
# In finite volume approaches a staggered mesh is used where temperatures
# are estimated at the mid points x__(k+1/2) (k=1..N-1) and fluxes phi are
# estimated at the finite volumes boundaries x__k (k=1..N).
#
# Let DL the divided difference the approximation of phi(x) in omega__(i-1/2)
#
# Let p = i-1/2 and x__i__L = limit(x__i - epsilon, epsilon=0^+)

DL := lambda__L * ( theta(x__i__L) - theta(x__p) ) / ( x__i__L - x__p )


 

lambda__L*(theta(x__i__L)-theta(x__p))/(x__i__L-x__p)

(4)

# Identically let DR the divided difference the approximation of phi(x) in omega__(i+1/2)
#
# Let q = i+1/2 and x__i__R = limit(x__i + epsilon, epsilon=0^+)

DR := lambda__R * ( theta(x__q) - theta(x__i__R) ) / ( x__q - x__i__R )

lambda__R*(theta(x__q)-theta(x__i__R))/(x__q-x__i__R)

(5)

# Remind theta is defined as points x__p and x__q alone.
# This means x__i is undefined and has to be estimated.
# This approximation relue supon the two continuity equations :

# by continuity of theta at point x__i one has

cond1L := theta(x__i__L) = theta(x__i);
cond1R := theta(x__i__R) = theta(x__i);

# by continuity of phi at point x__i one has

cond2 := DL = DR;

# at last, obviously,

cond3 := x__i__L = x__i;
cond4 := x__i__R = x__i;
 

theta(x__i__L) = theta(x__i)

 

theta(x__i__R) = theta(x__i)

 

lambda__L*(theta(x__i__L)-theta(x__p))/(x__i__L-x__p) = lambda__R*(theta(x__q)-theta(x__i__R))/(x__q-x__i__R)

 

x__i__L = x__i

 

x__i__R = x__i

(6)

COND := subs({cond1L, cond1R, cond3, cond4}, cond2)

lambda__L*(theta(x__i)-theta(x__p))/(x__i-x__p) = lambda__R*(theta(x__q)-theta(x__i))/(x__q-x__i)

(7)

# for the sake of simplicity, let's assume x__i-x__p = x__q-x__i = h/2

mesh := {x__p = x__i - h/2, x__q = x__i + h/2}

{x__p = x__i-(1/2)*h, x__q = x__i+(1/2)*h}

(8)

solve(COND, theta(x__i))

-(lambda__R*theta(x__q)*x__i-lambda__R*theta(x__q)*x__p-lambda__L*theta(x__p)*x__i+lambda__L*theta(x__p)*x__q)/(x__i*lambda__L-x__i*lambda__R+x__p*lambda__R-x__q*lambda__L)

(9)

subs(mesh, %);

-(lambda__R*theta(x__i+(1/2)*h)*x__i-lambda__R*theta(x__i+(1/2)*h)*(x__i-(1/2)*h)-lambda__L*theta(x__i-(1/2)*h)*x__i+lambda__L*theta(x__i-(1/2)*h)*(x__i+(1/2)*h))/(lambda__L*x__i-lambda__R*x__i+lambda__R*(x__i-(1/2)*h)-lambda__L*(x__i+(1/2)*h))

(10)

# temperature at point a (or at any point x__k where k is now an integer)
theta__a := simplify(%);

(lambda__R*theta(x__i+(1/2)*h)+lambda__L*theta(x__i-(1/2)*h))/(lambda__R+lambda__L)

(11)

# Injecting theta__a into DL (could be done with DR too) gives :

subs(theta(x__i__L)=theta__a, DL);
subs(cond3, %);
subs(mesh, %);

# thermal flux at point x=a (or at any point x__k where k is now an integer)
# (also known as "interfacial thermal flux")

phi__a := simplify(%);
 

lambda__L*((lambda__R*theta(x__i+(1/2)*h)+lambda__L*theta(x__i-(1/2)*h))/(lambda__R+lambda__L)-theta(x__p))/(x__i__L-x__p)

 

lambda__L*((lambda__R*theta(x__i+(1/2)*h)+lambda__L*theta(x__i-(1/2)*h))/(lambda__R+lambda__L)-theta(x__p))/(x__i-x__p)

 

2*lambda__L*((lambda__R*theta(x__i+(1/2)*h)+lambda__L*theta(x__i-(1/2)*h))/(lambda__R+lambda__L)-theta(x__i-(1/2)*h))/h

 

2*lambda__L*lambda__R*(theta(x__i+(1/2)*h)-theta(x__i-(1/2)*h))/((lambda__R+lambda__L)*h)

(12)

# The equivalent interfacial conductivity lambda__eq is de fined by the relation :

rel := lambda__eq*( theta(x__i+(1/2)*h) - theta(x__i-(1/2)*h) ) / h = phi__a:

Lambda__eq := solve(rel, lambda__eq);

2*lambda__L*lambda__R/(lambda__R+lambda__L)

(13)

# if lambda(x) is continuous at point x = a one has

subs(lambda__R = lambda__L, Lambda__eq);

lambda__L

(14)

# When continuity doesn't hold the equivalent interfacial conductivity is twice the
# harmonic mean of the left and right conductivities.
#
# In any case the correct divided differences approximation of the thermal flux is
# the expression phi__a above: only this one guarantees the continuity of the temperature
# and of the thermal flux at points where the thermal conductivity is discontinuous.

 


 

Download HarmonicMean.mw

To complete Tomleslie's answer, you could be interested to know that the value of  time "t0" can also be found by using the events feature of dsolve
(type "events" in the help and look to the  dsolve, numeric, Events (events) help page)

With tomleslies' notations ("events" are supported by rkf45 [default}, ck45 and rosenbrock methods)

sol1:= dsolve( 
               { sys, x(0)=0, y(0)=0, z(0)=cos(1), w(0)=sin(1)},
               type=numeric, method=rosenbrock, events=[[[x(t)<0, And(-y(t)<-5.5, y(t) < 6.5)], halt]]
             );

LargeEnoughTime := 20;  # set LargeEnoughTime to a value larger than the one returned by the warning message
sol1(LargeEnoughTime): 

EndTime := op(sol1(eventfired=[1]));
sol1(EndTime);


EndTime := 7.84831340510192

 

First 124 125 126 127 128 129 130 Last Page 126 of 154