tomleslie

5348 Reputation

15 Badges

9 years, 292 days

MaplePrimes Activity


These are answers submitted by tomleslie

You could just provide all the condtions where a '1' is required as part of an 'or' statement - otherwise '0'

As in the attached

  restart;
  with(LinearAlgebra[Modular]):
  A := Mod( 2,
            Matrix( 3,
                    6,
                    (i,j)-> if   `or`( i<2 and j<3,
                                       i=2 and j>2 and j<5,
                                       i=3
                                     )
                            then 1
                            else 0
                            end if
                  ),
            float[8]
          );

Matrix(3, 6, {(1, 1) = 1.0, (1, 2) = 1.0, (1, 3) = 0., (1, 4) = 0., (1, 5) = 0., (1, 6) = 0., (2, 1) = 0., (2, 2) = 0., (2, 3) = 1.0, (2, 4) = 1.0, (2, 5) = 0., (2, 6) = 0., (3, 1) = 1.0, (3, 2) = 1.0, (3, 3) = 1.0, (3, 4) = 1.0, (3, 5) = 1.0, (3, 6) = 1.0})

(1)

 

Download initMat.mw

 

  1. If I download and re-execute your worksheet (using !!!) I see the same effect
  2. It persists on multiple re-executions (using !!!)
  3. However, if I remove output using Evaluate->Remove Output from Worksheet, then re-execute, plot labels become consistent and correct, and stay this way on multiple re-executions (without ever using Evaluate->Remove Output from Worksheet again)
  4. So having used Evaluate->Remove Output from Worksheet once, the problem "goes away" and stays gone
  5. That's pretty weird

For Digits=15, every version of Maple I can check gives the same answer, ie 0.167084168057542.

This begs the obvious questions; which version of Maple were you using, and exactly what was the code? - Please upload the offending worksheet using the big green up-arrow in the Mapleprimes toolbar

Check the attachements below for identical code in

Maple 18
Maple 2015
Maple 2016
Maple 2017
Maple 2018
Maple 2019

restart;

kernelopts(version);
Digits:=15:
phi:=(j,x)->piecewise(j=0,exp(x),1/(j-1)!*Integrate(exp((1-theta)*x)*theta^(j-1),theta=0..1)):
evalf(phi(3,0.01));

`Maple 18.02, X86 64 WINDOWS, Oct 20 2014, Build ID 991181`

 

.167084168057542

(1)

 

Download num18.mw

restart:

kernelopts(version);
Digits:=15:
phi:=(j,x)->piecewise(j=0,exp(x),1/(j-1)!*Integrate(exp((1-theta)*x)*theta^(j-1),theta=0..1)):
evalf(phi(3,0.01));

`Maple 2015.2, X86 64 WINDOWS, Dec 20 2015, Build ID 1097895`

 

.167084168057542

(1)

 

Download num2015.mw

restart;

kernelopts(version);
Digits:=15:
phi:=(j,x)->piecewise(j=0,exp(x),1/(j-1)!*Integrate(exp((1-theta)*x)*theta^(j-1),theta=0..1)):
evalf(phi(3,0.01));

`Maple 2016.2, X86 64 WINDOWS, Jan 13 2017, Build ID 1194701`

 

.167084168057542

(1)

 

Download num2016.mw

restart;

kernelopts(version);
Digits:=15:
phi:=(j,x)->piecewise(j=0,exp(x),1/(j-1)!*Integrate(exp((1-theta)*x)*theta^(j-1),theta=0..1)):
evalf(phi(3,0.01));

`Maple 2017.3, X86 64 WINDOWS, Sep 13 2017, Build ID 1262472`

 

.167084168057542

(1)

 

Download num2017.mw

restart;

kernelopts(version);
Digits:=15:
phi:=(j,x)->piecewise(j=0,exp(x),1/(j-1)!*Integrate(exp((1-theta)*x)*theta^(j-1),theta=0..1)):
evalf(phi(3,0.01));

`Maple 2018.2, X86 64 WINDOWS, Nov 16 2018, Build ID 1362973`

 

.167084168057542

(1)

 

Download num2018.mw

restart;

kernelopts(version);
Digits:=15:
phi:=(j,x)->piecewise(j=0,exp(x),1/(j-1)!*Integrate(exp((1-theta)*x)*theta^(j-1),theta=0..1)):
evalf(phi(3,0.01));

`Maple 18.02, X86 64 WINDOWS, Oct 20 2014, Build ID 991181`

 

.167084168057542

(1)

 

Download num2019.mw

you were trying to achieve something like the attached

  restart;

  eulerexp:= proc( fin::procedure, condin::Vector, h::rational, tmax::integer )
                   local n, j,
                         N:= tmax/h,
                         tab:= Matrix(N, 5);
                   tab[1,..]:= condin;
                   for n from 2 to N do
                       tab[n,..]:=tab[n-1, ..]+h*fin( tab[n-1,..] );
                   od;
                   return tab
             end proc:
  fin:= proc( v::Vector )
            return Vector[row]
                   ( eval
                     ( [ 1, 2*t-4*w+5*x-6*y-z, x, z, t ],
                       [ t=v[1], w=v[2], x=v[3], y=v[4], z=v[5] ]
                     )
                   )
        end proc:
  condin:= <25, 1, 2, 3, 4>:
  h:= 1/10:
  tmax:= 20:
  ans:= eulerexp(fin, condin, h, tmax);

_rtable[18446744074327425142]

(1)

 

 

Download eexp.mw

After making a few syntactic corrections, I managed to persuade fsolve() to come up with nine solutions. (Had no luck with solve() at all - expressions to be solved have *ridiculous" powers in 'a, and 'b' - up to 50 - so I would suggest that symbolic solution is impossible

A warning - the attached runs for about 10minutes on my machine. The time-consuming part is actually settinging up the system, I think as a result of "expression length explosion". The loop containing fsolve() solutions is *reasonably* quick - and could probably be improved if there were any doman restriction on the quantitis 'a' and 'b'

If one looks for more than 10 solutions by changing the value of 'numSols' in the final execution group, then the fsolve() command generates an error. This *looks* like a limit on the number of entries in the set provided to the 'avoid' option, but I can't be sure.

Anyhow for what it is worth check the attached

restart;
n:=11:
M := 2:
Le := 5:
Lb := 2:
L:= 1:
l := 1/2:
Pr := 1:
Pe := 2:
Nt := 1/2:
Nb := 4/5:
F[0]:=0:
F[1]:=l*F[2]:
F[2]:=a:
T[0]:=1:
T[1]:=b:
d:=k->piecewise(k<>0,0,k=0,1):

for k from 0 to n do
    F[k+3]:=-1/(d(k)+(k+1)*(k+2)*F[k+2])*((add(F[k-m]*(m+1)*(m+2)*F[m+2],m=0..k))-(add((k-m+1)*(m+1)*F[k-m+1]*F[m+1],m=0..k))-M*(k+1)*F[k+1])*(factorial(k)/factorial(k+3));
    T[k+2]:=-1*(Pr/(k+1)*(k+2))*((add(F[k-m]*(m+1)*T[m+1],m=0..k))+Nt*(add((k-m+1)*(m+1)*T[k-m+1]*T[m+1],m=0..k))+Nb*(add((k-m+1)*(m+1)*T[k+1]*F[k-m+1],m=0..k)));
 end do:

with(numapprox):
f:=add(F[k]*y^k,k=0..n):
t:=add(T[k]*y^k,k=0..n):
ans:= {{}}:
eqsys:= { limit(pade(diff(f,y),y,[4,4]),y=infinity)=0.,
          limit(pade(t,y,[4,4]),y=infinity)=0.
        }:
#
# NB if numSols is set to 10 or higher, then
# fsolve() will generate an error - seems as
# if one can only "avoid" 10 solutions.
#
# Not sure why!!???
#
numSols:=8:
for i from 1 to numSols do
    sol:= fsolve( eqsys,
                  {a,b},
                  avoid = ans
               );
    ans:= `union`(ans,{sol});
od:
ans;

{{}, {a = -7.075494500, b = .3913361429}, {a = -1.134605000, b = 0.6719248299e-1}, {a = -.3028650866, b = -5.211998208}, {a = -.1827451829, b = -2.346056057}, {a = 0., b = -.2439671224}, {a = .9034417844, b = -1.486927916}, {a = 1.561732683, b = -2.156823308}, {a = 4.604997091, b = -3.085073661}}

(1)

 

Download solveSys.mw

 

  restart;
  L:= [0,3,0,7]:
  x:=[seq(`if`(L[i]>0, L[i]/2, NULL), i =1..numelems(L))];

 

The correct syntax for the command you are trying to implement is

dsolve({dl2,bbet}, f(t), numeric, output=Array([0,100, 200, 300, 400, 500, 600]))

although I doubt

  1. whether this is your only problem
  2. or is even the correct set of options for your purpose

From the error messages you are getting, I suspect that you have an undefined parameter either in the ODEs or BCs - obviously since you refuse to use the big green up-arrow in the Mapleprimes toolbar to upload your worksheet , I cannot check/correct this

Using the 'output=Array()' option will return an array of values for all dependent variables, at the values of the independent variable which you supply - ie at the points 0,100, 200, 300, 400, 500, 600. You cannot use the odeplot() command to plot these points.

I suspect that you just want a solution which can be continuously plotted in the range t=0..600 - in which case you don't want the 'output=Array()'.

Once again, if you could be bothered to use the big green up-arrow in the Mapleprimes toolbar to upload your worksheet, I could demonstrate how this is done.

But if you are determined to make life difficult for yourself..........

See my annotations of your "code" below. NB this is probably a non-exhaustive list, just the  glaringly obvious stupidities

restart;
restart; Digits := 1;

 Why do you restart twice?

You really want to work to a precision of one Digit?

Pr:=0.01:E:=1:a:=0:N:=10:

`&Delta;t`:=0.01:`&Delta;y`:=0.01:

#Discritization scheme

for i from 1 by 1 while i<=N do;  
end:

Above for loop 'ends' without doing anything

for j from 0 by 1 while j<=N do;
end:

Above for loop 'ends' without doing anything

eq1[i, j] := (U[i, j+1]-U[i, j])/`&Delta;t` = (1/2)*Gr*(theta[i, j+1]+theta[i, j])+(1/2)*Gc*(C[i, j+1]+C[i, j])+(U[i-1, j+1]-2.*U[i, j+1]-2.*U[i, j]+U[i+1, j])/(2.*`&Delta;y`)^2-(1/2)*M*(U[i, j+1]+U[i, j]):

eq2[i, j] := (theta[i, j+1]-theta[i, j])/`&Delta;t` = (1/Pr)*(theta[i-1, j+1]-2*theta[i, j+1]+theta[i+1, j+1]+theta[i-1, j]-2*theta[i,j]+theta[i+1,j])/(2.*`&Delta;y`)^2-E*((1/`&Delta;y`)^2*(U[i+1, j]-U[i, j])^2):

eq3[i, j] := (C[i, j+1]-C[i, j])/`&Delta;t` = (1/Sc)*(C[i-1, j+1]-2*C[i, j+1]+C[i+1, j+1]+C[i-1, j]-2*C[i,j]+C[i+1,j])/(2*`&Delta;y`)^2-(K/2)*(C[i, j+1]-C[i, j]):

eq1[], eq2[] and eq3[] will be evaluated once using the exit values from the earlier 'for' loops, which did nothing. Luckily none of eq1[], eq[2] and eq[3] are used for anything subsequently, so I suppose their (incorrect?) definition is irrelevant

end do;

Nothing to end - for loops all ended earlier

Error, reserved word `end` unexpected
end do:

Nothing to end - for loops all ended earlier

Error, reserved word `end` unexpected

# initial conditions
U[i, 0] := 0:
theta[i, 0]:= 0:
C[i, 0] := 0:

 In the above, three statements what do think the value of 'i' actually is?

NULL;

Well there's a statement which really does nothing!

U[0,j]:=exp(a*j*`&Delta;t`):
theta[0,j]:=(j*`&Delta;t`):
C[0,j]:=j*`&Delta;t`:

 In the above, three statements what do think the value of 'j' actually is?

U[N,j]:=0:
theta[N,j]:=0:
C[N,j]:=0:

sys := ([seq])(seq(eq[i, j], j = 0 .. N), i = 1 .. N):
nops(sys);
vars:=indets(sys):
nn := Matrix(N+1, N+1,(i, j)-> U[i-1, j-1]):
##
p:=proc(kk) local U_res,A;
  U_res:=solve(eval(sys,k=kk),vars);
  A:=eval(nn,U_res);
  plots:-matrixplot(A)
end proc;

The procedure 'p()' is defined, but is never called - so why does it exist?

plots:-(U,[M],Y=0..4);

Were you planning on using any specific command from the plots() package?

 

Your PDe is seconfd order in 'x' and first order in 't' - therefore you need three boundary conditions in order to obtain a complete solution.

If I "manufacture" a third boundary condition and set infinity to be something "large" but finite, then I can obtain the rather boring solution in the attached numerically

restart;
Inf:=100;
pde1:=diff(v(x,t),x,x)-diff(v(x,t),t)-v(x,t)-v(x,t)^2/(2*v(x,t)+0.5)=0;
bc1:=v(x,0)=0, v(0,t)=1, v(Inf,t)=0;
sol:=pdsolve( pde1, [bc1], numeric);
sol:-plot3d(v(x,t), x=0..Inf, t=0..10);

100

 

diff(diff(v(x, t), x), x)-(diff(v(x, t), t))-v(x, t)-v(x, t)^2/(2*v(x, t)+.5) = 0

 

v(x, 0) = 0, v(0, t) = 1, v(100, t) = 0

 

_m710005568

 

 

 

Download pdeProb.mw

 

on which to animate - so in the attached I just (arbitrarily) incorporated a multiolier on the y2 term of your function

  restart;
  with(plots):
  u:= (x, y) -> x^2+a*y^2+3;
  animate( gradplot,
           [ u(x, y),
             x = -10..10,
             y = -2 .. 2,
             grid = [8, 8],
             thickness = 3,
             arrows = SLIM
           ],
           a = 1..10
         );

proc (x, y) options operator, arrow; x^2+a*y^2+3 end proc

 

 

 

Download anim.mw

as in the attached

restart

PDE := diff(u(x, y), x)+u(x, y)*(diff(u(x, y), y)) = (1/2)*u(x, y);

diff(u(x, y), x)+u(x, y)*(diff(u(x, y), y)) = (1/2)*u(x, y)

(1)

Bc := u(x, 0) = x^2;

u(x, 0) = x^2

(2)

sol := pdsolve([PDE, Bc]);

"sol:="

(3)

if sol = NULL then printf("\t\t\t****  Didn't get an answer   ***\n") else printf("\t\t\t****  Got an answer   ***\n") end if;

                        ****  Didn't get an answer   ***

 

NULL

 

Download pdsol.mw

or is the attached the simple way to generate the solution (actually both of them)?

  restart:
  h:=unapply( [solve(y=(a+b*z+c*z^2)/(d+e*z+f*z^2), z)], y);
  g:=z->(a+b*z+c*z^2)/(d+e*z+f*z^2):
  simplify(g~(h(y)));

proc (y) options operator, arrow; [(1/2)*(e*y-b+(-4*d*f*y^2+e^2*y^2+4*a*f*y-2*b*e*y+4*c*d*y-4*a*c+b^2)^(1/2))/(-f*y+c), -(1/2)*(-e*y+(-4*d*f*y^2+e^2*y^2+4*a*f*y-2*b*e*y+4*c*d*y-4*a*c+b^2)^(1/2)+b)/(-f*y+c)] end proc

 

[y, y]

(1)

 

Download simp.mw

 

is to use listplot, as in the attached

S:=seq(j^2, j=-5..5):#testdata
plots:-listplot([S]);

 

 

 

 

 


 

Download lplt.mw

which Maple version are you using?

Maple 2019 provides an answer - see the attached
 

NULL

restart; kernelopts(version)

`Maple 2019.2, X86 64 WINDOWS, Oct 30 2019, Build ID 1430966`

(1)

PDE := diff(u(x, y), x)+u(x, y)*(diff(u(x, y), y)) = (1/2)*u(x, y)

diff(u(x, y), x)+u(x, y)*(diff(u(x, y), y)) = (1/2)*u(x, y)

(2)

Bc := u(s, s^2) = 2*s

u(s, s^2) = 2*s

(3)

pdsolve([PDE, Bc])

u(x, y) = -2*RootOf(4*exp(-(1/2)*x)*_Z^2-8*exp(_Z)*_Z+8*_Z*exp(-(1/2)*x)-exp(-(1/2)*x)*y)^2-4*RootOf(4*exp(-(1/2)*x)*_Z^2-8*exp(_Z)*_Z+8*_Z*exp(-(1/2)*x)-exp(-(1/2)*x)*y)+(1/2)*y

(4)

``


 

Download pdeSol2.mw

is shown in the attached

A:=Matrix(2, 2, [[-0.0001633261895*z[1, 2]^2 + 0.0002805135275*z[1, 2]*z[2, 2] - 0.0001200583046*z[2, 2]^2 + 0.0006934805795*z[1, 1]^2 - 0.001190280265*z[1, 1]*z[2, 1] + 0.00007689977894*z[1, 1]*z[1, 2] - 0.00009937418547*z[1, 1]*z[2, 2] + 0.0005090615773*z[2, 1]^2 - 0.00003303758400*z[2, 1]*z[1, 2] + 0.00005683264925*z[2, 1]*z[2, 2] + 0.7021232886*z[1, 1] - 0.3171553245*z[1, 2] - 0.08291569324*z[2, 1] + 0.04647270631*z[2, 2] - 0.1436869545, 0.0002939068385*z[2, 1]^2 + 0.4237544799*z[1, 1] - 0.03129537402*z[1, 2] - 0.06276282411*z[2, 1] + 0.02529757039*z[2, 2] + 0.0004003811990*z[1, 1]^2 + 0.0002177682527*z[1, 1]*z[1, 2] - 0.0006872086309*z[1, 1]*z[2, 1] - 0.0001976167183*z[1, 1]*z[2, 2] - 0.0001764013184*z[2, 1]*z[1, 2] + 0.0001600777394*z[2, 1]*z[2, 2] - 0.1237363898], [0.00006763201108*z[2, 1]*z[1, 2] - 0.0001020812322*z[1, 2]*z[2, 2] - 0.00001554113990*z[2, 1]*z[2, 2] - 0.00003577693711*z[1, 1]*z[1, 2] + 0.0004330743651*z[1, 1]*z[2, 1] - 0.00001941220415*z[1, 1]*z[2, 2] - 0.01736180925 + 0.5623450996*z[2, 1] - 0.2353707048*z[2, 2] - 0.0003226356619*z[1, 1]^2 + 0.00007598605473*z[1, 2]^2 - 0.0001392051452*z[2, 1]^2 + 0.00003283047567*z[2, 2]^2 + 0.04653058230*z[1, 1] - 0.03026711709*z[1, 2], -0.00008037012799*z[2, 1]^2 + 0.03994641178*z[1, 1] - 0.02291248064*z[1, 2] + 0.3140461555*z[2, 1] + 0.01853659924*z[2, 2] - 0.0001862737861*z[1, 1]^2 - 0.0001013147396*z[1, 1]*z[1, 2] + 0.0002500356011*z[1, 1]*z[2, 1] + 0.00005403916772*z[1, 1]*z[2, 2] + 0.00008206914192*z[2, 1]*z[1, 2] - 0.00004377396755*z[2, 1]*z[2, 2] - 0.01370765196]]):

#
# Obtain a solution
#
  sol1:=fsolve([entries(A, 'nolist')]);
#
# Obtain a solution and insert into matrix
# in the required order
#
  Z:=Matrix(2,2,(i,j)->eval(z[i,j], sol1 ));

sol1 := {z[1, 1] = .3117132485, z[1, 2] = .2328518749, z[2, 1] = 0.2064174947e-1, z[2, 2] = 0.7118281938e-2}

 

Matrix(%id = 18446744074441697150)

(1)

 

Download matSol.mw

1 2 3 4 5 6 7 Last Page 1 of 119