tomleslie

13876 Reputation

20 Badges

15 years, 163 days

MaplePrimes Activity


These are answers submitted by tomleslie

fnormal(..., eps) and simplify(..,zero) as in the attached.

 restart:
  v1 := 1:
  v2 := 0.5:
  k := 0.12:
  p1 := 0.328:
  p2 := 0.74:
  l1 := 0.31:
  l2 := 1.16:
  sysode := diff(Cp(t), t) = -(p1 + p2 + k)*Cp(t) + l1*C1(t) + l2*C2(t),
            diff(C1(t), t) = (p1*Cp(t) - l1*C1(t))/v1,
            diff(C2(t), t) = (p2*Cp(t) - l2*C2(t))/v2:
  ics := Cp(0) = 0.347, C1(0) = 0., C2(0) = 0.:
  sol := evalf( dsolve([sysode, ics])):
  ans:=simplify(fnormal~(sol, 9), zero);
  plot( [ eval(Cp(t), ans), eval(C1(t), ans), eval(C2(t), ans)], t=0..10, color=[red, green, blue]);

Or, just do the whole thing numerically with

#
# Or do the whole thing numerically
#
  sol:=dsolve([sysode, ics], numeric);
  plots:-odeplot(sol, [ [t, Cp(t)], [t, C1(t)], [t, C2(t)]], t=0..10, color=[red, green, blue]); 

Download odesol.mw

to uses Newton's root-finding method?  ie https://en.wikipedia.org/wiki/Newton%27s_method

I have implemented this method for your problem in the attached


 

  restart;
  f:=unapply(2*x-4*cos(x)-0.6,x); #the equation itself
  f1:=unapply(diff(f(x),x),x); #its derivative
  a:=-0.5: b:=1.5: eps:=0.001:
#
# Use Newton's method
#
  n:=1:
  x[0]:=0:
  x[1]:=1:
  while abs(evalf(x[n]-x[n-1])) > eps do
        n:=n+1:
        x[n]:=evalf(x[n-1]-f(x[n-1])/f1(x[n-1]));
  od;
#
# Use Maple's built-in numerical solver
#
  fsolve(f(x)=0,x=a..b);

proc (x) options operator, arrow; 2*x-4*cos(x)-.6 end proc

 

proc (x) options operator, arrow; 2+4*sin(x) end proc

 

2

 

1.141860918

 

3

 

1.138293771

 

4

 

1.138291886

 

1.138291886

(1)

 

Download newton.mw

 

Rather than mahe a lot of assumptions, it is generally a better idea to use the evalc() command which evaluates complex expressions on th basis that all names represent real quantities, and does its very best to get a result in the form expr1+I*expr2

The square root of -1 is represented as 'I' in Maple , not 'j' (although you can change this if you really want to. In the attached I'm using the default.

It can be confusing to load a number of packages which are never actually used

Having said all of the above, the attached shows how I would perform this calculation.

  restart;

#
# Define equations and solve ofr I1, I2
#
  eq1 := Vin - I1*(2/(s*C1) + s*L1 + R1) - I2*s*M = 0;
  eq2 := I1*s*M + I2*(RL + 2/(s*C2) + s*L2 + R2) = 0;
  sol1 := solve({eq1, eq2}, {I1, I2});

Vin-I1*(2/(s*C1)+s*L1+R1)-I2*s*M = 0

 

I1*s*M+I2*(RL+2/(s*C2)+s*L2+R2) = 0

 

{I1 = Vin*s*C1*(C2*L2*s^2+C2*R2*s+C2*RL*s+2)/(C1*C2*L1*L2*s^4-C1*C2*M^2*s^4+C1*C2*L1*R2*s^3+C1*C2*L1*RL*s^3+C1*C2*L2*R1*s^3+C1*C2*R1*R2*s^2+C1*C2*R1*RL*s^2+2*C1*L1*s^2+2*C2*L2*s^2+2*C1*R1*s+2*C2*R2*s+2*C2*RL*s+4), I2 = -Vin*s^3*C1*C2*M/(C1*C2*L1*L2*s^4-C1*C2*M^2*s^4+C1*C2*L1*R2*s^3+C1*C2*L1*RL*s^3+C1*C2*L2*R1*s^3+C1*C2*R1*R2*s^2+C1*C2*R1*RL*s^2+2*C1*L1*s^2+2*C2*L2*s^2+2*C1*R1*s+2*C2*R2*s+2*C2*RL*s+4)}

(1)

#
# Extract the solution for I1, from sol1 above,
# evaluate it with s=I*omega
# use evalc() to get the reult in 'neat' form
#
  I1im := evalc
          ( Im
            ( eval
              ( eval(I1, sol1),
                s=I*omega
              )
            )
          );

C1*omega*Vin*(-C2*L2*omega^2+2)*(C1*C2*L1*L2*omega^4-C1*C2*M^2*omega^4-C1*C2*R1*R2*omega^2-C1*C2*R1*RL*omega^2-2*C1*L1*omega^2-2*C2*L2*omega^2+4)/((-C1*C2*L1*R2*omega^3-C1*C2*L1*RL*omega^3-C1*C2*L2*R1*omega^3+2*C1*R1*omega+2*C2*R2*omega+2*C2*RL*omega)^2+(C1*C2*L1*L2*omega^4-C1*C2*M^2*omega^4-C1*C2*R1*R2*omega^2-C1*C2*R1*RL*omega^2-2*C1*L1*omega^2-2*C2*L2*omega^2+4)^2)+C1*omega*Vin*(C2*R2*omega+C2*RL*omega)*(-C1*C2*L1*R2*omega^3-C1*C2*L1*RL*omega^3-C1*C2*L2*R1*omega^3+2*C1*R1*omega+2*C2*R2*omega+2*C2*RL*omega)/((-C1*C2*L1*R2*omega^3-C1*C2*L1*RL*omega^3-C1*C2*L2*R1*omega^3+2*C1*R1*omega+2*C2*R2*omega+2*C2*RL*omega)^2+(C1*C2*L1*L2*omega^4-C1*C2*M^2*omega^4-C1*C2*R1*R2*omega^2-C1*C2*R1*RL*omega^2-2*C1*L1*omega^2-2*C2*L2*omega^2+4)^2)

(2)

#
# Define parameters
#
  k:=1:
  M:=k*sqrt(L1*L2):
  params:= [ Vin = 24, C1 = 0.20600001, C2 = 0.20600001, L1 = 0.00003400,
             L2 = 0.00003400, RL = 3.30000000, R1 = 0.20000000, R2 = 0.20000000
           ]:
#
# Solve I1im for omega uing the above parameter
# definitions and the assumption that omega>0
#
  omega__res:= solve
               ( eval(I1im, params),
                 omega,
                 useassumptions
               ) assuming omega>0;

534.3698155

(3)

#
# Evaluate I1 in I1sol using the parameters defined
# above aand omega=omega__res
#
# Floating-point rounding may prevent the imaginary
# term disappearing comletely, so use fnormal(..,9)
# and simplify(.., zero) to remoe any residual (very
# small) imaginary parts
#
  tmp := simplify
         ( fnormal
           ( eval
             ( eval(I1, sol1),
               [ params[], s=I*omega__res]
             ),
             9
           ),
           zero
         );

119.943439

(4)

 


 

Download refload.mw

you can only have four boundary/initial conditions - so in the attached I have commented out a couple of the ones in your original worksheet. No justification for the ones I commented out, except that one has to be on x(s) and one has to be on y(s).

After that (in order to obtain a numerical solution), numerical values have to be giocven to the names 'r' and 't' in your equations. I have (arbitrarliy) set these both equal to 1. Pick any other values you might want

With these changes a numerical solution i easily obtianed - see the attached

(And somebody has broken the inline display of worksheets on this site AGAIN)


Download odesol.mw
 

 

just by *looking* at the equations, that no solution is possible, which is what Maple returns. See the attached

  restart:
  d:=0.03:
  w:=<20.33, 61.10>;
  f:=x->d-0.5*(alpha/beta-beta*x);
  f~(w);
  solve(convert(%,list), [alpha,beta]);

Vector(2, {(1) = 20.3300000000, (2) = 61.1000000000})

 

f := proc (x) options operator, arrow; d+(-1)*.5*(alpha/beta-beta*x) end proc

 

Vector[column](%id = 36893488148087288884)

 

[]

(1)

 

Download noSol.mw

your are asking for a tangent plane at the point t=11, u=-12, it is probably a good idea to ensure that your plot ranges include this point.

The exponential function will be changing very rapidly at this point so you probably want to keeep the plotting ranges quite small - so something like the attached

  restart;
  with(plots):
  f:=exp(t^2 + 10*u - 1):
  T:=-121 + 22*t + 10*u:
  pt:=[11, -12]:
  r:=0.1:
  display( [ plot3d( [f,T], t = pt[1]-r .. pt[1]+r, u = pt[2]-r .. pt[2]+r, color = [red, green]),
             pointplot3d( [pt[], eval(T, [t=pt[1], u=pt[2]])], symbol=solidsphere, symbolsize=20, color=blue)
           ]
         );

 

 

Download tplane.mw

to passing the variable name as a parameter is to use the indets() function to extract the appropriate name from the passed polynomial as in the attached

NULL

Programm zur Brechnung der Kreisteilungspolynome_2022-04-05 Ki

 

NULL

restart; with(Algebraic); with(NumberTheory)

n := 6

6

(1)

 

cyclo_poly := Vector[row](1 .. n, 0)

Vector[row](%id = 36893488148078618252)

(2)

i := 1; cyclo_poly[1] := X-1

1

 

X-1

(3)

NULL
c_poly := proc (i, kt_poly) local j, hz1, hz2; j := i+1; hz1 := indets(kt_poly, name)[]^j-1; hz2 := kt_poly; Algebraic:-Quotient(hz1, hz2, indets(kt_poly, name)[]) end proc

cyclo_poly[2] := c_poly(i, cyclo_poly[i])

X+1

(4)

``

Download quot.mw

functions with no errors - so what exactly is the problem?

You might want to check the execution group I have added at the end, but I doubt that this is what you are after


 

Import packages

 

restart: with(ArrayTools): with(Student:-Calculus1): with(LinearAlgebra): with(ListTools):with(RootFinding):with(ListTools):

NULL

Parameters

 

gamma1 := .1093:
alpha3 := -0.1104e-2:
k[1] := 6*10^(-12):
d:= 0.2e-3:
xi:= -0.01:
theta0:= 0.1e-3:
eta[1]:= 0.240e-1:
alpha:= 1-alpha3^2/(gamma1*eta[1]):
c:= alpha3*xi*alpha/(eta[1]*(4*k[1]*q^2/d^2-alpha3*xi/eta[1])):
theta_init:= theta0*sin(Pi*z/d):
n:= 10:

NULL

NULL

Assign g for q and plot g

 

g := q-(1-alpha)*tan(q)-c*tan(q):
plot(g, q = 0 .. 3*Pi, view = [DEFAULT, -30.. 10]);

 

Set q as a complex

 

Assume q = x+I*y and subsitute the result into g and equate the real and complex part to zero, and solve for x and y.

f := subs(q = x+I*y, g):
b1 := evalc(Re(f)) = 0:
b2 := evalc(Im(f)) = 0:

Compute the Special Asymptotes

 

This asymptote is coming from the c from the definition of "q."

NULL

qstar := (fsolve(1/c = 0, q = 0 .. infinity)):````NULL

NULL

NULL

Compute Odd asymptote

 

First, Since tan*q = sin*q*(1/(cos*q)), then an asymptote occurs at cos*q = 0. In general, we have
"q= ((2 k+1)Pi)/(2). "
Next, we compute the entry of the Oddasymptotes that is close to qstar (special asymptote) as assign it to
ModifiedOaddAsym, and then find the minimum of the ModifiedOaddAsym. Searchall Function returns

the index of an entry in a list.

OddAsymptotes := Vector[row]([seq(evalf((1/2*(2*j+1))*Pi), j = 0 .. n)]);
ModifiedOddAsym := abs(`~`[`-`](OddAsymptotes, qstar));
qstarTemporary := min(ModifiedOddAsym);
indexOfqstar2 := SearchAll(qstarTemporary, ModifiedOddAsym);
qstar2 := OddAsymptotes(indexOfqstar2);

Vector[row](11, {(1) = 1.5707963270, (2) = 4.7123889810, (3) = 7.8539816350, (4) = 10.9955742900, (5) = 14.1371669400, (6) = 17.2787596000, (7) = 20.4203522500, (8) = 23.5619449000, (9) = 26.7035375600, (10) = 29.8451302100, (11) = 32.9867228700})

 

Vector[row](%id = 36893488148121118828)

 

.6952012913

 

1

 

1.570796327

(4.2.1)

Compute x and y

 

Here, we solve for xand y within the min. and max. of qstar2 and qstar, and substitute the results into q.

AreThereComplexRoots := type(true, 'truefalse');
try
   soln1:= fsolve({b1, b2}, {x = min(qstar2, qstar) .. max(qstar2, qstar), y = 0 .. infinity});
   soln2:= fsolve({b1, b2}, {x = min(qstar2, qstar) .. max(qstar2, qstar), y = -infinity .. 0});
   qcomplex1 := subs(soln1, x+I*y);
   qcomplex2 := subs(soln2, x+I*y);
catch:
   AreThereComplexRoots := type(FAIL, 'truefalse');
end try;

 

true

 

{x = 1.348928550, y = .3589396337}

 

{x = 1.348928550, y = -.3589396337}

 

1.348928550+.3589396337*I

 

1.348928550-.3589396337*I

(4.3.1)

Compute the rest of the Roots

 

In this section we compute the roots between each asymptotes.

OddAsymptotes := Vector[row]([seq(evalf((1/2)*(2*j+1)*Pi), j = 0 .. n)]);
AllAsymptotes := sort(Vector[row]([OddAsymptotes, qstar]));
if AreThereComplexRoots then
gg := [qcomplex1, qcomplex2, op(Roots(g, q = 0.1e-3 .. AllAsymptotes[1])), seq(op(Roots(g, q = AllAsymptotes[i] .. AllAsymptotes[i+1])), i = 1 .. n)];
elif not AreThereComplexRoots then
gg := [op(Roots(g, q = 0.1e-3 .. AllAsymptotes[1])), seq(op(Roots(g, q = AllAsymptotes[i] .. AllAsymptotes[i+1])), i = 1 .. n)];
end if:

Vector[row](11, {(1) = 1.5707963270, (2) = 4.7123889810, (3) = 7.8539816350, (4) = 10.9955742900, (5) = 14.1371669400, (6) = 17.2787596000, (7) = 20.4203522500, (8) = 23.5619449000, (9) = 26.7035375600, (10) = 29.8451302100, (11) = 32.9867228700})

 

Vector[row](%id = 36893488148329110572)

(4.4.1)

NULL

Remove the repeated roots if any

 

qq := MakeUnique(gg):

NULL

Redefine n

 

m := numelems(qq):

NULL

Compute the `&tau;_n`time constants

 

for i to m do
p[i] := gamma1*alpha/(4*k[1]*qq[i]^2/d^2-alpha3*xi/eta[1]);
end do;

93.91209918-98.41042341*I

 

93.91209918+98.41042341*I

 

8.521555786

 

2.990232721

 

1.515805379

 

.9145981009

 

.6114591994

 

.4374663448

 

.3284338129

 

.2556221851

 

.2045951722

(4.7.1)

NULL

Minimum of the Re(`&tau;_n`)

 

for i to m do
p[i] := min(Re(gamma1*alpha/(4*k[1]*qq[i]^2/d^2-alpha3*xi/eta[1])));
end do;

93.91209918

 

93.91209918

 

8.521555786

 

2.990232721

 

1.515805379

 

.9145981009

 

.6114591994

 

.4374663448

 

.3284338129

 

.2556221851

 

.2045951722

(4.7.1.1)

#
# Not clear what you are trying to achieve!
#
# Maybe this?
#
  pp:=[seq( min(Re(gamma1*alpha/(4*k[1]*qq[i]^2/d^2-alpha3*xi/eta[1]))), i=1..m)];
#
# Or perhaps this
#
  pp:= min( seq( min(Re(gamma1*alpha/(4*k[1]*qq[i]^2/d^2-alpha3*xi/eta[1]))), i=1..m) );

[93.91209918, 93.91209918, 8.521555786, 2.990232721, 1.515805379, .9145981009, .6114591994, .4374663448, .3284338129, .2556221851, .2045951722]

 

.2045951722

(4.7.1.2)

NULL


 

Download compRoots.mw

see the two attached worksheets below. Respectfully suggest that you submit an SCR

restart;
interface(version);
with(GraphTheory):
with(RandomGraphs):
N:=100: n:=20: m:=30:
add(`if`(IsConnected(RandomGraph(n,m,connected)), 1, 0), 1..N) <> N;

`Standard Worksheet Interface, Maple 2020.2, Windows 7, November 11 2020 Build ID 1502365`

 

100 <> 100

(1)

 

Download RG2020.mw

restart;
interface(version);
with(GraphTheory):
with(RandomGraphs):
N:=100: n:=20: m:=30:
add(`if`(IsConnected(RandomGraph(n,m,connected)), 1, 0), 1..N) <> N;

`Standard Worksheet Interface, Maple 2022.0, Windows 7, March 8 2022 Build ID 1599809`

 

54 <> 100

(1)

 

Download RG2022.mw

I mean what wiould you expect Maple to do with something which "looked" like the result you desire - see the attached for how to produce it - but what do you think you can do with it?

restart;
series(tan(x)^(-1),x,9);
convert(%, polynom);
desired:=%..;

series(x^(-1)-(1/3)*x-(1/45)*x^3-(2/945)*x^5+O(x^7),x,7)

 

1/x-(1/3)*x-(1/45)*x^3-(2/945)*x^5

 

1/x-(1/3)*x-(1/45)*x^3-(2/945)*x^5 .. ()

(1)

 

Download oddSeries.mw

'D' is not the differential operator - syntax is wrong. I assume Maple is just interpreting it as some (unknown?) function D(). The simple way to check is just to use convert(expression, diff) as in the attached, where I have also shown the correct syntax, and convert(expression, diff) works as expected.

This is all a bit "academic" because I don't think there is any waay to make the differetnial operator 'D' behave as if it were a "coefficient  of a polynomial'

restart;

with(DEtools):

eq_e5_9b := psi__d0*Delta__delta(t) + psi__q0 * D(Delta__delta(t))/omega__0 = p_(Delta__psi__d(t))/omega__0 - Delta__psi__q(t);

psi__d0*Delta__delta(t)+psi__q0*D(Delta__delta(t))/omega__0 = p_(Delta__psi__d(t))/omega__0-Delta__psi__q(t)

(1)

#
# In the above 'D' is not the differetiial oprator - apart from
# anything else, syntax is wrong for 'D@ as differential operator
#
# Convert to 'diff' notation to make this clear
# Compare with the following execution group whihc has the correct
# syntax for 'D' as a differetnial operator
#
  convert(%, diff);

psi__d0*Delta__delta(t)+psi__q0*D(Delta__delta(t))/omega__0 = p_(Delta__psi__d(t))/omega__0-Delta__psi__q(t)

(2)

#
# Corrected syntax for 'D' as differetnial operator. Note the change
# when one applies convert(..., diff)
#
  eq_e5_9b := psi__d0*Delta__delta(t) + psi__q0 * D(Delta__delta)(t)/omega__0 = p_(Delta__psi__d(t))/omega__0 - Delta__psi__q(t);
  convert(%, diff);

psi__d0*Delta__delta(t)+psi__q0*(D(Delta__delta))(t)/omega__0 = p_(Delta__psi__d(t))/omega__0-Delta__psi__q(t)

 

psi__d0*Delta__delta(t)+psi__q0*(diff(Delta__delta(t), t))/omega__0 = p_(Delta__psi__d(t))/omega__0-Delta__psi__q(t)

(3)

 

Download Ddiff.mw

whether you are after a a "single" curve or multiple curves on the same graph. The attached does the latter

  restart;
  with(plots):
#
# A "made-up" function, just for test purposes
#
  a:=(z1,z2)-> z1/(1+z1+z2/10);
  a0:=[0, 50, 100, 150, 200]:
  cols:=[red, blue, green, orange, cyan]:
  display
  ( [ seq
      ( pointplot
        ( [ seq
            ( [ k, a(k, a0[j]) ],
              k = 0 .. 10
            )
          ],
          style=pointline,
          color=cols[j]
        ),
        j=1..numelems(a0)
      )
    ]
  )

proc (z1, z2) options operator, arrow; z1/(1+z1+(1/10)*z2) end proc

 

 

 

Download ptplt2.mw

whihc is perhaps closer to your original code, (and may be easier to understand?), is shown in the attached. All I really did was

  1. Dispense with things that "looked" like functions, but weren't and really didn't need to be in the first place - so v(x), R(x), phi[n](x) etc can all be simply replaced by v, R and phi[n]. This avoids some notational confusion (for me at least)
  2. Reordered the way the calculation is done by shifting the execution groups around into what I consider a more "logical" sequence (although your brain may work differently from mine!)
  3. Never use sum() when add() will suffice.

  restart:
  N := 2:
  var:= seq
        ( alpha[n],
          n = 1 .. N
        ):
  for n to N do
      phi[n]:= sin((2*n - 1)*Pi*x/L):
  end do:
  v:= add
      ( alpha[n]*phi[n],
        n = 1 .. N
      ):
  R:= diff(v, x$4) - p/EI:
  eqs := seq
         ( int
           ( R*phi[n],
             x = 0 .. L
           ) = 0,
           n = 1 .. N
         ):
  solve({eqs}, {var});

{alpha[1] = 4*p*L^4/(EI*Pi^5), alpha[2] = (4/243)*p*L^4/(EI*Pi^5)}

(1)

 

Download oddSolve.mw

the function in the attached?

 restart;
 a:=2.5:
 b:=-1.5:
 e:=2:
 f:=5;
 c:= x->piecewise(x<0, undefined, frem(x, e+f)<e, a, frem(x, e+f)<e+f, b);
 plot( c, 0..50);

f := 5

 

proc (x) options operator, arrow; piecewise(x < 0, undefined, frem(x, e+f) < e, a, frem(x, e+f) < e+f, b) end proc

 

 

 

Download pw.mw

a case where the provision of a worksheet (use the big green up-arrow in the Mapleprimes toolbar) would be useful. Without such a worksheet, only general guidelines - and sort-of pseudoCode - can be given. Suggestions -

  1. I'd split the problem into two stages, so that the "inner" maximization can be easliy tested/debugged
  2. I'd force an optimization method which avoids the use of derivatives
  3. I'd supply as much information in the form of constraints and/or variable ranges as possible

So the pseudoCode below would seem to be to logical approach to the problem. (NB this does not excute - it is pseudoCode)

  myProc:= proc( p1, p2, p3)
                 local Gamma, f, z1, z2, z3:
               #
               # Define the function Gamma
               #
                 Gamma:=someExpressionInvolving( f, z1, z2, z3);
               #
               # Evaluate this function for the 'passed' values
               #
                 myfunc:= eval(Gamma, [z1=p1, z2=p2, z3=p3]);
               #
               # myfunc is now a univariate function of the variable 'f'
               # It *may* be complex and may or may not be differentiable
               # so force an optimization method which doesn't use
               # derivatives
               #
                 sol:=NLPSolve( abs(myfunc),
                                f=f1..f2,
                                maximize=true,
                                method=nonlinearsimplex
                              );
               #
               # The above (if successful) will return a list containg
               # the required maximum, and the value of 'f' where this
               # was obtained. Ensure that this procedure returns only
               # the former
               #
                 return sol[1];
            end proc:
#
# Now one can test whether the above procedure is "functional", for a
# for a few sets of variables
#
  myProc(1.0, 2.0, 3.0);
  myproc(2.5e-6, 123.45, 2.0);
#
# Assuming the above test work (after debugging myProc if necessary),
# one can move on to the second stage of optimization, whihc would be
# something like
#
  NLPsolve( myProc,
            initialpoint=[1,1,1],
            method=nonlinearsimplex
          );
#
# If any kind of bounds on the variables are known, these should be
# supplied as well

 

First 28 29 30 31 32 33 34 Last Page 30 of 207