Preben Alsholm

13728 Reputation

22 Badges

20 years, 242 days

MaplePrimes Activity


These are answers submitted by Preben Alsholm

The first three commands should be assignments.

Also a is implicitly defined as a table, so to get the element with index 60 you ask for a[60], not a(60).

Thus you have

a[1]:=3;
a[2]:= 2;
a[3]:= -2;

for i from 3 to 60 do

a[i+1] := a[i] + 3*a[i-1] + 2*a[i-2];

end do:

a[60];
eval(a);

If you had wanted a vector and you knew its size to be 61 you could have started with a:=Vector(61).

If you don't know the length in advance you can use programmer indexing like the following, where you should notice that () replaces [].

restart;
a:=Vector();
a(1):=3;
a(2):= 2;
a(3):= -2;

for i from 3 to 60 do

a(i+1) := a(i) + 3*a(i-1) + 2*a(i-2);

end do:

a(60);





Go to the View menu. Then Header/Footer.

Maybe you need to elaborate some more on what you mean.

rest parameters do exist:

p:=proc(a,b) a*b,_rest end proc;
p(8,9);
p(8,9,s,y,i,o);

#Another example:

f:=x->x^2*`*`(_rest);
f(3);
f(3,4);
f(3,4,5,6,7);

#There is also the sequence modifier

g:=proc(s::seq(anything))  local S; S:=[s]; S[1]*S[-1] end proc;
g(3);
g(3,4,5);

But maybe that wasn't what you meant?

Following the advice given by Joe Riel I used 'Extensible XML Editor'.

I removed a nonvalid character and some closing tags without corresponding beginning tags.

The result is attached.matematik_input.mw

Try

ev:=Eigenvalues(P(14,k,1.,1.,1.));
Dimension(ev);

You may be surprised (as I was) that the dimension is 1.
That the element is a RootOf structure is not surprising though.
Since add(a[j],j=1..1/2) = 0 this explains why lambdak(k,14,1.,1.,1.) = 0.

Try to let lambdak return unevaluated if it doesn't receive numeric data by inserting the line

if not type([_passed],list(numeric)) then return 'procname(_passed)' end if;

right after the local-declaration.

To make sense your procedure lambdak seems to rely on a particular ordering of eigenvalues. No particular ordering is guaranteed in general, but in your case (a real symmetric matrix with numeric elements) it may be that eigenvalues are ordered increasingly.

You could turn the problem into an initial value problem with the 3 parameters g1, t1, f2 being  D(G)(0)=g1,D(T)(0)=t1,(D@D)(f)(0)=f2.

Then use fsolve to find g1, t1, and f2 by requiring that the conditions at x = b are satisfied.

This is what is done in the following lines.

restart;
nn:=2;
Nt:=0.5;
NB:=0.5;
Le:=0.5;
Pr:=2;
b:=18;
sys:={diff(G(x), x, x)+Le*f(x)*(diff(G(x), x))+(Nt/NB)*diff(T(x), x, x) = 0,diff(f(x), x, x, x)+f(x)*(diff(f(x), x, x))-(2*nn)/(nn+1)*(diff(f(x), x))^2 = 0,diff(T(x), x, x)/Pr+f(x)*(diff(T(x), x))+NB*(diff(T(x), x))*(diff(G(x), x))+Nt*(diff(T(x), x))^2=0};
bv:={G(0) = 1, G(b) = 0, T(0) = 1, T(b) = 0, f(0) = 0, (D(f))(0) = 1, (D(f))(b) = 0};
inits:={G(0) = 1, T(0) = 1, f(0) = 0, D(f)(0) = 1, D(G)(0)=g1,D(T)(0)=t1,(D@D)(f)(0)=f2};
ivpsol:=dsolve(sys union inits,numeric,parameters=[g1,t1,f2],output=listprocedure,maxfun=5000,range=0..b);
#It takes some experimenting (try plotting as below) to find reasonable values for the 3 parameters.
#The following 3 are reasonable:
ivpsol(parameters=[0.1,-0.2,-1.1]):
plots[odeplot](ivpsol,[x,T(x)],0..b,thickness=3,symbol=circle,style=point,symbolsize=13,color=black);
plots[odeplot](ivpsol,[x,G(x)],0..b,thickness=3,symbol=circle,style=point,symbolsize=13,color=black);
plots[odeplot](ivpsol,[x,f(x)],0..b,thickness=3,symbol=circle,style=point,symbolsize=13,color=black);
#Pulling out the 3 procedures for G, T, and f':
Gp,Tp,f1p:=op(subs(ivpsol,[G(x),T(x),diff(f(x),x)]));
#3 procedures accepting parameter values as input and producing G(b), T(b), and f'(b), respectively:
pg:=proc(gg1,tt1,ff2)
   ivpsol(parameters=[gg1,tt1,ff2]);
   Gp(b)
end proc;  
pT:=proc(gg1,tt1,ff2)
   ivpsol(parameters=[gg1,tt1,ff2]);
   Tp(b)
end proc;
pf1:=proc(gg1,tt1,ff2)
   ivpsol(parameters=[gg1,tt1,ff2]);
   f1p(b)
end proc;
#Now requiring the conditions at b be satisfied:
par:=fsolve({pg,pT,pf1},[.1,-.2,-1.1]);
#Setting the parameters just found:
ivpsol(par);
#The following 3 should be approximately zero:
Gp(b);
Tp(b);
f1p(b);

You could try replacing 0 with 'undefined'.

A:=Matrix([[0, 0, 1, 1, 0, 0],
[0, 1, 1, 1, 1, 0],
[0, 1, 2, 2, 1, 0],
[0, 1, 1, 1, 1, 0],
[0, 0, 1, 1, 0, 0]]);

B:=subs(0=undefined,A);
plots:-matrixplot(B,axes=boxed);

You could use 'add' instead of 'sum' as in

add(diff( (x^2-1)^i,[x$i]),i=0..4);

or if you don't include i=0 you could omit the brackets:

add(diff( (x^2-1)^i,x$i),i=1..4);

'add' is recommended by Maple instead of 'sum' when the range is concrete as in your case. 

Here are two ways. The first uses 'solve';  the second uses 'fsolve'.

I have added one equation to the ones you gave.

eq1:=X1+X2+X3=1;
eq2:=X3=T*X1^2*exp(.12/T);
eq3:=X1*X2+X3*T=3;
#Using solve
res:=solve({eq1,eq2,eq3},{X1,X2,X3});
X:=subs(res,[X1,X2,X3]);
plots:-spacecurve(X,T=1..10,axes=boxed,thickness=3);
#Using fsolve.
#The procedure Xf returns unevaluated if it receives input t not of type 'realcons'.
#Otherwise Xf(t) returns the sequence X1,X2,X3 and Xf[i](t) returns Xi (i=1..3).
Xf:=proc(t) local res;
if not type(t,realcons) then return 'procname(_passed)' end if;
res:=op(subs(fsolve(eval({eq1,eq2,eq3},T=t),{X1,X2,X3}),[X1,X2,X3]));
if type(procname,indexed) then res[op(1,procname)] else res end if;
end proc;
Xf(1.2345);
Xf[2](1.2345);
Xf(t);
Xf[3](t);
plots:-spacecurve([Xf[1],Xf[2],Xf[3]],1..10,axes=boxed,thickness=3);
plots:-spacecurve([Xf[1](t),Xf[2](t),Xf[3](t)],t=1..10,axes=boxed,thickness=3);

By looking at the two procedures in the module Explore (explore and ModuleApply) you will see that constants are taken away from the variables in the local procedure explore:

v := `minus`(indets(e, And('name', Non('last_name_eval'))), {constants});

Thus one could easily modify Explore to include an optional argument e.g. like this

'skip'::{name,{set,list}(name)}:={}

and then add to the sequence of constants the variables in 'skip'.

Without modifying anything you could just redefine the variable 'constants' like in this simple example:

Explore(int(sin(a*x),x=0..b));
constants:=constants,b;
Explore(int(sin(a*x),x=0..b));

My correction about u was wrong. I didn't look carefully enough.

I have looked more carefully at the problem now and the problem is with series(s2,poles,1). You need a higher value of the order than 1, 4 should do it.

restart;
with(MultiSeries):
s2:=(1/(2*Pi)+2*u/(1+u^2))^3/(1+u^2);
series(s2,u=I,1);
series(s2,u=I,2);
series(s2,u=I,3);
s:=convert(series(s2,u=I,4),polynom);
coeff(s,(u-I)^(-1));
#residue directly:
simplify(residue(s2,u=I));
##################

 

With your big expression defined as A_1 the following should work.

with(MultiSeries);
 _EnvExplicit := true;
ord:=4: #The order used in series
h:=[]:# set up a list h to store the results of integrating the terms in phi
for z in op(A_1) do
s1a := expand(z):
s1 := simplify(remove(has, z, psi),size);
s2:=subs(cos(k*phi)=((1-u^2) / (1+u^2)), sin(k*phi)=((2*u) / (1+u^2)),s1)*1/(1 + u^2);
poles1 := singular(s2, u);
t1a := map(rhs@op, [poles1]);
t1:=select(x->Im(evalf(x))>0,t1a);
poles2 := [];
for i to nops(t1) do poles2 := [op(poles2), u = t1[i]] end do;
poles := poles2;
s:=convert~(series~(s2,poles,ord),polynom);
p:=((lhs-rhs)~(poles))^~(-1);
residues1:=coeff~(s,p);
residue_total1 := 0;
for i to nops(residues1) do residue_total1 := simplify(residue_total1 + residues1[i], size) end do;
result1 := simplify(((2*Pi*I)*residue_total1),size);
h:=[op(h),result1];
end do:

h;

[y(t), diff(y(t),t)>0] is a conditional event. The event is that y(t) becomes 0, but under the condition that y'(t) > 0.

Similarly,

events = [[[diff(y(t),t),y(t)<0], halt]]

would make the integration stop when y'(t) = 0, but only if y(t) < 0.

But you are right; the help page for dsolve,events is not easy reading.

You have a typing error. u = t1[i] surely was meant to be u:=t1[i].

I'm wondering (as I was in your previous and related question) why you make substitutions for sin(m*phi) and cos(m*phi). These don't appear in your expression.

Also I think you could simplify the following two commands:

p1:=(beta,Q,P) -> select(x->Im(evalf(eval(x,[beta=beta,Q=Q,P=P])))>0,t1a);
t1:=p1(beta,Q,P):

to just

t1:=select(x->Im(evalf(x))>0,t1a);

Instead of eval(V[x],x=0) =1 you should write

D[1](V)(0,y)=1

which means the partial derivative of V w.r.t. the first variable at (0,y) .

The appearance of a RootOf expression is not necessarily due to a bug. See the help page for RootOf.

You should be able to upload a Maple file by using the icon with a thick green arrow (the last one on the menu).

 

Example.

Try the following two commands.

restart;
solve(d^3-32*(x-l)=0,d);
   
solve({d^3-32*(x-l)=0,t=d},{d,t});
              
In Maple 12 (and also in Maple 15) the first one results in 3 explicit results, whereas the second results in RootOf expressions. This has nothing to do with document mode. In fact I always use worksheet mode.

First 132 133 134 135 136 137 138 Last Page 134 of 160