C_R

3622 Reputation

21 Badges

6 years, 123 days

MaplePrimes Activity


These are answers submitted by C_R

Its not fully clear what the unknows are that you want dsolve to solve for.

nops(sys)
                               12

tells us that you have 12 equations.

indets(sys);
 /                                      (1/2)   d           
{ exp, omicron, t, theta, (42.3 - theta)     , --- i[h](t), 
 \                                              dt          

   d            d            d            d           
  --- i[v](t), --- j[v](t), --- r[h](t), --- s[h](t), 
   dt           dt           dt           dt          

   d           
  --- s[v](t), 
   dt          

     /                                                  2\  
  exp\0.02366863905 (-0.0464 omicron + 1.046 theta - 23) /, 

     /                                                     4\  
  exp\0.00002055229087 (0.01 omicron + 1.01 theta - 21.211) /, 

  exp(0.0054 theta + 0.6737), i[h](t), i[v](t), j[v](t), r[h](t), 

                  \ 
  s[h](t), s[v](t) }
                  / 


lists additional to 12 unknown functions of t the parameters omicron and theta. These are not functions of t as you have defined them in the first two input lines. As such sys cannot be solved numerically.

Also: The frist two input lines do not use the assignement operator to define theta and omicron.

This works as well

map(X->(odetest(X,ode) assuming x>0),[sol])

The parenthesis group terms. In that way the solutions are mapped onto an expression that inculdes the assumption.

Afterwards odetest is excecuted with the assumptions.

Without parentheses the parser does not spot the second argument.

This one works as well

eval(map(X->'odetest(X,ode) assuming x>0',[sol]));

The reason "why Maple gives this internal error" is that Maple applies the procedure SolveSeparable which provides a result that gives an error because it computes ln(0) for the IC y(0)=1.

Only for this IC the result does not work.

In a similar case the Student,ODEs package had an appropriate method on board but the case (method not appropriate for a particular IC) could be solved by fixing the false classification "exact" to "NONE".
For this case it seems that there is no Student,ODEs method.

dsolve solves this IVP differently with an implicit method.

infolevel[dsolve]:=5;
dsolve({ode,ic},implicit);
solve(%,{y(x)})[];
dsolve({ode,ic});

Since I don't see that an implicit method is implemented in ODESteps, I'm curious if it's really a bug or a current limitation of ODESteps.

You can extract the polygons (vertical bars) from the plot structure which decribe the xy data.
The polygons have four corners. You probably want not xy data from all corners.
In the below I have extracted the very left x coordinate of the polygons and added the most right corner of the histogram.

[op(op(1, Q))];
%[1 .. nops(%) - 1];
seq(%[i][1][1], i = 1 .. nops(%)), %[nops(%)][2][1];

You can do the same for y coordinates or pairs of x,y whatever you are interesed in.

This is a crude example how you could filter subexpressions still using indets

indets(eqn) minus indets(eqn,name):
subexpr:=map(op,%) minus indets(%,fraction):# remove of root terms - instead of filtering for `^`
rpl:=[A,B,C,`&D;`,E,F]:
Subs2:=[seq(subexpr[i]=rpl[i], i=1..nops(subexpr))]:
simplify(subs(Subs2,eqn));

This could be refined and put into a procedure.( I am not quite sure if you are looking for something like that.)

ODESteps does not apply an adequate method although it has one on board:
Student:-ODEs:-Solve:-FirstOrderLinear. Instead "homotopy method" is applied.

When tracing ODEstep I got the impression that ODEstep tries to follow dsolve closely and adds comments step by step. Programming this is probably non trivial because essential steps in the execution of a sophisticated command (that was initially not designed for the purpose of education) have to be identified and attributed to a mathematical correct instruction to a student.

Assuming no bug in the program flow, the answer to your question “Why ODEStep is unable” could be: FirstOrderLinear is not implemented yet. This is likely because it is not listed here under “Step-by-Step Computation”.
I guess we will see it implemented in the future.

 

Update:
The old link did not work because of a special character in the file name.
first_order_quadrature_ode_with_odesteps.mw

(now v1749 can compute the integral using two methods )

Maple distinguishes between many units because they either are in use or they have been. For some units the context is important. ?Units,annotations provides some examples. If you find them strange or exotic it’s probably because you use the SI system and do not have to deal with, for example, historic units.
Maple also provides energy conversions ?Units,EnergyConversions which seem to be useful in certain areas but are not known at all in others domains.

The units package has grown over the years and includes allot of options and functions users have requested but other users do not need. For this reason the package has become powerfull but not straighforward to use (at least it was for me).
Up to you to use Grays or not.

 

Personally, I use the default unit settings in combination with convert and simplify. The context panel is usefull too.
If you have any particular calculation or conversion problems consider uploading a file with


 

2*Unit('gray')

2*Units:-Unit(Gy)

(1)

Using the context panel and conversion to E0/em and erg

2*Units:-Unit(Gy)

2*Units:-Unit(Gy)

(2)

2*Units:-Unit(Gy)

2*Units:-Unit(Gy)

(3)

Now: Remove the context

convert(2*Units:-Unit(Gy), units, J/kg)

2*Units:-Unit(J/kg)

(4)

` `After that, the context pannel does not offer conversion to Gray anymore (but to other units)

2*Units:-Unit(J/kg)

2*Units:-Unit(J/kg)

(5)

NULL

Lets do a calculation

2*Units:-Unit(Gy)-2*Units:-Unit(J/kg)

2*Units:-Unit(Gy)-2*Units:-Unit(J/kg)

(6)

simplify(2*Units:-Unit(Gy)-2*Units:-Unit(J/kg))

0

(7)

NULL


 

Download Unit_conversion.mw

The problem with your algorithm is the break statement that terminates the inner loop without defining a condition for t[j+1].

When the outer loop continues and increments j from 2 to 3 then this statement

assigns t[3] to u2[0]. t[3] however has no numeric value assigned to and Maple starts evaluating symbolic expressions. This blows up the whole calculation without giving any usefull results.

 

Attached is your code with debugging statements that allow you to investigate line by line the computation.

?worksheet,interactive,debugger explains how to use it.

NULL

 

restart;

 

dbg:=proc ()

DBG> quit

showstat(dbg)


dbg := proc()
local HAM, TOL, x, N, h, M, t, alpha, f1, f2, f3, g1, g2, j, u1, u2, u3, v1, v2, i,
kf1, kf2, kf3, kg1, kg2, U;
   1   HAM := [1];
   2   Digits := 30;
   3   TOL := 1/1000;
   4   x[0] := 0;
   5   N := 5000;
   6   h := .1e-2;
   7   M := 20;
   8   t[0] := .6;
   9   alpha := 0.;
  10   f1 := (x, u1, u2, u3, v1, v2) -> u2;
  11   f2 := (x, u1, u2, u3, v1, v2) -> u3;
  12   f3 := (x, u1, u2, u3, v1, v2) -> u2^2-2*u1*u3-v1^2;
  13   g1 := (x, u1, u2, v1, v2) -> v2;
  14   g2 := (x, u1, u2, v1, v2) -> 2*u2*v1-2*u1*v2;
  15   for j from 0 while j <= M do
  16       u1[0] := 0;
  17       u2[0] := t[j];
  18       u3[0] := 0;
  19       v1[0] := .8;
  20       v2[0] := 0;
  21       for i from 0 while i <= N-1 do
  22           DEBUG(is((i = 221)*`and`(j = 2)));
  23           kf1[i,1] := f1(x[i],u1[i],u2[i],u3[i],v1[i],v2[i]);
  24           kf2[i,1] := f2(x[i],u1[i],u2[i],u3[i],v1[i],v2[i]);
  25           kf3[i,1] := f3(x[i],u1[i],u2[i],u3[i],v1[i],v2[i]);
  26           kg1[i,1] := g1(x[i],u1[i],u2[i],u3[i],v1[i],v2[i]);
  27           kg2[i,1] := g2(x[i],u1[i],u2[i],u3[i],v1[i],v2[i]);
  28           kf1[i,2] := f1(x[i]+1/2*h,u1[i]+1/2*h*kf1[i,1],u2[i]+1/2*h*kf2[
                 i,1],u3[i]+1/2*h*kf3[i,1],v1[i]+1/2*h*kg1[i,1],v2[i]+1/2*h*
                 kg2[i,1]);
  29           kf2[i,2] := f2(x[i]+1/2*h,u1[i]+1/2*h*kf1[i,1],u2[i]+1/2*h*kf2[
                 i,1],u3[i]+1/2*h*kf3[i,1],v1[i]+1/2*h*kg1[i,1],v2[i]+1/2*h*
                 kg2[i,1]);
  30           kf3[i,2] := f3(x[i]+1/2*h,u1[i]+1/2*h*kf1[i,1],u2[i]+1/2*h*kf2[
                 i,1],u3[i]+1/2*h*kf3[i,1],v1[i]+1/2*h*kg1[i,1],v2[i]+1/2*h*
                 kg2[i,1]);
  31           kg1[i,2] := g1(x[i]+1/2*h,u1[i]+1/2*h*kf1[i,1],u2[i]+1/2*h*kf2[
                 i,1],u3[i]+1/2*h*kf3[i,1],v1[i]+1/2*h*kg1[i,1],v2[i]+1/2*h*
                 kg2[i,1]);
  32           kg2[i,2] := g2(x[i]+1/2*h,u1[i]+1/2*h*kf1[i,1],u2[i]+1/2*h*kf2[
                 i,1],u3[i]+1/2*h*kf3[i,1],v1[i]+1/2*h*kg1[i,1],v2[i]+1/2*h*
                 kg2[i,1]);
  33           kf1[i,3] := f1(x[i]+1/2*h,u1[i]+1/2*h*kf1[i,2],u2[i]+1/2*h*kf2[
                 i,2],u3[i]+1/2*h*kf3[i,2],v1[i]+1/2*h*kg1[i,2],v2[i]+1/2*h*
                 kg2[i,2]);
  34           kf2[i,3] := f2(x[i]+1/2*h,u1[i]+1/2*h*kf1[i,2],u2[i]+1/2*h*kf2[
                 i,2],u3[i]+1/2*h*kf3[i,2],v1[i]+1/2*h*kg1[i,2],v2[i]+1/2*h*
                 kg2[i,2]);
  35           kf3[i,3] := f3(x[i]+1/2*h,u1[i]+1/2*h*kf1[i,2],u2[i]+1/2*h*kf2[
                 i,2],u3[i]+1/2*h*kf3[i,2],v1[i]+1/2*h*kg1[i,2],v2[i]+1/2*h*
                 kg2[i,2]);
  36           kg1[i,3] := g1(x[i]+1/2*h,u1[i]+1/2*h*kf1[i,2],u2[i]+1/2*h*kf2[
                 i,2],u3[i]+1/2*h*kf3[i,2],v1[i]+1/2*h*kg1[i,2],v2[i]+1/2*h*
                 kg2[i,2]);
  37           kg2[i,3] := g2(x[i]+1/2*h,u1[i]+1/2*h*kf1[i,2],u2[i]+1/2*h*kf2[
                 i,2],u3[i]+1/2*h*kf3[i,2],v1[i]+1/2*h*kg1[i,2],v2[i]+1/2*h*
                 kg2[i,2]);
  38           kf1[i,4] := f1(x[i]+h,h*kf1[i,3]+u1[i],h*kf2[i,3]+u2[i],h*kf3[i
                 ,3]+u3[i],h*kg1[i,3]+v1[i],h*kg2[i,3]+v2[i]);
  39           kf2[i,4] := f2(x[i]+h,h*kf1[i,3]+u1[i],h*kf2[i,3]+u2[i],h*kf3[i
                 ,3]+u3[i],h*kg1[i,3]+v1[i],h*kg2[i,3]+v2[i]);
  40           kf3[i,4] := f3(x[i]+h,h*kf1[i,3]+u1[i],h*kf2[i,3]+u2[i],h*kf3[i
                 ,3]+u3[i],h*kg1[i,3]+v1[i],h*kg2[i,3]+v2[i]);
  41           kg1[i,4] := g1(x[i]+h,h*kf1[i,3]+u1[i],h*kf2[i,3]+u2[i],h*kf3[i
                 ,3]+u3[i],h*kg1[i,3]+v1[i],h*kg2[i,3]+v2[i]);
  42           kg2[i,4] := g2(x[i]+h,h*kf1[i,3]+u1[i],h*kf2[i,3]+u2[i],h*kf3[i
                 ,3]+u3[i],h*kg1[i,3]+v1[i],h*kg2[i,3]+v2[i]);
  43           u1[i+1] := u1[i]+1/6*h*(kf1[i,1]+2*kf1[i,2]+2*kf1[i,3]+kf1[i,4]
                 );
  44           u2[i+1] := u2[i]+1/6*h*(kf2[i,1]+2*kf2[i,2]+2*kf2[i,3]+kf2[i,4]
                 );
  45           u3[i+1] := u3[i]+1/6*h*(kf3[i,1]+2*kf3[i,2]+2*kf3[i,3]+kf3[i,4]
                 );
  46           v1[i+1] := v1[i]+1/6*h*(kg1[i,1]+2*kg1[i,2]+2*kg1[i,3]+kg1[i,4]
                 );
  47           v2[i+1] := v2[i]+1/6*h*(kg2[i,1]+2*kg2[i,2]+2*kg2[i,3]+kg2[i,4]
                 );
  48           if abs(v1[i+1]-1) <= TOL then
  49               N := i+1;
  50               print("Value of v = ",[(i+1)*h, v1[i+1], u2[N]]);
  51               if abs(u2[i+1]) <= TOL then
  52                   print("Value of f' = ",u2[i+1]);
  53                   break
                   else
  54                   if j = 0 then
  55                       t[j+1] := t[j]+(alpha-u1[i+1])/(i+1)/h;
  56                       U[j] := u2[i+1];
  57                       print("Value of u1[j] = ",%)
                       else
  58                       U[j] := u2[i+1];
  59                       print("Value of u1[j] = ",%);
  60                       t[j+1] := t[j]-(U[j]-alpha)*(t[j]-t[j-1])/(U[j]-U[j
                             -1]);
  61                       print("Value of t = ",%)
                       end if
                   end if
               end if
           end do;
  62       print(j,i)
       end do
end proc
 

 

stopat(dbg,49);

[dbg]

(1)

dbg()

2, 222

(2)

NULL


 

Download debug.mw

The reason is this line of code that (I assume) determines the integration constant

Since the solution contains Pi and c__1 as a name (one name too much)

solve throws and error

odesteps_fail_may_10_2024-2_debug_attempt.mw

 

PS.: Maybe someone can tell why I could not stopat or showstat the procedure

For a newbe, you have mastered the most demanding part (DynamicSystems package) quite well but you forgot to add a space to define multiplication and to declare the variables without a dot in an equation as functions of t. For variables with a dot Maple automatically assumes that they are functions of t.

Triple Cart derivation

with(DynamicSystems); with(Physics)

 

cart1eom := `m__1 `*(diff(v__1(t), t, t))+c__1*(diff(v__1(t), t))+k*(v__1(t)-v__2(t)) = F

`m__1 `*(diff(diff(v__1(t), t), t))+c__1*(diff(v__1(t), t))+k*(v__1(t)-v__2(t)) = F

(1)

cart2eom := m__2*(diff(v__2(t), t, t))+c__2*(diff(v__2(t), t))+k*(v__2(t)-v__3(t)) = k*(v__1(t)-v__2(t))

m__2*(diff(diff(v__2(t), t), t))+c__2*(diff(v__2(t), t))+k*(v__2(t)-v__3(t)) = k*(v__1(t)-v__2(t))

(2)

cart3eom := m__3*(diff(v__3(t), t, t))+c__3*(diff(v__3(t), t)) = k*(v__2(t)-v__3(t))

m__3*(diff(diff(v__3(t), t), t))+c__3*(diff(v__3(t), t)) = k*(v__2(t)-v__3(t))

(3)

F := alpha*k__m*k__g*V(t)/(R*r)-k__m^2*k__g^2*(diff(v__1(t), t))/(R*r^2)``

expand(cart1eom)

`m__1 `*(diff(diff(v__1(t), t), t))+c__1*(diff(v__1(t), t))+k*v__1(t)-k*v__2(t) = alpha*k__m*k__g*V(t)/(R*r)-k__m^2*k__g^2*(diff(v__1(t), t))/(R*r^2)

(4)

"(->)"

`m__1 `*(diff(diff(v__1(t), t), t))+c__1*(diff(v__1(t), t))+k*v__1(t)-k*v__2(t)-alpha*k__m*k__g*V(t)/(R*r)+k__m^2*k__g^2*(diff(v__1(t), t))/(R*r^2) = 0

(5)

collect(`m__1 `*(diff(diff(v__1(t), t), t))+c__1*(diff(v__1(t), t))+k*v__1(t)-k*v__2(t)-alpha*k__m*k__g*V(t)/(R*r)+k__m^2*k__g^2*(diff(v__1(t), t))/(R*r^2) = 0, [v__1(t), v__2, diff(v__1(t), t, t), diff(v__1(t), t)])

k*v__1(t)-k*v__2(t)+`m__1 `*(diff(diff(v__1(t), t), t))+(c__1+k__m^2*k__g^2/(R*r^2))*(diff(v__1(t), t))-alpha*k__m*k__g*V(t)/(R*r) = 0

(6)

"(->)"

cart1eom

(7)

eoms := [cart1eom, cart2eom, cart3eom]

[k*v__1(t)-k*v__2(t)+`m__1 `*(diff(diff(v__1(t), t), t))+(c__1+k__m^2*k__g^2/(R*r^2))*(diff(v__1(t), t))-alpha*k__m*k__g*V(t)/(R*r) = 0, m__2*(diff(diff(v__2(t), t), t))+c__2*(diff(v__2(t), t))+k*(v__2(t)-v__3(t)) = k*(v__1(t)-v__2(t)), m__3*(diff(diff(v__3(t), t), t))+c__3*(diff(v__3(t), t)) = k*(v__2(t)-v__3(t))]

(8)

NULL

sys_1 := DiffEquation(eoms, [V], [v__3])

_m1349275517664

(9)

a := StateSpace(sys_1)

_m1349214001216

(10)

"(->)"

a, b, c, d, inputcount, outputcount, statecount, sampletime, discrete, systemname, inputvariable, outputvariable, statevariable, parameters, systemtype, ModulePrint, ModuleContextMenu

(11)

"->"

"module() ... end module"

(12)

StateSpace(sys_1)

_m1349236337536

(13)

NULL

Download 403TripleCart_reply.mw

You use a(n,j) to determine elements of the Matrix Alanda. In Maple a(n,j) represents a two argument function. For your purposes the following code is sufficient

Alanda:=Matrix(16,16):

for n from 1 to 16 do
for j from 1 to 16 do

    Alanda[n,j]:=coeff(eq[n],A[j]):

end do:
end do:

For Digits:=10 the Matirx Alanda looks like this

For Digits:=100

There is a huge difference in the minimal matrix values.
With this big difference it can be expected that calcutations will differ or fail if the problem is I'll conditioned. 

 Try:

    end proc

In your code there is a "r" missing

Here is a solution derived with the help of MapleSim, where I used MapleSim to assemble a kinematic loop of 4 links including the constraint AC=BD

 

By symmetry the angles can be derived from the triangle AED with AE=AB/2=85 and E=CD/2=145.

Knowing that Angle A= Angle B and Angle C = Angle D, only Angle A and Angle D have to be calculated.

With the law of cosines I get Angle A = 52.56628938 deg and Angle D=27.74140544 deg.

 

 

Trick_question.msim

 

I cannot answer the why but provide a way for "full simplification" for the first expression group of the attached worksheet.

restart

kernelopts('version');

Physics:-Version();

`Maple 2024.0, X86 64 WINDOWS, Mar 01 2024, Build ID 1794891`

 

`The "Physics Updates" version in the MapleCloud is 1732. The version installed in this computer is 1724 created 2024, April 15, 17:29 hours Pacific Time, found in the directory C:\Users\cra\maple\toolbox\2024\Physics Updates\lib\`

(1)

with(RealDomain):

simplify(eval(MTM:-det(<
    a, b/2, d/2 |
    b/2, c, e/2 |
    d/2, e/2, f
   >), PDETools:-Solve(MTM:-det(<
      map(`**`, x + y, 2), seq[reduce = `+`](cat(_, 1 .. 3) **~ 2, _ in [x, y]) |
      x, x || (1 .. 3) |
      y, y || (1 .. 3) |
      <1 $ 4>
     >) = inner([cat](a .. f), [x**2, x*y, y**2, x, y, 1]),
    [cat](a .. f), 'independentof' = [x, y]))/MTM:-det(<
   <x || (1, 2, 3)> |
   <y || (1, 2, 3)> |
   <1 $ 3>
  >));
map(simplify,%)

-(1/4)*(x1^2-2*x1*x2+x2^2+(y1-y2)^2)*(x1^2-2*x1*x3+x3^2+(y1-y3)^2)*(x2^2-2*x2*x3+x3^2+(y2-y3)^2)

 

-(1/4)*((y1-y2)^2+(x1-x2)^2)*((y1-y3)^2+(x1-x3)^2)*((y2-y3)^2+(x2-x3)^2)

(2)
 

 

For the second expression group the map trick does not work. The length of the subexpression seems to play a role

simplify((x2 - x3)*x1 - x2*x4 + x3*x4)
                      (x2 - x3) (x1 - x4)

#but
simplify((x2 - x3)*x1 - x2*x4 + x3*x4 + (y1 - y4)*(y2 - y3))
       (x2 - x3) x1 - x2 x4 + x3 x4 + (y1 - y4) (y2 - y3)

I hope there will be an answer on the why.

Download Why_not_touch_subexpressions-reply.mw

What worked for me: Substitute the IC into the solution of ode,implict from vv and not into the original sol_no_IC. This way, no branches need to be selected.

restart;
ode := x*y(x)*diff(y(x), x) = (x + 1)*(y(x) + 1);
ic := y(1) = 1;
sol_no_IC_vv := dsolve(ode, implicit);
solve(%, {c__1});
subs(x = 1, ic, %);
solve(eval(sol_no_IC_vv, %), {y(x)})[];

 

5 6 7 8 9 10 11 Last Page 7 of 18