tomleslie

13821 Reputation

20 Badges

14 years, 301 days

MaplePrimes Activity


These are answers submitted by tomleslie

The Maple help for int() clearly states (emphasis added)

The int(expression, x) calling sequence computes an indefinite integral of the expression with respect to the variable x. Note: No constant of integration appears in the result.

 

but in "straightforward" Maple, something like the attached will do it.

  restart:

  s:= f->2*Pi*I*f:
  V1:=1:
  C:=100e-09:
  L:=10.0e-03:
  R:=1e03:
  XL:=f-> s(f)*L:
  XC:=f-> 1/(s(f)*C):
  Z:= f-> XL(f)+XC(f):
  T:=f-> R/(R+Z(f)):
  Vout:=f-> V1*T(f);

  plot( abs(Vout(f)),
        f=100..100000,
        axis[1]=[mode=log, gridlines=[30, color=green] ],
        axis[2]=[gridlines=[3, color=green] ],
        view=[100..100000, 0..1]
      );
  

proc (f) options operator, arrow; V1*T(f) end proc

 

 

 

Download serRes.mw

 

for the example you quote, ie x=1, y=1, z=6 and w=-1, there are actually an infinite number of solutions.

Just select _Z1 to be any negative integer in the attached.

  restart;
  eq1 := a + b + c = n*x;
  eq2 := a + 3*b + c = n*y;
  eq3 := a + b + 5*c = n*z;
  eq4 := 4*a + 8*b = n*w;
#
# for a givn set of integers x, y, z, and w (can
# be positive or negative), can we determine a
# positive integer integer n (n must be positive)
# and the three integer (a, b, c) solution of previous system
#
  isolve(eval({eq1, eq2, eq3, eq4}, [x = 1, y = 1, z = 6, w = -1]));
#
# For example
#
  eval(%, _Z1=-1);;
  eval(%%, _Z1=-10);

a+b+c = n*x

 

a+3*b+c = n*y

 

a+b+5*c = n*z

 

4*a+8*b = n*w

 

{a = _Z1, b = 0, c = -5*_Z1, n = -4*_Z1}

 

{a = -1, b = 0, c = 5, n = 4}

 

{a = -10, b = 0, c = 50, n = 40}

(1)

 

NULL

Download intsol.mw

tou want somthing like the attached? You might want to consider restricting the range of 't' to 1..20, rather than 1..100, because after t=~20, the animation gets a bit boring

  restart;
  with(plots):
  M:= [ seq
        ( matrixplot
          ( -Matrix( 3,
                     3,
                     [ [ 0.2588777368e9, -0.2588777368e9,        0.     ],
                       [-0.2588777368e9,  0.2588777368e9,        0.     ],
                       [         0.,           0.,        0.6503118260e8]
                     ]
                   )*(1/t^0.9),
            heights=histogram
          ),
          t=1..101
        )
      ]:
  display(M, insequence=true);

 

 

Download animMat.mw

MVals := [1.5, 2, 2.5];
for j to numelems(MVals) do
    Ans[j] := dsolve(eval([OdeSys, Cond], M = MVals[j]), numeric, output = listprocedure);
end do;

the loop will produce A[1], A[2], A[3], and the loop variable 'j' will be 4, when the loop finishes

The next execution group, ie

Theta_b[j]:= int( eval(U(Y), Ans[j])*eval(Theta(Y), Ans[j]), Y=0..1) / int( eval(U(Y), Ans[j]), Y=0..1):  
Q_b[j]:=int( eval(U(Y), Ans[j]), Y=0..1):

will therefore use j=4, and so Ans[4], which of course does not exist - so this will  produce an error. In fact I can't work out what 'j' is supposed to be in thhis group

working out precisely what you want from your description, but maybe the final execution group in the attached will be of some use

restart

A := (-18*sqrt(2)*(M-4/3)*(x^2+2)^2*arctan((1/2)*x*sqrt(2))-9*Pi*(M-4/3)*(x^2+2)^2*sqrt(2)+(-36*M+48)*x^3+(-120*M+96)*x)/(4*(x^2+2)^2)

(1/4)*(-18*2^(1/2)*(M-4/3)*(x^2+2)^2*arctan((1/2)*x*2^(1/2))-9*Pi*(M-4/3)*(x^2+2)^2*2^(1/2)+(-36*M+48)*x^3+(-120*M+96)*x)/(x^2+2)^2

(1)

p0 := plot([subs(M = 1.3015, A)], x = -5 .. 0, axes = boxed, colour = [black], style = [line])

 

p1 := plot([subs(M = 1.2431, A)], x = -5 .. 0, colour = [red], style = [line], axes = box)

 

with(plots); display({p0, p1})

 

#
# The function g() returns the maximum value of the curve 'A'
# in the range x=-5..0, for the supplied value of 'M'
#
  g:= mVal->maximize(eval(A, M = mVal), x = -5 .. 0);
#
# A couple of examples
#
  g(1.4);
  g(1.3);
#
# The function f() computes the maximum values of the curve 'A'
# in the range x=-5..0, for both supplied values of 'M', and
# returns  smaller/larger, expressed as a percentage
#
  f:=(M1, M2)->`if`(g(M1)>g(M2), 100*g(M2)/g(M1), 100*g(M1)/g(M2));
#
# A couple of exaamples
  f(1.4,1.3);
  f(1.3,1.4);

proc (mVal) options operator, arrow; maximize(eval(A, M = mVal), x = -5 .. 0) end proc

 

1.681120821

 

1.925072574

 

proc (M1, M2) options operator, arrow; `if`(g(M2) < g(M1), 100*g(M2)/g(M1), 100*g(M1)/g(M2)) end proc

 

87.32765942

 

87.32765942

(2)

 

Download pc.mw

It constructs a graph isomorphic to the original graph 's', using only Arabic numerals, and provides a mapping between the two graphs

  restart;

  with(GraphTheory):
  g1:= PathGraph(10):
  g2:= CycleGraph(3):
  s:= LexicographicProduct(g1,g2):
  IsChordal(s,eliminationordering=true);
#
# Construct graph isomorphic t 's'
#
  G2:= Graph({seq( seq( {i, j}, j in op(4,s)[i]), i=1..30)}):

  IsChordal(G2); # should be chordal
  IsIsomorphic(s, G2, phi); # should be isomorphic
  phi; # mapping from S to G2

  DrawGraph(s);
  DrawGraph(G2);

true, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]

 

true

 

true

 

["1:1" = 1, "1:2" = 3, "1:3" = 2, "2:1" = 4, "2:2" = 5, "2:3" = 6, "3:1" = 7, "3:2" = 8, "3:3" = 9, "4:1" = 10, "4:2" = 11, "4:3" = 12, "5:1" = 13, "5:2" = 14, "5:3" = 15, "6:1" = 16, "6:2" = 17, "6:3" = 18, "7:1" = 19, "7:2" = 20, "7:3" = 21, "8:1" = 22, "8:2" = 23, "8:3" = 24, "9:1" = 25, "9:2" = 26, "9:3" = 27, "10:1" = 28, "10:2" = 29, "10:3" = 30]

 

 

 

 

Download chordal.mw

what you were trying to achieve? (NB the gridlines are an aretfact of rendering on this site - they do not appear in the actual worksheet)

restart

data := Matrix(22, 4, {(1, 1) = y, (1, 2) = Analytical*Solution, (1, 3) = Numerical*Solution, (1, 4) = Errors = abs(Analytical-Numerical), (2, 1) = -1, (2, 2) = 0., (2, 3) = 0., (2, 4) = 0., (3, 1) = -.9, (3, 2) = 0.5636152013e-1, (3, 3) = 0.5636163548720764e-1, (3, 4) = 0.1153572076e-6, (4, 1) = -.8, (4, 2) = .1125384516, (4, 3) = .11253867882000401, (4, 4) = 0.2272200040e-6, (5, 1) = -.7, (5, 2) = .1684783747, (5, 3) = .16847870520337455, (5, 4) = 0.3305033746e-6, (6, 1) = -.6, (6, 2) = .2241222651, (6, 3) = .2241226832780044, (6, 4) = 0.4181780044e-6, (7, 1) = -.5, (7, 2) = .2794044740, (7, 3) = .2794049550379978, (7, 4) = 0.4810379978e-6, (8, 1) = -.4, (8, 2) = .3342527056, (8, 3) = .3342532136589305, (8, 4) = 0.5080589305e-6, (9, 1) = -.3, (9, 2) = .3885879914, (9, 3) = .38858847929279206, (9, 4) = 0.4878927921e-6, (10, 1) = -.2, (10, 2) = .4423246654, (10, 3) = .4423250728927329, (10, 4) = 0.4074927329e-6, (11, 1) = -.1, (11, 2) = .4953703320, (11, 3) = .49537058813706913, (11, 4) = 0.2561370691e-6, (12, 1) = 0., (12, 2) = .5476258363, (12, 3) = .5476258615287573, (12, 4) = 0.2522875731e-7, (13, 1) = .1, (13, 2) = .5989852297, (13, 3) = .5989849407535721, (13, 4) = 0.2889464279e-6, (14, 1) = .2, (14, 2) = .6493357340, (14, 3) = .6493350513874487, (14, 4) = 0.6826125513e-6, (15, 1) = .3, (15, 2) = .6985577020, (15, 3) = .6985565620510028, (15, 4) = 0.1139948997197493e-5, (16, 1) = .4, (16, 2) = .7465245786, (16, 3) = .7465229481170813, (16, 4) = 0.1630482918679732e-5, (17, 1) = .5, (17, 2) = .7931028563, (17, 3) = .7931007540853308, (17, 4) = 0.2102214669230662e-5, (18, 1) = .6, (18, 2) = .8381520310, (18, 3) = .8381495547462811, (18, 4) = 0.24762537189637612e-5, (19, 1) = .7, (19, 2) = .8815245545, (19, 3) = .8815219152663064, (19, 4) = 0.2639233693590981e-5, (20, 1) = .8, (20, 2) = .9230657831, (20, 3) = .9230633503340617, (20, 4) = 0.24327659382539224e-5, (21, 1) = .9, (21, 2) = .9626139288, (21, 3) = .9626122825186632, (21, 4) = 0.16462813368089968e-5, (22, 1) = 1.0, (22, 2) = 1.000000000, (22, 3) = .9999999999999999, (22, 4) = 0.1110223025e-15})

with(plots):



p1 := display
      (  plot
         ( data[2..-1, [1, 4]],
           color=blue,
           linestyle=3
         ),
         plot
         (  data[2..-1, [1, 4]],
            style=point,
            color=blue,
            symbol=asterisk,
            symbolsize=20,
            color=red
         ),
         axes=boxed,
         labels=[y, "Absolute Error"],
         labeldirections=[default, vertical]
       );
 

 

 

Download basicPlot.mw

but in Maple you can generate arrays of exxentially arbitray dimension - see the attached for a random 4x4x4x4 example.

  restart:
#
# A random 4*4*4*4 array
#
  Arr:=ArrayTools:-RandomArray(4,4,4,4,distribution=uniform):
#
# An element of the random array
#
  Arr[4,3,2,1]

HFloat(0.25806469591206693)

(1)

 

Download Arr4.mw

is to use the 'legend' option.

Since nothing in your worksheet contains a derivative, you do not have a BVP. You appear to have algebraic expressions for f(x), g(x), and h(x), together with some conditions (which you have misleadinglys assigned to bcs) for certain values of the independent variable x.
These can be solved using fsolve() - see the attached

restart; inf := 10

10

(1)

eq1 := f(x) = x+a[1]*x^2-(1/48)*sqrt(2)*a[1]*x^4-(1/120)*a[1]^2*sqrt(2)*x^5; eq2 := g(x) = -0.3830161729e-5*x^5*a[3]*a[2]^2+0.2357022603e-3*x^5*a[1]*a[2]^2-0.2946278254e-1*x^4*a[1]*a[2]+1.+0.1666666667e-4*x^3*a[2]*a[3]^2+0.3333333334e-4*x^3*a[3]*a[2]^2+0.5155986944e-3*x^4*a[3]*a[2]-0.5000000000e-2*a[2]*x^2*a[3]+8.333333336*10^(-11)*x^5*a[2]^5-0.2357022603e-5*x^5*a[2]*a[3]^2-4.166666668*10^(-8)*x^4*a[2]^4-0.5892556509e-1*x^3*a[2]+0.3125000000e-2*x^5*a[2]+a[2]*x-0.5000000000e-2*a[2]^2*x^2+0.1666666667e-4*x^3*a[2]^3+0.4419417381e-3*x^4*a[2]^2-0.1473139127e-5*x^5*a[2]^3+3.333333334*10^(-10)*x^5*a[3]*a[2]^4+8.333333336*10^(-11)*x^5*a[2]*a[3]^4+3.333333334*10^(-10)*x^5*a[2]^2*a[3]^3+5.000000000*10^(-10)*x^5*a[3]^2*a[2]^3-1.250000000*10^(-7)*x^4*a[3]^2*a[2]^2-1.250000000*10^(-7)*x^4*a[3]*a[2]^3+0.2651650428e-3*x^5*a[2]*a[1]*a[3]-4.166666668*10^(-8)*x^4*a[2]*a[3]^3; eq3 := h(x) = 0.4714045206e-5*x^5*a[3]*a[2]^2-0.3240906080e-3*x^5*a[1]*a[2]^2+0.2946278254e-1*x^4*a[1]*a[2]-0.1473139128e-1*x^4*a[1]*a[3]+1.+a[3]*x-0.1666666667e-4*x^3*a[2]*a[3]^2-0.3333333334e-4*x^3*a[3]*a[2]^2-0.6629126071e-3*x^4*a[3]*a[2]+0.5000000000e-2*a[2]*x^2*a[3]-8.333333336*10^(-11)*x^5*a[2]^5+0.2798964342e-5*x^5*a[2]*a[3]^2+4.166666668*10^(-8)*x^4*a[2]^4+0.5892556509e-1*x^3*a[2]-0.4687500000e-2*x^5*a[2]+0.5000000000e-2*a[2]^2*x^2-0.1666666667e-4*x^3*a[2]^3-0.5892556508e-3*x^4*a[2]^2+0.1915080866e-5*x^5*a[2]^3-0.2946278254e-1*x^3*a[3]+0.7812499998e-3*x^5*a[3]-3.333333334*10^(-10)*x^5*a[3]*a[2]^4-8.333333336*10^(-11)*x^5*a[2]*a[3]^4-3.333333334*10^(-10)*x^5*a[2]^2*a[3]^3-5.000000000*10^(-10)*x^5*a[3]^2*a[2]^3+1.250000000*10^(-7)*x^4*a[3]^2*a[2]^2+1.250000000*10^(-7)*x^4*a[3]*a[2]^3-0.3535533905e-3*x^5*a[2]*a[1]*a[3]+4.166666668*10^(-8)*x^4*a[2]*a[3]^3

f(x) = x+a[1]*x^2-(1/48)*2^(1/2)*a[1]*x^4-(1/120)*a[1]^2*2^(1/2)*x^5

(2)

bcs := f(0) = 0, (D(f))(0) = 1, f(inf) = 0, g(0) = 1, g(inf) = 0, h(0) = 1, h(inf) = 0

f(0) = 0, (D(f))(0) = 1, f(10) = 0, g(0) = 1, g(10) = 0, h(0) = 1, h(10) = 0

(3)

NULL

aVals := fsolve([rhs(eval(eq1, x = inf)) = 0, rhs(eval(eq2, x = inf)) = 0, rhs(eval(eq3, x = inf))])

{a[1] = -.2062816351, a[2] = -0.3082843522e-2, a[3] = -0.2752261123e-1}

(4)

eval(eq1, `union`({x = 0}, aVals))

f(0) = 0.

(5)

(D(f))(0) = eval(diff(rhs(eq1), x), `union`({x = 0}, aVals))

(D(f))(0) = 1.

(6)

evalf(eval(eq1, `union`({x = inf}, aVals)))

f(10) = 0.1e-7

(7)

eval(eq2, `union`({x = 0}, aVals))

g(0) = 1.

(8)

eval(eq2, `union`({x = inf}, aVals))

g(10) = -0.1585e-9

(9)

eval(eq3, `union`({x = 0}, aVals))

h(0) = 1.

(10)

eval(eq3, `union`({x = inf}, aVals))

h(10) = -0.9042e-9

(11)

NULL

Download noBVP.mw

as in the attached

restart;

with(LinearAlgebra):

with(DynamicSystems):

interface(imaginaryunit=j):

eq_m1 := m1 = (X__Tq*E__B*sin(delta) - R__T*E__B*cos(delta))/(R__E^2 + 2*R__a*R__E + R__a^2 + X__E^2 + X__E*L__ads*L__fd/(L__fd + L__ads) + 2*X__E*L__l + L__aqs*X__E + L__aqs*L__ads*L__fd/(L__fd + L__ads) + L__aqs*L__l + L__l*L__ads*L__fd/(L__fd + L__ads) + L__l^2);

m1 = (X__Tq*E__B*sin(delta)-R__T*E__B*cos(delta))/(R__E^2+2*R__a*R__E+R__a^2+X__E^2+X__E*L__ads*L__fd/(L__fd+L__ads)+2*X__E*L__l+L__aqs*X__E+L__aqs*L__ads*L__fd/(L__fd+L__ads)+L__aqs*L__l+L__l*L__ads*L__fd/(L__fd+L__ads)+L__l^2)

(1)

eq_m1_desired := m1 = (X__Tq*E__B*sin(delta) - R__T*E__B*cos(delta))/(R__E^2 + 2*R__a*R__E + R__a^2 + X__E^2 + X__E*L__ads_p + 2*X__E*L__l + L__aqs*X__E + L__aqs*L__ads_p + L__aqs*L__l + L__l*L__ads_p + L__l^2);

m1 = (X__Tq*E__B*sin(delta)-R__T*E__B*cos(delta))/(L__aqs*L__l+L__aqs*X__E+L__aqs*L__ads_p+L__l^2+2*L__l*X__E+L__l*L__ads_p+R__E^2+2*R__E*R__a+R__a^2+X__E^2+X__E*L__ads_p)

(2)

######

eq_m1a := simplify(subs(L__ads = L__ads_p*L__fd/(L__fd - L__ads_p), eq_m1));
simplify(eq_m1_desired-eq_m1a);

m1 = -E__B*(-sin(delta)*X__Tq+cos(delta)*R__T)/(L__l^2+(L__ads_p+2*X__E+L__aqs)*L__l+X__E^2+(L__ads_p+L__aqs)*X__E+L__aqs*L__ads_p+(R__E+R__a)^2)

 

0 = 0

(3)

 

Download simpSubs.mw

available from the Maple application centre. This "appears" to work without problems. See the attached.

restart:

Test code written by Dr. Venkat Subramanian at UT Austin, 05/31/2023. This code uses CVP approach (piecwise constant) to perform optimal control. NLPSolve combination with dsolve numeric parametric form is buggy and fails for some values of nvar, and works for some values of nvar. Ideally increasing nvar should show convergence with respect to the objective function.

restart:

Digits:=15;

15

(1)

eqodes:=[diff(ca(t),t)=-(u+u^2/2)*1.0*ca(t),diff(cb(t),t)=1.0*u*ca(t)-0.1*cb(t)];

[diff(ca(t), t) = -1.0*(u+(1/2)*u^2)*ca(t), diff(cb(t), t) = 1.0*u*ca(t)-.1*cb(t)]

(2)

soln:=dsolve({op(eqodes),ca(0)=alpha,cb(0)=beta},type=numeric,'parameters'=[alpha,beta,u],compile=true,savebinary=true):

  ss:= proc(x)
            interface(warnlevel=0):
           #if  type(x[1],numeric)
            if  type(x,Vector)
            then local z1,n1,i,c10,c20,dt,u;
                 global soln,nvar;
                 dt:=evalf(1.0/nvar):
                 c10:=1.0:c20:=0.0:
                 for i from 1 to nvar do
                     u:=x[i]:
                     soln('parameters'=[c10,c20,u]):
                     z1:=soln(dt):
                     c10:=subs(z1,ca(t)):c20:=subs(z1,cb(t)):
                 od:
                 -c20;
            else 'procname'(args):
            end if:
       end proc:

  preP:= proc()
              if   type( [_passed][1], numeric)
              then ss( <_passed> );
              else 'thisproc(_passed)'
              fi;
         end proc;

proc () if type([args][1], numeric) then ss(`<,>`(args)) else 'thisproc(args)' end if end proc

(3)

  nvar:=2;
  DirectSearch:-Search( preP,
                        [seq( [cat(z, j)>=0, cat(z,j)<=5][], j=1..nvar)],
                        initialpoint=[0.1 $ nvar],
                        variables=[seq( cat(z, j), j=1..nvar)]
                      )[1..2];

         
 

nvar := 2

 

[HFloat(-0.5239011644866959), Vector[column](%id = 36893488148178529084)]

(4)

  nvar:=3;
  DirectSearch:-Search( preP,
                        [seq( [cat(z, j)>=0, cat(z,j)<=5][], j=1..nvar)],
                        initialpoint=[0.1 $ nvar],
                        variables=[seq( cat(z, j), j=1..nvar)]
                      )[1..2];

nvar := 3

 

[HFloat(-0.5314533818996774), Vector[column](%id = 36893488148163938052)]

(5)

  nvar:=4;
  DirectSearch:-Search( preP,
                        [seq( [cat(z, j)>=0, cat(z,j)<=5][], j=1..nvar)],
                        initialpoint=[0.1 $ nvar],
                        variables=[seq( cat(z, j), j=1..nvar)]
                      )[1..2];

nvar := 4

 

[HFloat(-0.5351539426577706), Vector[column](%id = 36893488148138835108)]

(6)

  nvar:=5;
  DirectSearch:-Search( preP,
                        [seq( [cat(z, j)>=0, cat(z,j)<=5][], j=1..nvar)],
                        initialpoint=[0.1 $ nvar],
                        variables=[seq( cat(z, j), j=1..nvar)]
                      )[1..2];
         

nvar := 5

 

[HFloat(-0.537338871817855), Vector[column](%id = 36893488148134278556)]

(7)

 

Download usingDS.mw

the attached.

restart

ERROR COMPARISON

 

n := [84, 83, 83, 81, 85, 86, 86, 83, 82, 83, 84, 83, 81, 80, 83, 79, 82, 81, 85]

[84, 83, 83, 81, 85, 86, 86, 83, 82, 83, 84, 83, 81, 80, 83, 79, 82, 81, 85]

(1)

nops(n)

19

(2)
• 

-BBDF*FORMULA*FORWARD+PC

-BBDF*FORMULA*FORWARD+PC

(3)

A := [90.3333, 85.3636, 80.1313, 81.4518, 78.9241, 90.2078, 89.8305, 85.9949, 78.7198, 79.8495, 84.3264, 86.2465, 82.7222, 78.1001, 77.8260, 86.7687, 77.2371, 85.2345, 81.7439]

[90.3333, 85.3636, 80.1313, 81.4518, 78.9241, 90.2078, 89.8305, 85.9949, 78.7198, 79.8495, 84.3264, 86.2465, 82.7222, 78.1001, 77.8260, 86.7687, 77.2371, 85.2345, 81.7439]

(4)

``

add(`~`[abs](`~`[`-`](A, n))); %/numelems(A)

67.9484

 

3.576231579

(5)

NULL

Download sumMean2.mw

restart

ERROR COMPARISON

 

n := [84, 83, 83, 81, 85, 86, 86, 83, 82, 83, 84, 83, 81, 80, 83, 79, 82, 81, 85]

[84, 83, 83, 81, 85, 86, 86, 83, 82, 83, 84, 83, 81, 80, 83, 79, 82, 81, 85]

(1)

nops(n)

19

(2)
• 

-BBDF*FORMULA*FORWARD+PC

-BBDF*FORMULA*FORWARD+PC

(3)

A := [90.3333, 85.3636, 80.1313, 81.4518, 78.9241, 90.2078, 89.8305, 85.9949, 78.7198, 79.8495, 84.3264, 86.2465, 82.7222, 78.1001, 77.8260, 86.7687, 77.2371, 85.2345, 81.7439]

[90.3333, 85.3636, 80.1313, 81.4518, 78.9241, 90.2078, 89.8305, 85.9949, 78.7198, 79.8495, 84.3264, 86.2465, 82.7222, 78.1001, 77.8260, 86.7687, 77.2371, 85.2345, 81.7439]

(4)

add(`~`[abs](`~`[`-`](A, n))); %/numelems(A)

67.9484

 

3.576231579

(5)

``

Download sumMean.mw

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