Carl Love

Carl Love

28020 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

To get exact solutions, simply use solve instead of fsolve.

To extract the exact positive solutions, do

Sol:= [solve(30+1144*r^4-832*r^2=0)];
select(x-> is(x>0), Sol);

Your solution does not fulfill the exercise because your integral is being done symbolically, not numerically. It's rather tricky to get Maple's numeric differential equation solver (dsolve(..., numeric)) to use a numeric integral. You have to encapsulate the integral in a procedure and then use dsolve's rather arcane protocol for specifying an IVP via a procedure. I wouldn't expect any beginning Maple user to figure it out. So, here's how to do it.

 

MakeDeq:= (f,init)->
     proc(N, t, Y, YP)
          local x;
          YP[1]:= evalf(Int(f, 0..t))
     end proc
:

T:= 10:  numsteps:= 100:  f:= x-> exp(-x^2):  #or f:= x-> x

Sol:= dsolve(
     numeric,
     procedure= MakeDeq(f),
     number= 1,
     start= 0,
     initial= Array(1..1, [0]),
     procvars= [y(t)],
     method= classical[foreuler],
     stepsize= T/numsteps
);

proc (x_classical) local _res, _dat, _vars, _solnproc, _xout, _ndsol, _pars, _n, _i; option `Copyright (c) 2000 by Waterloo Maple Inc. All rights reserved.`; if 1 < nargs then error "invalid input: too many arguments" end if; _EnvDSNumericSaveDigits := Digits; Digits := 15; if _EnvInFsolve = true then _xout := evalf[_EnvDSNumericSaveDigits](x_classical) else _xout := evalf(x_classical) end if; _dat := Array(1..4, {(1) = proc (_xin) local _xout, _n, _y0, _yn, _yl, _ctl, _octl, _reinit, _errcd, _fcn, _i, _yini, _pars, _ini, _par; option `Copyright (c) 2002 by the University of Waterloo. All rights reserved.`; table( [( "complex" ) = false ] ) _xout := _xin; _ctl := Array(1..9, {(1) = 1, (2) = 0., (3) = 0., (4) = .100000000000000, (5) = 50000, (6) = 0, (7) = 0, (8) = 1, (9) = 0}); _octl := Array(1..9, {(1) = 1, (2) = 0., (3) = 0., (4) = .100000000000000, (5) = 50000, (6) = 0, (7) = 0, (8) = 1, (9) = 0}); _n := trunc(_ctl[1]); _yini := Array(0..1, {(1) = 0.}); _y0 := Array(0..1, {(1) = 0.}); _yl := Array(1..1, {(1) = 0}); _yn := Array(1..1, {(1) = 0}); _fcn := proc (N, t, Y, YP) local x; YP[1] := evalf(Int(f, 0 .. t)) end proc; _pars := []; if not type(_xout, 'numeric') then if member(_xout, ["start", "left", "right"]) then return _y0[0] elif _xout = "method" then return "classical" elif _xout = "numfun" then return round(_ctl[6]) elif _xout = "initial" then return [seq(_yini[_i], _i = 0 .. _n)] elif _xout = "parameters" then return [seq(_yini[_n+_i], _i = 1 .. nops(_pars))] elif _xout = "initial_and_parameters" then return [seq(_yini[_i], _i = 0 .. _n)], [seq(_yini[_n+_i], _i = 1 .. nops(_pars))] elif _xout = "last" then if _ctl[3]-_y0[0] <> 0. then _xout := _ctl[3] elif _ctl[2]-_y0[0] <> 0. then _xout := _ctl[2] else error "no information is available on last computed point" end if elif _xout = "enginedata" then return eval(_octl, 1) elif _xout = "function" then return eval(_fcn, 1) elif type(_xin, `=`) and type(rhs(_xin), 'list') and member(lhs(_xin), {"initial", "parameters", "initial_and_parameters"}) then if sing_bool then error "initial conditions cannot be changed for systems with removable singularities" end if; _ini, _par := [], []; if lhs(_xin) = "initial" then _ini := rhs(_xin) elif lhs(_xin) = "parameters" then _par := rhs(_xin) elif select(type, rhs(_xin), `=`) <> [] then _par, _ini := selectremove(type, rhs(_xin), `=`) elif nops(rhs(_xin)) < nops(_pars)+1 then error "insufficient data for specification of initial and parameters" else _par := rhs(_xin)[-nops(_pars) .. -1]; _ini := rhs(_xin)[1 .. -nops(_pars)-1] end if; _xout := lhs(_xout); if _par <> [] then `dsolve/numeric/process_parameters`(_n, _pars, _par, _yini) end if; if _ini <> [] then `dsolve/numeric/process_initial`(_n, _ini, _yini, _pars) end if; if _pars <> [] then _par := {seq(rhs(_pars[_i]) = _yini[_n+_i], _i = 1 .. nops(_pars))}; for _i from 0 to _n do _y0[_i] := subs(_par, _yini[_i]) end do; for _i from _n+1 to _n+nops(_pars) do _y0[_i] := _yini[_i] end do; for _i to nops(_pars) do _yn[_n+_i] := _y0[_n+_i] end do else for _i from 0 to _n do _y0[_i] := _yini[_i] end do end if; _octl[2] := _y0[0]; _octl[3] := _y0[0]; for _i to 9 do _ctl[_i] := _octl[_i] end do; for _i to _n+nops(_pars) do _yl[_i] := _y0[_i] end do; if _Env_smart_dsolve_numeric = true and type(_y0[0], 'numeric') then procname("right") := _y0[0]; procname("left") := _y0[0] end if; if _xout = "initial" then return [seq(_yini[_i], _i = 0 .. _n)] elif _xout = "parameters" then return [seq(_yini[_n+_i], _i = 1 .. nops(_pars))] else return [seq(_yini[_i], _i = 0 .. _n), op(_pars)], [seq(_yini[_n+_i], _i = 1 .. nops(_pars))] end if else return "procname" end if end if; if _xout-_y0[0] = 0. then return [seq(_y0[_i], _i = 0 .. _n)] end if; _reinit := false; if _xin <> "last" then if 0 < 0 and `dsolve/numeric/checkglobals`(0, table( [ ] ), _pars, _n, _yini) then _reinit := true; if _pars <> [] then _par := {seq(rhs(_pars[_i]) = _yini[_n+_i], _i = 1 .. nops(_pars))}; for _i from 0 to _n do _y0[_i] := subs(_par, _yini[_i]) end do; for _i from _n+1 to _n+nops(_pars) do _y0[_i] := _yini[_i] end do; for _i to nops(_pars) do _yn[_n+_i] := _y0[_n+_i] end do else for _i from 0 to _n do _y0[_i] := _yini[_i] end do end if end if; if _pars <> [] and select(type, {seq(_yini[_n+_i], _i = 1 .. nops(_pars))}, 'undefined') <> {} then error "parameters must be initialized before solution can be computed" end if end if; if not _reinit and _xout-_ctl[3] = 0. then [_ctl[3], seq(_yn[_i], _i = 1 .. _n)] elif not _reinit and _xout-_ctl[2] = 0. then [_ctl[2], seq(_yl[_i], _i = 1 .. _n)] else if _ctl[2]-_y0[0] = 0. or sign(_ctl[2]-_y0[0]) <> sign(_xout-_ctl[2]) or abs(_xout-_y0[0]) < abs(_xout-_ctl[2]) or _reinit then for _i to 9 do _ctl[_i] := _octl[_i] end do; for _i to _n+nops(_pars) do _yl[_i] := _y0[_i] end do; for _i to nops(_pars) do _yn[_n+_i] := _y0[_n+_i] end do end if; _ctl[3] := _xout; if Digits <= evalhf(Digits) then try _errcd := evalhf(`dsolve/numeric/classical`(_fcn, var(_ctl), _y0[0], var(_yl), var(_yn), Array(1..1, {(1) = 0}), Array(1..1, {(1) = 0}), Array(1..1, {(1) = 0}), Array(1..1, {(1) = 0}), var(Array(1..3, 1..1, {(1, 1) = 0, (2, 1) = 0, (3, 1) = 0})))) catch: userinfo(2, `dsolve/debug`, print(`Exception in classical:`, [lastexception])); if searchtext('evalhf', lastexception[2]) <> 0 or searchtext('real', lastexception[2]) <> 0 or searchtext('hardware', lastexception[2]) <> 0 then _errcd := `dsolve/numeric/classical`(_fcn, _ctl, _y0[0], _yl, _yn, Array(1..1, {(1) = 0}), Array(1..1, {(1) = 0}), Array(1..1, {(1) = 0}), Array(1..1, {(1) = 0}), Array(1..3, 1..1, {(1, 1) = 0, (2, 1) = 0, (3, 1) = 0})) else _ctl[3] := _y0[0]; _errcd := [lastexception][2 .. -1] end if end try else try _errcd := `dsolve/numeric/classical`(_fcn, _ctl, _y0[0], _yl, _yn, Array(1..1, {(1) = 0}), Array(1..1, {(1) = 0}), Array(1..1, {(1) = 0}), Array(1..1, {(1) = 0}), Array(1..3, 1..1, {(1, 1) = 0, (2, 1) = 0, (3, 1) = 0})) catch: _ctl[3] := _y0[0]; _errcd := [lastexception][2 .. -1] end try end if; if type(_errcd, 'list') or _errcd < 0 then userinfo(2, {dsolve, `dsolve/classical`}, `Last values returned:`); userinfo(2, {dsolve, `dsolve/classical`}, ` t =`, _ctl[2]); userinfo(2, {dsolve, `dsolve/classical`}, ` y =`, _yl[1]); for _i from 2 to _n do userinfo(2, {dsolve, `dsolve/classical`}, `	 `, _yl[_i]) end do; if type(_errcd, 'list') then error op(_errcd) elif _errcd+1. = 0. then Rounding := `if`(_y0[0] < _xout, -infinity, infinity); error "cannot evaluate the solution past %1, maxfun limit exceeded (see ?dsolve,maxfun for details)", evalf[8](_ctl[3]) else Rounding := `if`(_y0[0] < _xout, -infinity, infinity); error "cannot evaluate the solution past %1, unknown error code returned from classical %2", evalf[8](_ctl[3]), trunc(_errcd) end if end if; if _Env_smart_dsolve_numeric = true then if _y0[0] < _xout and procname("right") < _xout then procname("right") := _xout elif _xout < _y0[0] and _xout < procname("left") then procname("left") := _xout end if end if; [_xout, seq(_yn[_i], _i = 1 .. _n)] end if end proc, (2) = Array(0..0, {}), (3) = [t, y(t)], (4) = []}); _vars := _dat[3]; _pars := map(rhs, _dat[4]); _n := nops(_vars)-1; _solnproc := _dat[1]; if not type(_xout, 'numeric') then if member(x_classical, ["start", 'start', "method", 'method', "left", 'left', "right", 'right', "leftdata", "rightdata", "enginedata", "eventstop", 'eventstop', "eventclear", 'eventclear', "eventstatus", 'eventstatus', "eventcount", 'eventcount', "laxtol", 'laxtol', "numfun", 'numfun', NULL]) then _res := _solnproc(convert(x_classical, 'string')); if 1 < nops([_res]) then return _res elif type(_res, 'array') then return eval(_res, 1) elif _res <> "procname" then return _res end if elif member(x_classical, ["last", 'last', "initial", 'initial', "parameters", 'parameters', "initial_and_parameters", 'initial_and_parameters', NULL]) then _xout := convert(x_classical, 'string'); _res := _solnproc(_xout); if _xout = "parameters" then return [seq(_pars[_i] = _res[_i], _i = 1 .. nops(_pars))] elif _xout = "initial_and_parameters" then return [seq(_vars[_i+1] = [_res][1][_i+1], _i = 0 .. _n), seq(_pars[_i] = [_res][2][_i], _i = 1 .. nops(_pars))] else return [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] end if elif type(_xout, `=`) and member(lhs(_xout), ["initial", 'initial', "parameters", 'parameters', "initial_and_parameters", 'initial_and_parameters', NULL]) then _xout := convert(lhs(x_classical), 'string') = rhs(x_classical); if type(rhs(_xout), 'list') then _res := _solnproc(_xout) else error "initial and/or parameter values must be specified in a list" end if; if lhs(_xout) = "initial" then return [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] elif lhs(_xout) = "parameters" then return [seq(_pars[_i] = _res[_i], _i = 1 .. nops(_pars))] else return [seq(_vars[_i+1] = [_res][1][_i+1], _i = 0 .. _n), seq(_pars[_i] = [_res][2][_i], _i = 1 .. nops(_pars))] end if elif type(_xout, `=`) and member(lhs(_xout), ["eventdisable", 'eventdisable', "eventenable", 'eventenable', "eventfired", 'eventfired', "direction", 'direction', NULL]) then return _solnproc(convert(lhs(x_classical), 'string') = rhs(x_classical)) elif _xout = "solnprocedure" then return eval(_solnproc) elif _xout = "sysvars" then return _vars end if; if procname <> unknown then return ('procname')(x_classical) else _ndsol; _ndsol := pointto(_dat[2][0]); return ('_ndsol')(x_classical) end if end if; try _res := _solnproc(_xout); [seq(_vars[_i+1] = _res[_i+1], _i = 0 .. _n)] catch: error  end try end proc

plots:-display([
     plots:-odeplot(Sol, [t, y(t)], t= 0..T, legend= [euler]),

     plot(int(int(f(x), x= 0..t), t= 0..tau), tau= 0..T, legend= [exact], color= black)
]);

 

 

Download dsolve_int_proc.mw

There is hardly any difference in the graphs, so I fail to see the pedagogical value of this exercise.

 


Maple can almost do the integral symbolically: It can do it in exact numeric values if you change your constants to exact values. Once we do that, it is easy to see where the problem is: erf(10) is extremely close to 1; so close that it takes 45 Digits to discern any difference.

 

restart:

eq2:= (a/(a + c*z))^L*exp(-z)/sqrt(z);

L:= 2:
a:= 10^(1/10):  # a:= 10^(0.1);

c:= a/100:  # c:= 0.01*a;

J:= Int(eq2, z= 0..infinity);
'value'('J') = value(J);  

 

 

 

V:= 995*Pi*exp(100)*(erf(10)-1)+100*sqrt(Pi);

995*Pi*exp(100)*(erf(10)-1)+100*Pi^(1/2)

evalf(erf(10));

1.

evalf(100*sqrt(Pi));

177.2453851

evalf(V);

177.2453851

while erf(10.) = 1. do  Digits:= Digits+1  end do:

Digits;

45

Digits:= 45+1+15:

evalf(V): Digits:= 15: evalf(%%);

1.75511537316683

evalf(J);

1.75511537316683

 

 

Download cata_cancel.mw

If f(x) = r*(8-2*x^2) = r*2*(2-x)*(2+x), then |(f@@n)(x)| -> infinity as n -> infinity, for r > 1 and 0 < x < 1. ((f@@n)(x) denotes the nth iterate of f, e.g., (f@@3)(x) = f(f(f(x))).)

The trick is to apply eval to count whenever its value (as opposed to its name) is required. Like this,

xcp:= proc(count)
local i;
     print("nargs=", nargs, "args=", args);
     count:= 0;
     for i from 2 to nargs do
          if isprime(args[i]) then
               count:= eval(count)+1
          end if;
          print("i=", i, "count=", eval(count))
     end do;
     print("count=", eval(count))
end proc ;

Please don't conclude from this exercise that the above is a good way to write Maple code. The purpose of the exercise is, IMO, to show you what one-argument eval is good for. I'd much rather read the original cp procedure.

One error is that you need with(combstruct) before your first call to iterstructs.


macro(LA= LinearAlgebra):

a) The consumption matrix. Index 1 is services and index 2 is foods.

C:= Matrix([[.5, .2], [.4, .2]]);

C := Matrix(2, 2, {(1, 1) = .5, (1, 2) = .2, (2, 1) = .4, (2, 2) = .2})

b) The demand vector...

d:= < 2e6, 12e6 >;

d := Vector(2, {(1) = 2000000., (2) = 12000000.0})

,,, and the production vector

p:= LA:-LinearSolve(LA:-IdentityMatrix(2)-C, d);

p := Vector(2, {(1) = 12500000.00, (2) = 21250000.00})

c)

C[2,1]*p[2];

HFloat(8500000.0)

 


Download Leontief1.mw

Running your code in Maple 17, I get 7 solutions for [A,B], one real and six complex.

What result did you get?

The command that you want is select. See ?select .

Example:

Even:= n-> irem(n,2) = 0:
select(Even, [$1..10]);
                        [2, 4, 6, 8, 10]

Sol:= dsolve({diff(y(x),x)=y(x), y(0)=1}, numeric, output= listprocedure):
theta:= eval(y(x), Sol):
evalf(Int(ln@theta, 0..2));
                   1.999999704723899

The exact answer is 2. So the accuracy is limited to the accuracy of dsolve not the accuracy of numerical integration.

Is this what you had in mind for the second plot?

restart:
b:= 100:
plot([seq(BesselJ(0, BesselJZeros(0,n)*sqrt(z/b)), n= 1..4)], z= 0..100);

And for the animation, I had to assume some values for your constants.

restart:
A:= K[n]*cos(BesselJZeros(0,n)^2/4/b*sqrt(g)*t - sigma[n])*BesselJ(0, BesselJZeros(0,n)*sqrt(z/b)):
n:= 3: K[n]:= 1: b:= 100: g:= 1: sigma[3]:= Pi/3:
plots:-animate(plot, [A, z= 0..100], t= 0..20);

The closest thing to that that is possible is

(A,C,B,F):= convert(Q, list)[];

Note that the order is not (A,B,C,F).

Your list6 is too big to generate the permutations all at once, which is what combinat:-permute does. You need to use the iterator commands, which generate them one at a time. These are combinat:-firstperm, combinat:-nextperm, etc.

You must mean for the cumulative probability to be greater than 0.95, not the one-point probability. For the cumulative probability, you need the sum of the one-point probabilities from k = 0 to n.

restart:
lambda:= 2:
sum(exp(-lambda)*lambda^k/k!, k= 0..n):
fsolve(% = .95, n);
                        4.04766491450491

Since n must be integer, we take n = 5.


restart:

DE:= z*diff(Z(z),z$2)+diff(Z(z),z)+a^2*Z(z) = 0;

z*(diff(diff(Z(z), z), z))+diff(Z(z), z)+a^2*Z(z) = 0

tr:= {z= x^2*b}:

PDEtools:-dchange(tr, DE, [x], params= {a,b});

(1/2)*x*(-(1/2)*(diff(Z(x), x))/(x^2*b)+(1/2)*(diff(diff(Z(x), x), x))/(x*b))+(1/2)*(diff(Z(x), x))/(x*b)+a^2*Z(x) = 0

simplify(%);

(1/4)*(4*a^2*Z(x)*x*b+(diff(diff(Z(x), x), x))*x+diff(Z(x), x))/(x*b) = 0

numer(lhs(%));

4*a^2*Z(x)*x*b+(diff(diff(Z(x), x), x))*x+diff(Z(x), x)

expand(%/x);

4*a^2*Z(x)*b+diff(diff(Z(x), x), x)+(diff(Z(x), x))/x

 


Download dchange.mw

First 329 330 331 332 333 334 335 Last Page 331 of 395