I want to plot the motion of a particle under the influence of gravity and constrained to move on the inside of a unit sphere. The parametric equation of the sphere is
From Hamilton’s principle, we have the two ode’s in u(t) and v(t) given below, along with their initial conditiions>sys:={diff(u(t),t)*cos(v(t))^2=1, diff(v(t),t$2)+sin(v(t))*cos(v(t))* diff(u(t),t)^2+cos(v(t))=0, u(0)=0,v(0)=-Pi/4,D(v)(0)=0}
>sol:=dsolve(sys,{u(t),v(t)},type=numeric,output=listprocedure); >U:=subs(sol,u(t)); >V:=subs(sol,v(t)); >alpha:=subs(u=U(t),v=V(t)},X); ****Error,(in unknown) cannot evaluate boolean.****
I wanted to use alpha as follows
Fortunately, we can get a plot by creating a list and plotting the contents of that list.
It seems to me that this listp should be unnecessary. Is there any way to do this without the listp?
The functions resulting from the numerical solution are only designed to work with numerical actual parameters. They cannot cope with symbolic parameters.
Try the following rearrangement. I modified the functions U and V to take account of symbolic actual parameters.
These refer to U1 and V1 which are your original functions. The resulting spacecurve now plots.
I will leave it to others to produce a more elegant solution.
> X:=[cos(u)*cos(v),sin(u)*cos(v),sin(v)]; > sys:={diff(u(t),t)*cos(v(t))^2=1, diff(v(t),t$2)+sin(v(t))*cos(v(t))* > diff(u(t),t)^2+cos(v(t))=0, u(0)=0,v(0)=-Pi/4,D(v)(0)=0}; > sol:=dsolve(sys,{u(t),v(t)},type=numeric,output=listprocedure): > U1:=subs(sol,u(t)): > V1:=subs(sol,v(t)): > U:=t->if type(t,constant) then U1(t) else 'U'(t)fi; > V:=t->if type(t,constant) then V1(t) else 'V'(t)fi; > alpha:=subs(u=U(t),v=V(t),X); > plots[spacecurve](alpha,t=0..15);
Premature evaluation strikes again! The "cannot evaluate boolean" comes from trying to evaluate U(t) or V(t) with a symbolic parameter t, when U and V will only work with numerical parameters. You could delay evaluation with quotes. This will work:
If you want to do it in two steps, obtaining alpha first, then you need two levels of quotes:
> alpha:= subs(u=''U(t)'',v=''V(t)'',X); alpha := [cos('U(t)') cos('V(t)'), sin('U(t)') cos('V(t)'),sin('V(t)')] > spacecurve(alpha,t=0..15);
I tried this (which you will recognize):
and reduced it to a first-order integral, which would require numerical solution.
Below I give 3 solutions.
The first defines alpha1 using two sets of apostrophes around U(t) and V(t), thus preventing evaluation twice.
The second redefines X to XX and uses variable-free syntax in spacecurve.
The third redefines U and V to U3 and V3. The latter two procedures return unevaluated when called with a non-numeric argument.
> restart; > X:=[cos(u)*cos(v),sin(u)*cos(v),sin(v)]: > XX:=[(cos@u)*(cos@v),(sin@u)*(cos@v),sin@v]: > sys:={diff(u(t),t)*cos(v(t))^2=1, diff(v(t),t$2)+sin(v(t))*cos(v(t))* > diff(u(t),t)^2+cos(v(t))=0, u(0)=0,v(0)=-Pi/4,D(v)(0)=0}: > sol:=dsolve(sys,{u(t),v(t)},type=numeric,output=listprocedure): > > U:=subs(sol,u(t)): > V:=subs(sol,v(t)): > alpha1:=subs({u=''U(t)'',v=''V(t)''},X): > alpha2:=subs({u=U,v=V},XX): > > U3:=proc(t) if type(t,numeric) then U(t) else 'U3'(t) fi end: > V3:=proc(t) if type(t,numeric) then V(t) else 'V3'(t) fi end: > alpha3:=subs({u=U3(t),v=V3(t)},X): > with(plots): > spacecurve(alpha1,t=0..15); > spacecurve(alpha2,0..15); > spacecurve(alpha3,t=0..15);
Here is a slightly less clumsy approach using the remember table for sysmbolic actuals, ie in U(t) and V(t):
> restart;with(plots); > X:=[cos(u)*cos(v),sin(u)*cos(v),sin(v)]; > sys:={diff(u(t),t)*cos(v(t))^2=1, diff(v(t),t$2)+sin(v(t))*cos(v(t))* > diff(u(t),t)^2+cos(v(t))=0, u(0)=0,v(0)=-Pi/4,D(v)(0)=0}; > sol:=dsolve(sys,{u(t),v(t)},type=numeric,output=listprocedure): > U:=subs(sol,u(t)): > V:=subs(sol,v(t)): > # now set alpha using symbolic form of U(t) and V(t) > alpha:=subs(u='U(t)',v='V(t)',X); > # now allow U and V to handle the special case of symbolic t > # using the remember table since > # it is impractical to use a conditional statement > U(t):='U'(t); > V(t):='V'(t); > # and now it all works > spacecurve(alpha,t=0..15);
It seems to work fine with this approach.
However, on a general point since this is something that is often a hurdle for Maple users, I think that the generated functions of this type should be set to handle non-constant actual parameters to yield a symbolic value.
I assume it hasn’t been done since it would interfere with other aspects of Maple.
I propose :
> sys:={diff(u(t),t)*cos(v(t))^2=1, > diff(v(t),t$2)+sin(v(t))*cos(v(t))*diff(u(t),t)^2+cos(v(t))=0, > u(0)=0,v(0)=-Pi/4,D(v)(0)=0}; > sol:=dsolve(sys,{u(t),v(t)},type=numeric); > X:=[tt->subs(sol(tt),cos(u(t))*cos(v(t))), > tt->subs(sol(tt),sin(u(t))*cos(v(t))), > tt->subs(sol(tt),sin(v(t))), > 0..15]; > with(plots,spacecurve); > spacecurve(X);
The problem is premature evaluation. One way to avoid this is to assign the procedures U and V so that they return unevaluated if the argument is nonnumeric. This can be automated with the following procedure (requires R5):
> Numeric := proc(V) > if nargs > 1 then map(procname,[args])[] > else proc(t) if t::numeric then V(t) > else 'procname'(t) fi > fi > end: > U,V := Numeric(subs(sol,[u,v](t))[]): > alpha := subs(u=U(t),v=V(t),X): > plots[spacecurve](alpha, t=0..15);
Another approach is to convert X to a list of procedures of t.
This can be accomplished with function composition.