Carl Love

Carl Love

28055 Reputation

25 Badges

12 years, 356 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

It's as easy as

plot(A[.., [1,3]]);

The .. means "all rows".

The help page ?dsolve,numeric,bvp just says that the midpoint methods can help with "harmless endpoint singularities". Here's an an example: y'' = sin(x)/x on 0..1. The derivative expression cannot be properly evaluated at the left endpoint because of the division by zero, but we know that this singularity is removable because limit(sin(x)/x, x= 0) = 1. Since the midpoint methods evaluate the derivative expression at the midpoints of the subintervals rather than the endpoints, they will never use x=0 in this problem---0 will never be a midpoint of a subinterval.


restart:

BVP:= {diff(f(x), x$2) = sin(x)/x, f(0)=1, f(1)=1}:

Sol_exact:= rhs(dsolve(BVP));

Si(x)*x+cos(x)+(1-Si(1)-cos(1))*x

plot(Sol_exact, x= 0..1);

Sol_num:= dsolve(BVP, numeric);

Error, (in dsolve/numeric/bvp) system is singular at left endpoint, use midpoint method instead

Sol_num:= dsolve(BVP, numeric, method= bvp[midrich]);

proc (x_bvp) local res, data, solnproc, _ndsol, outpoint, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; _EnvDSNumericSaveDigits := Digits; Digits := 15; if _EnvInFsolve = true then outpoint := evalf[_EnvDSNumericSaveDigits](x_bvp) else outpoint := evalf(x_bvp) end if; data := Array(1..4, {(1) = proc (outpoint) local X, Y, YP, yout, errproc, L, V, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; X := Vector(8, {(1) = .0, (2) = .13989255348898227, (3) = .28097321467475084, (4) = .42369264612713453, (5) = .567766418038716, (6) = .7126271458449935, (7) = .8577435136247847, (8) = 1.0}, datatype = float[8], order = C_order); Y := Matrix(8, 2, {(1, 1) = 1.0, (1, 2) = -.48638541327385726, (2, 1) = .9417379493876471, (2, 2) = -.34664486749193985, (3, 1) = .9027252779317808, (3, 2) = -.20664160699283896, (4, 1) = .8832338357702728, (4, 2) = -0.6689561121524981e-1, (5, 1) = .8835920621231957, (5, 2) = 0.7131076175121163e-1, (6, 1) = .9037615124308206, (6, 2) = .2064399080804538, (7, 1) = .9432597404358745, (7, 2) = .33706326363848954, (8, 1) = 1.0, (8, 2) = .45969763470211805}, datatype = float[8], order = C_order); YP := Matrix(8, 2, {(1, 1) = .0, (1, 2) = .0, (2, 1) = -.34664486749193985, (2, 2) = .9967415356099041, (3, 1) = -.20664160699283896, (3, 2) = .9868941817766961, (4, 1) = -0.6689561121524981e-1, (4, 2) = .9703481603018593, (5, 1) = 0.7131076175121163e-1, (5, 2) = .9471328918014389, (6, 1) = .2064399080804538, (6, 2) = .9174837786498442, (7, 1) = .33706326363848954, (7, 2) = .8818118779194667, (8, 1) = .45969763470211805, (8, 2) = .8414709848078965}, datatype = float[8], order = C_order); errproc := proc (x_bvp) local outpoint, X, Y, yout, L, V, i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; Digits := 15; outpoint := evalf(x_bvp); X := Vector(8, {(1) = .0, (2) = .13989255348898227, (3) = .28097321467475084, (4) = .42369264612713453, (5) = .567766418038716, (6) = .7126271458449935, (7) = .8577435136247847, (8) = 1.0}, datatype = float[8], order = C_order); Y := Matrix(8, 2, {(1, 1) = .0, (1, 2) = 0.370411810516113e-7, (2, 1) = 0.4498878652951399e-8, (2, 2) = 0.40290737929366984e-7, (3, 1) = 0.7575662105969684e-8, (3, 2) = 0.4363302742454424e-7, (4, 1) = 0.9052815055928714e-8, (4, 2) = 0.4707249966490021e-7, (5, 1) = 0.8821086311401802e-8, (5, 2) = 0.505183751217569e-7, (6, 1) = 0.693184493972332e-8, (6, 2) = 0.53841758416381137e-7, (7, 1) = 0.35686669203094067e-8, (7, 2) = 0.569247651683525e-7, (8, 1) = .0, (8, 2) = 0.5943333402100548e-7}, datatype = float[8], order = C_order); if not type(outpoint, 'numeric') then if outpoint = "start" or outpoint = "left" then return X[1] elif outpoint = "right" then return X[8] elif outpoint = "order" then return 4 elif outpoint = "error" then return HFloat(5.943333402100548e-8) elif outpoint = "errorproc" then error "this is already the error procedure" elif outpoint = "rawdata" then return [2, 8, [f(x), diff(f(x), x)], X, Y] else return ('procname')(x_bvp) end if end if; if outpoint < X[1] or X[8] < outpoint then error "solution is only defined in the range %1..%2", X[1], X[8] end if; V := array([1 = 4, 2 = 0]); if Digits <= trunc(evalhf(Digits)) then L := Vector(4, 'datatype' = 'float'[8]); yout := Vector(2, 'datatype' = 'float'[8]); evalhf(`dsolve/numeric/lagrange`(8, 2, X, Y, outpoint, var(yout), var(L), var(V))) else L := Vector(4, 'datatype' = 'sfloat'); yout := Vector(2, 'datatype' = 'sfloat'); `dsolve/numeric/lagrange`(8, 2, X, Y, outpoint, yout, L, V) end if; [x = outpoint, seq('[f(x), diff(f(x), x)]'[i] = yout[i], i = 1 .. 2)] end proc; if not type(outpoint, 'numeric') then if outpoint = "start" or outpoint = "left" then return X[1] elif outpoint = "method" then return "bvp" elif outpoint = "right" then return X[8] elif outpoint = "order" then return 4 elif outpoint = "error" then return HFloat(5.943333402100548e-8) elif outpoint = "errorproc" then return eval(errproc) elif outpoint = "rawdata" then return [2, 8, "depnames", X, Y, YP] else error "non-numeric value" end if end if; if outpoint < X[1] or X[8] < outpoint then error "solution is only defined in the range %1..%2", X[1], X[8] end if; if Digits <= trunc(evalhf(Digits)) and (_EnvInFsolve <> true or _EnvDSNumericSaveDigits <= trunc(evalhf(Digits))) then V := array( 1 .. 6, [( 1 ) = (7), ( 2 ) = (0), ( 3 ) = (false), ( 4 ) = (false), ( 5 ) = (true), ( 6 ) = (false)  ] ); L := Matrix(7, 2, {(1, 1) = .0, (1, 2) = .0, (2, 1) = .0, (2, 2) = .0, (3, 1) = .0, (3, 2) = .0, (4, 1) = .0, (4, 2) = .0, (5, 1) = .0, (5, 2) = .0, (6, 1) = .0, (6, 2) = .0, (7, 1) = .0, (7, 2) = .0}, datatype = float[8], order = C_order); yout := Vector(2, {(1) = .0, (2) = .0}, datatype = float[8]); evalhf(`dsolve/numeric/hermite`(8, 2, X, Y, YP, outpoint, var(yout), var(L), var(V))) else if _EnvInFsolve = true then Digits := _EnvDSNumericSaveDigits end if; V := array( 1 .. 6, [( 1 ) = (7), ( 2 ) = (0), ( 3 ) = (false), ( 4 ) = (false), ( 5 ) = (true), ( 6 ) = (false)  ] ); L := Matrix(7, 2, {(1, 1) = 0., (1, 2) = 0., (2, 1) = 0., (2, 2) = 0., (3, 1) = 0., (3, 2) = 0., (4, 1) = 0., (4, 2) = 0., (5, 1) = 0., (5, 2) = 0., (6, 1) = 0., (6, 2) = 0., (7, 1) = 0., (7, 2) = 0.}, order = C_order); yout := Vector(2, {(1) = 0., (2) = 0.}); `dsolve/numeric/hermite`(8, 2, X, Y, YP, outpoint, yout, L, V) end if; [outpoint, seq(yout[i], i = 1 .. 2)] end proc, (2) = Array(0..0, {}), (3) = [x, f(x), diff(f(x), x)], (4) = 0}); solnproc := data[1]; if not type(outpoint, 'numeric') then if outpoint = "solnprocedure" then return eval(solnproc) elif member(outpoint, ["start", "left", "right", "errorproc", "rawdata", "order", "error"]) then return solnproc(x_bvp) elif outpoint = "sysvars" then return data[3] elif procname <> unknown then return ('procname')(x_bvp) else _ndsol := pointto(data[2][0]); return ('_ndsol')(x_bvp) end if end if; try res := solnproc(outpoint); [x = res[1], seq('[f(x), diff(f(x), x)]'[i] = res[i+1], i = 1 .. 2)] catch: error  end try end proc

plots:-odeplot(Sol_num);

 


Download midrich.mw

That's right: You cannot integrate numerically when the integral has a parameter, the kk in your case. The integral will be done if you specify a value for kk. Considering the complexity and non-smoothness of the integrand, you need to increase your error tolerance from the default in order to get an answer in reasonable time. This is done with the epsilon option.

JJJ:= Int(max(0., (0.9483573506e-3*(-1.*sin(a)*cos(w)-1.*cos(a)*sin(w)*sin(b)))*cos(a)*cos(b)^2*(-58.5*signum(cos(b)*sin(w)*sin(b))*kk+200.*cos(b)*sin(w)*sin(b))*Heaviside(-58.5+200.*cos(b)*sin(w)*sin(b)*signum(cos(b)*sin(w)*sin(b))*kk)*Heaviside(1.-.98*cos(b)^2)/sqrt(1.-.98*cos(b)^2)) +
min(0., (0.9483573506e-3*(-1.*sin(a)*cos(w)-1.*cos(a)*sin(w)*sin(b)))*cos(a)*cos(b)^2*(-58.5*signum(cos(b)*sin(w)*sin(b))*kk+200.*cos(b)*sin(w)*sin(b))*Heaviside(-58.5+200.*cos(b)*sin(w)*sin(b)*signum(cos(b)*sin(w)*sin(b))*kk)*Heaviside(1.-.98*cos(b)^2)/sqrt(1.-.98*cos(b)^2)), [a= 0..2*Pi, b= 0..Pi/2, w= 0..2*Pi], epsilon= 1e-4, method= _cuhre):

evalf(eval(JJJ, kk=1));

This answer should only be trusted to 4 significant digits.

Using unprotect let's you assign to D; it doesn't change or remove the value that D already has. To do that, you need unassign in addition to unprotect:

save_D:= eval(D):  #Just in case you need it later.
unprotect(D):
unassign('D'):

However, if you have Maple 17, it would be better to use the local option (although not as described by Georgios):

local D;  Lett:= D;

This leaves the original D accessible as :-D.

Here is your program translated into modern Maple.


restart:

macro(LA= LinearAlgebra):
L:= 1:  r:= 20:  tau:= 0.3:
interface(rtablesize= 2*r+1):

#definition of exact solution

T1:= piecewise(
     t < 0,   0,
     t < 0.3, 1+t^2,
     t < 0.6, 691/1000+109/100*t+7/10*t^2+t^3/3,
     t < 0.9, 4409/5000+209/500*t+69/50*t^2+2/15*t^3+t^4/12,
     t < 1,   1500917/2000000+35107/40000*t+1617/2000*t^2+87/200*t^3+t^4/120+t^5/60
):

plot(T1, t= 0..1, numpoints= 10000, discont);

g:= t^2:

a0:= evalf(Int(g, t= 0..L)/L):

a:= seq(evalf(2/L*Int(g*cos(2*i1*Pi*t/L), t= 0..L)), i1= 1..r):

b:= seq(evalf(2/L*Int(g*sin(2*j1*Pi*t/L), t= 0..L)), j1= 1..r):


X00:= < a0, a, b >^%T:

 

Z:= Matrix(
     2*r+1, 2*r+1,
     [tau,

      seq(evalf((L/(2*(iz-1)*Pi))*sin(2*(iz-1)*Pi*tau/L)), iz= 2..r+1),

      seq(evalf((L/(2*(iz-1-r)*Pi))*(1-cos(2*(iz-1-r)*Pi*tau/L))), iz= r+2..2*r+1)
      ],
     scan= columns,
     datatype= float[8]
):

 

Dtau00:= < 1 >:

Dtau01:= Vector[row](r):

Dtau02:= Vector[row](r):

Dtau10:= Vector(r):

Dtau20:= Vector(r):


Dtau1:= LA:-DiagonalMatrix([seq(evalf(cos(2*i*Pi*tau/L)), i= 1..r)]):
Dtau2:= LA:-DiagonalMatrix([seq(evalf(sin(2*i*Pi*tau/L)), i= 1..r)]):
Dtau3:= -Dtau2:

Dtau4:= copy(Dtau1):

Dtau:= < < Dtau00 | Dtau01 | Dtau02 >,
         < Dtau10 | Dtau1  | Dtau2  >,
         < Dtau20 | Dtau3  | Dtau4  > >:

 

P00:= < L/2 >:

P01:= Vector[row](r):

P02:= Vector[row](r, j-> evalf(-L/j/Pi), datatype= float[8]):

P10:= Vector(r):

P20:= Vector(r, i-> evalf(L/2/i/Pi)):
P1:= Matrix(r,r):
P2:= LA:-DiagonalMatrix(P20):
P3:= LA:-DiagonalMatrix(-P20):

P4:= Matrix(r,r):

P:= < < P00 | P01 | P02 >,
      < P10 | P1  | P2  >,
      < P20 | P3  | P4  > >:

I1:= Matrix(2*r+1, shape= identity):

K1:= I1 - Dtau.(P+Z):

K2:= K1^(-1):

X0:= Vector[row](2*r+1,[1]):

X:= (X0+X00).K2:

 

f1:= h-> cos(2*h*Pi*t/L):

f2:= k-> sin(2*k*Pi*t/L):

 

XP:= X[1]+add(X[l+1]*f1(l)+X[r+l+1]*f2(l), l= 1..r):

plot([XP,T1], t= 0..1, discont, legend= ['XP', 'T1']);

 


Download Matrix_Calculation.mw

The obvious works:

eqn:= diff(x(t), t) = 0:
subs(diff(x(t), t)= v(t), eqn)
;

Your fprintf statement has four %gs, but you only have three numeric values (three evalfs).

ex:= x/2+y/2:
content(ex)*``(primpart(ex));

To extract the leading square submatrix of order M, use A[1..M, 1..M].

Any of the following:

subsindets(y=a+b, atomic, f);
subsindets(y=a+b, name, f);
evalindets(y=a+b, atomic, f);
evalindets(y=a+b, name, f);

See command ?fnormal .

See ?numapprox,minimax .

If you don't mind extra parentheses in the display, you can do this

``(3) + ``(7) + ``(1);

If you want it without the parentheses, then it is significantly more complicated, but it can be done with the Typesetting package.

Your equation is fifth order in alpha. There is provably no possible general solution for fifth-order and higher-order polynomials. Since you have parameters, there is no numerical solution either.

When Maple makes up a variable name, it begins that name with a underscore to help distinguish it from user-supplied names. _Z takes the place of the solved-for variable in a RootOf expression. That is, _Z takes the place of alpha. A RootOf is Maple's placeholder for the root of an equation that Maple in unable to solve.

First, you need to change your syntax. To apply sqrt to two arguments, the closest syntax to what you had is

sqrt~([c^2, r^2]);

The reason that Maple does not simplify these square roots is that it does not know the sign of c and or even that they are real. You can supply this information with an assuming clause:

sqrt~([c^2, r^2]) assuming c > 0, r > 0;

or

sqrt~([c^2, r^2]) assuming positive;

There is also a symbolic argument that can be give to sqrt:

sqrt~([c^2,r^2], symbolic);

First 324 325 326 327 328 329 330 Last Page 326 of 395