Preben Alsholm

13743 Reputation

22 Badges

20 years, 310 days

MaplePrimes Activity


These are answers submitted by Preben Alsholm

restart;
with(LinearAlgebra):
#x:=2:
g:=Matrix([[3*ξ+5*x,8*x-7*ξ,2*ξ],[ξ,4*ξ+9*x,7*ξ],[5*ξ,ξ,4*x-6*ξ]]):
h:=RandomMatrix(3):
p:=g.h:
#You could make a function of x as follows:
E00:=unapply(map(int,p,ξ=1..3),x):
#Then use it like this:
E00(x);
E00(2);
E00(16);

I don't see any way of simplifying the solution as polynomials of degree 5 and above cannot in general be solved in terms of radicals. Your polynomial does have a special structure, so there could be hope. However, experimentation with randomly chosen parameter values (here integers between 1 and 9) suggests that there is no hope of a general formula.

restart;
test := [[lambda[h] = RootOf((n^2*tau[h]^2-2*n^2*tau[f]*tau[h]+n^2*tau[f]^2)*_Z^5+(-8*a*n^2*tau[h]+8*L*b*n^2*tau[h]-4*n*tau[f]*L*b+tau[h]^2*n+5*n^2*tau[f]*tau[h]+4*L*b*n*tau[h]+n^3*tau[h]^2-5*n^2*tau[f]^2+8*n^2*tau[f]*a-n^3*tau[f]^2-n*tau[f]^2-8*n^2*tau[f]*L*b)*_Z^4+(-32*a*n^2*b*L+16*n*b^2*L^2+20*n^2*tau[f]*L*b-2*n^3*tau[h]^2+tau[h]*L*b-3*tau[f]*n*a-2*tau[h]^2*n+16*n^2*b^2*L^2-12*L*b*n^2*tau[h]-4*n^2*tau[f]*tau[h]+12*n*tau[f]*L*b-16*n*b*L*a-4*L*b*n*tau[h]+tau[f]*L*b-3*a*n*tau[h]+16*a^2*n^2+7*n^2*tau[f]^2+2*n^3*tau[f]^2+10*a*n^2*tau[h]+4*b^2*L^2-3*n^2*tau[h]^2-22*n^2*tau[f]*a+2*n*tau[f]^2)*_Z^3+(-6*b^2*L^2-24*n^2*b^2*L^2-24*n*b^2*L^2-n*tau[f]^2+n^3*tau[h]^2+24*n*b*L*a+5*a*n*tau[h]-16*n^2*tau[f]*L*b-n^3*tau[f]^2-12*n*tau[f]*L*b-3*n^2*tau[f]^2-24*a^2*n^2+48*a*n^2*b*L+4*tau[f]*n*a+2*n^2*tau[h]^2+n^2*tau[f]*tau[h]-tau[h]*L*b+4*L*b*n^2*tau[h]+tau[h]^2*n+18*n^2*tau[f]*a-2*tau[f]*L*b)*_Z^2+(-tau[f]*n*a-8*n*b*L*a-16*a*n^2*b*L+tau[f]*L*b-2*a^2*n+8*a^2*n^2-2*a*n^2*tau[h]+8*n^2*b^2*L^2-2*a*n*tau[h]-4*n^2*tau[f]*a+2*b^2*L^2+8*n*b^2*L^2+4*n^2*tau[f]*L*b+4*n*tau[f]*L*b)*_Z+a^2*n)]]:
R:=rhs(test[1,1]);
p:=op(R): #The polynomial
#There is at least one real root between 0 and 1:
eval(p,_Z=0);
eval(p,_Z=1);
nms:=[op(indets(R,name))]; #The list of parameters
param1:= nms=~[1,2,3,4,5,6]; #Initial experiment
R1:=eval(R,param1);
allvalues(R1);
evalf(%);
r:=rand(1..9): #Chooses random integers between 1 and 9
param:= nms=~[seq(r(),k=1..6)];
R1:=eval(R,param);
allvalues(R1);
evalf(%);
#This loop shows that mostly no solution in terms of radicals are found:
to 10 do
   param:= nms=~[seq(r(),k=1..6)];
   R1:=eval(R,param);
   res:=allvalues(R1);
   if has([res],RootOf) then res:=evalf(res) else res end if;
   print(res)
end do:
#Giving up finding exact roots and using fsolve to find roots between 0 and 1:
to 100 do
   param:= nms=~[seq(r(),k=1..6)];
   F:=eval(op(R),param);
   res:=fsolve(F,_Z=0..1);
   if res=NULL then print("None") else print(res) end if
end do:

Even for mm=1 and nn=1 it is impossible:

f:=t->add(A[m]*cos(m*w*t+m*t0),m=0..1);
g:=phi->add(B[n]*cos(n*phi+n*phi0),n=0..1);

fg:=unapply(combine(f(t)*g(phi)),t,phi);
h:=(t,phi)->add(add(C[m,n]*cos(m*w*t+n*phi+cmn),n=0..1),m=0..1);
eq:=h(t,phi)-fg(t,phi)=0;
diff(eq,phi);
diff(%,t);
subs(w*t=s-phi,%);
diff(%,phi);
#Result: A[1]*B[1]*sin(-s+2*phi-t0+phi0)*w = 0, which means that one of A[1], B[1], w must be zero.

You may want to take a look at ImportMatrix as it has an option 'skiplines=n'.

So if your file looks like this:

This is text
bla bla bla
ååååøøøææøælopk567
----------------
78 89 45
56 7 -98

and is saved in F:/test.txt  then do

ImportMatrix("F:/test.txt",delimiter=" ",skiplines=4);

There are a couple of obvious problems:

(1) Presumably you want to use the package T, so you need to do with(T); or use S:=T:-sin(t);

(2) You wrote DS:=diff(DS,t): This would make DS=0 and subsequently DDS=0. You probably meant DS:=diff(S,t):

However, the inhomogeneous term is irrelevant when it comes to the angular eigenfrequency omega. That one is
(1/2)*sqrt(4*c[0]*m[1]-d[0]^2)/m[1] for the ODE as written. And as d[0] is small it can be neglected so it is roughly sqrt(c[0]/m[1]) as you say.

Notice that even after doing  with(T); the result of dsolve(diff(x(t),t,t)+x(t)=0); is x(t) = _C1*sin(t)+_C2*cos(t), which means it is not expressed in terms of the T-versions but the global versions, which are available as :-sin and :-cos. Try
res:=dsolve(diff(x(t),t,t)+x(t)=0);
eval(res,t=360);
subs({:-sin = sin,:-cos=cos},res);
eval(%,t=360);

You may want to avoid redefining sin and cos and consider changing variables in the ODE, i.e. using another time tau:

PDEtools:-dchange({t=tau*k,x(t)=X(tau)},ODE,[tau,X]);
#And then pick k to fit your needs.
#If you use the angle in degrees as time tau, then you have tau = t*omega*180/Pi, so you should pick
k = Pi/(omega*180).
An additional comment. Why not just write s:=x; v:=D(x): a:=(D@D)(x):




If M > m >0 then it appears from the animation below that there is one real solution:
eq:=k = ln(( M-m)/m/(k-1));
res:=solve(eq,k);
#Animation ('eq' only depends on M/m, so we may safely use m=1):
plots:-animate(plot,[eval([k,rhs(eq),res],m=1),k=0..5],M=5..20);

If M < m there will be two real solutions when also M>0:

restart;
eq:=k = ln(( M-m)/m/(k-1));
res:=solve(eq,k,AllSolutions);
z:=op(indets(res,`local`));
res1:=subs(z=0,res);
res2:=subs(z=-1,res);
plots:-animate(plot,[eval([k,rhs(eq),res1,res2],m=1),k=-5..5],M=-5..10);
#This shows that there is tangency when k = 0 and M = 0:
solve({diff(eq,k),eq},{k,M});



It turns out that an explicit list is needed:

phi:=(x,y,z)->[2*x/(x^2+y^2+(-1+z)^2),2*y/(x^2+y^2+(-1+z)^2), 1+2*(-1+x)/(x^2+y^2+(-1+z)^2)];

In a procedure `transform/objects` local to the plottools package there is a conditional statement depending on the value of 'outdim' as defined by outdim := nops(f(i,j,outdim)); where f in our case is phi and the arguments to f are just (local) names. If phi(x,y,z) is seen as a sum of two terms, which it is in your original version, then outdim:=2.
However, if phi is defined as above, nops(phi(x,y,z)) returns 3 because there are 3 elements in the list.

In the 2-dim case there happens to be agreement between the two versions! Pure luck!

The example with Q below exhibits the problem. So you could define A implicitly or explicitly to be a table.

restart;
Q:=seq(a[k],k=1..3):
Q[1]:=3;
restart;
with(LinearAlgebra):
interface(rtablesize=infinity):
#In this loop A is implicitly defined as a table:
for k from 1 to 21 do A[k]:=Matrix(18) end do:
A[1]:=IdentityMatrix(18);
whattype(eval(A));

You should use 'add' instead of 'sum'.

'add' is for summations with concrete limits like in your case k = 0..3.

'sum' on the other hand tries to find a formula so that it actually might handle k=0..n, where n is not assigned a value. Also, and more importantly, 'add' and 'sum' have different evaluation rules: 'sum' evaluates its argument before acting, whereas 'add' does not. This means that MatrixPower(x,k) gets evaluated before k is known! That is the reason for the weird looking result you get. It is correct, though (at least in my example below).

Try the following:

with(LinearAlgebra);
A:=RandomMatrix(2);
c := 5;
x:=c*A;
MatrixPower(x,k);
'MatrixPower'(x,k);
sum(MatrixPower(x,k), k = 0..3);
simplify(%);
#You may or may not need evalf (A is randomly chosen)
add(MatrixPower(x,k), k = 0..3);
#Enclosing 'MatrixPower' in unevaluation quotes:
sum('MatrixPower'(x,k), k = 0..3);
#Notice that MatrixPower is more general than just using x^k (k concrete).
?MatrixPower
sum(x^k, k = 0..3);
add(x^k,k=0..3);
sum(MatrixPower(x,k),k=0..n);
eval(%,n=3);
simplify(%);
evalf(%);
#Compare with
add(x^k,k=0..3);


By enclosing the arguments in curly brackets you make them optional keyword parameters. In your first two calls to h1, there is no matching argument, so the default applies.

If you don't h1 to accept any other arguments than the ones explicitly given in the definition of h1, then end the argument sequence with a dollar sign:

h1 := proc( { [n,N] :: {positive,identical(n)=positive} := 1 }
         , { [l,L] :: {list,identical(l)=list} := [1,1,1] },$ )
  local %n,%l;
  if type(n,positive) then %n:=n; else %n:=rhs(n); end if;
  if type(l,list) then %l:=l; else %l:=rhs(l); end if;
      print([n,whattype(n),is(n,positive)]);
      print([%n,whattype(%n),is(%n,positive)]);
      print([l,whattype(l)]);
      print([%l,whattype(%l)]);
end proc :


I see nothing wrong with something like this (sd introduced only for a check).

Notice that the default doesn't have to have the declared type!

p:=proc({ [s,seed]::posint:= NULL} )
  local sd;
  if s<>NULL then sd:=randomize(s) end if;
  print([s,sd]);
  rand()
end proc;

p();
p(seed=45);

Does this do what you want?

restart;
g1:=proc({[n,N]::posint:=1})
  return g2(:-n=n);
end proc;
g2:=proc({n::posint:=1})
  return n^2;
end proc;

 

#And for your last question:

g3:=proc(n::{posint,identical(n)=posint}:=1)
local nn;
if type(n,posint) then nn:=n else nn:=rhs(n) end if;
return nn^2;
end proc;
g3(6);
g3(n=6);
g3();

If I understand your intention correctly, you want to turn the ode into a system of 3 first order odes.

If that is correct then you can use 'convertsys' from the DEtools package.

Due to an interesting bug (?) in DEtools, I begin by replacing the right hand side by just 'p(t)':

sys := diff(y(t),t$3) + 3*diff(y(t),t$2) + 5*diff(y(t),t)  = p(t);
#See the help page for convertsys for the arguments to convertsys. I chose xp as the name of the vector of derivatives.
DEtools[convertsys](sys,{},y,t,x,xp);
#Then replace 'p(t)' by the correct right hand side:
res:=subs(p(t)=diff(u(t),t$3) + diff(u(t),t$2) + diff(u(t),t),%);
#The system:
res[1];

#The translation (not exactly the one you mentioned, but probably what you meant):

res[2];


PS. I have submitted an SCR about the bug.

I suggest making the following changes besides ending the loop with a colon.

C:=Vector():
E:=Vector():

#Don't assign to i explicitly, but let the loop do it (and start from 1)

for i from 1 while t.....

C(i):=t:  #Notice the use of a parenthesis, not square brackets: Programmer indexing
E(i):=p_2:  #Same thing
#Again: Don't assign to i. The loop does it.

Outside the loop:

with(plots):
pointplot([C,E]);

#You could also (if you like) tighten up the definitions of S, A_zu, and A_ab a little (inside the loop):

S:=piecewise(
   t <= 9.5,s_1/1000,
   t <= 12.875,s_2/1000,
   t <= 15.5,s_3/1000,
   t <= 20.75,s_4/1000,
   t <= 26.75,s_5/1000
                       );
if S >= 0.01 then A_zu := 0 else A_zu := b*h-b*S end if;
if S < 0.01 or S >= 0.018 then A_ab := b*h-b*S else A_ab:=0 end if;


It appears that you have a couple of errors in your procedure: (1) a missing 'then' , (2) a missing condition in 'if lambda' (presumably you mean 'if lambda < lambda0'), and (3) 'e^(...)' should be 'exp(...)'.
I had problems in copying my corrected procedure into MaplePrimes. I suspect (1) and (2) are actually MaplePrimes copying mistakes.

There is no need for Cp (it doesn't hurt, though).

So maybe this is what you intended:

Cplot := proc (beta, lambda)
local lambda0;
lambda0 := 0.22e-1*beta^2+(7/1000000000000000)*beta+5.6;
if lambda < lambda0 then
   0.1e-2
else
  ((1/2)*lambda+(1/2)*(-1)*0.22e-1*beta^2+(1/2)*(-5.6))*exp((-1)*.17*lambda)
end if
end proc;

#Testing:
Cplot(5,40);
#But symbolic input gives an error:
Cplot(a,b);
#Use unevaluation quotes to prevent that
'Cplot'(a,b);
#So here is the plot:
plot([seq('Cplot'(k*5,lambda),k=0..6)],lambda=0..60);

#An alternative to using unevaluation quotes outside the procedure is to take care of the problem inside as is done in this version:
Cplot := proc (beta, lambda)
local lambda0;
if not type([beta,lambda],list(realcons)) then return 'procname(_passed)' end if;
lambda0 := 0.22e-1*beta^2+(7/1000000000000000)*beta+5.6;
if lambda  < lambda0 then
   0.1e-2;
else
   ((1/2)*lambda+(1/2)*(-1)*0.22e-1*beta^2+(1/2)*(-5.6))*exp((-1)*.17*lambda)
end if
end proc;

plot([seq(Cplot(k*5,lambda),k=0..6)],lambda=0..60);

We have no way of actually checking your worksheets since we don't have the matrices

PsiST := ImportMatrix("L:/MapleTabellen/[PsiTST]_NT=5e17,xT=100,ET=1700.dat", source = delimited);

FD32 := ImportMatrix("L:/FD/FD32_M.txt", source = delimited);

From a very superficial look at your worksheets it appears that the value of Digits is the default, i.e. 10.

You may want to raise that.

First 124 125 126 127 128 129 130 Last Page 126 of 160