Preben Alsholm

13728 Reputation

22 Badges

20 years, 249 days

MaplePrimes Activity


These are replies submitted by Preben Alsholm

@kinesimario As you write it there is nothing wrong once you have corrected ic2 as explained by Jarekk.

But why use a stiff solver?

deq2 := diff(x(t),t,t) = -x(t)/(x(t)^2+y(t)^2)^(3/2), diff(y(t), t,t) = -y(t)/(x(t)^2+y(t)^2)^(3/2);

ic2 := x(0) = 1, D(x)(0) = 0, y(0) = 0, D(y)(0) = 1;

rosen := dsolve({ic2, deq2}, type = numeric, range = 0 .. 2*Pi);

plots:-odeplot(rosen,[x(t),y(t)],0..2*Pi);

You may find some fun in trying the following:

rosen1 := dsolve({ic2, deq2}, numeric);
plots:-odeplot(rosen1,[x(t),y(t)],0..2*Pi,scaling=constrained);
?dsolve,interactive,numeric
rosen1(initial);
rosen1(initial=[1.5,0,0,1]);
plots:-odeplot(rosen1,[x(t),y(t)],0..33,scaling=constrained);
rosen1(initial=[2,0,0,1]);
plots:-odeplot(rosen1,[x(t),y(t)],-500..500,scaling=constrained);

If u is actually a function of two variables x and t, this construction won't work, but you can do any of the following.

restart;
DE:=diff(x(t),t)=cos(x(t));
IC:=x(0)=0;
u:=(x,t)->x^2+sin(t);
s := dsolve( {DE,IC }, numeric, output = listprocedure );
X:=subs(s,x(t));
U:=t->u(X(t),t);
plot( U, 0..10 );
#A somewhat clumsy alternative:
U:=tt->subs(s,u(x(t)(tt),tt));
plot( U, 0..10 );

#If you use output=operator the clumsy version becomes less so:

restart;
DE:=diff(x(t),t)=cos(x(t));
IC:=x(0)=0;
u:=(x,t)->x^2+sin(t);
s := dsolve( {DE,IC }, numeric, output = operator );
X:=subs(s,x);
U:=t->u(X(t),t);
plot( U, 0..10 );
#Alternatively, and not so clumsy this time:
U:=t->subs(s,u(x(t),t));
plot( U, 0..10 );

If u is actually a function of two variables x and t, this construction won't work, but you can do any of the following.

restart;
DE:=diff(x(t),t)=cos(x(t));
IC:=x(0)=0;
u:=(x,t)->x^2+sin(t);
s := dsolve( {DE,IC }, numeric, output = listprocedure );
X:=subs(s,x(t));
U:=t->u(X(t),t);
plot( U, 0..10 );
#A somewhat clumsy alternative:
U:=tt->subs(s,u(x(t)(tt),tt));
plot( U, 0..10 );

#If you use output=operator the clumsy version becomes less so:

restart;
DE:=diff(x(t),t)=cos(x(t));
IC:=x(0)=0;
u:=(x,t)->x^2+sin(t);
s := dsolve( {DE,IC }, numeric, output = operator );
X:=subs(s,x);
U:=t->u(X(t),t);
plot( U, 0..10 );
#Alternatively, and not so clumsy this time:
U:=t->subs(s,u(x(t),t));
plot( U, 0..10 );

You are more likely to get good answers if you provide us with the details, e.g. in the form of an uploaded worksheet or the complete lines of code pasted into your posting.

I don't have that problem in Maple 15. In Maple 12, however, I do. But if you change the range to 0..2*Pi as in

odeplot(res,[e1r(t),e1i(t)],0..2*Pi,refine=1);

the error doesn't appear. Alternatively, change the range in the assignment to res like this:

res:=dsolve(s1 union s2,numeric, method =rkf45_dae,abserr=10^(-10),relerr=10^(-10),range=0..Pi,maxfun = 0,output=listprocedure);

I don't have that problem in Maple 15. In Maple 12, however, I do. But if you change the range to 0..2*Pi as in

odeplot(res,[e1r(t),e1i(t)],0..2*Pi,refine=1);

the error doesn't appear. Alternatively, change the range in the assignment to res like this:

res:=dsolve(s1 union s2,numeric, method =rkf45_dae,abserr=10^(-10),relerr=10^(-10),range=0..Pi,maxfun = 0,output=listprocedure);

@nic_rf Well, then f(t) = 1-exp(-t) is the solution. The laplace transform method using f(0) = 0 gave two possible solutions, but with f ' (0) > 0 one is singled out, i.e. f(t) = 1-exp(-t).

@nic_rf Well, then f(t) = 1-exp(-t) is the solution. The laplace transform method using f(0) = 0 gave two possible solutions, but with f ' (0) > 0 one is singled out, i.e. f(t) = 1-exp(-t).

@PatrickT You can make use of 'satisfies' as in

RNN(M,1,'satisfies'(s->s::realcons and s>0 and s<30));

if you change RNN to accept as the third argument either a regular type or the special function 'satisfies'.

(This is still not perfect, since combining those two with And, Or, or Not won't work).

RNN:= proc(M::{Array,Matrix},k::posint, t::{type,specfunc(procedure,satisfies)}:=numeric,$)
  local U,d,i,dk;
  d:= [rtable_dims(M)];
  U:= remove(r -> hastype(M[op(subsop(k=r,d))],Not(t),'exclude_container'),[seq(i,i=d[k])]);
  M[op(subsop(k=U,d))]
end proc;

@PatrickT You can make use of 'satisfies' as in

RNN(M,1,'satisfies'(s->s::realcons and s>0 and s<30));

if you change RNN to accept as the third argument either a regular type or the special function 'satisfies'.

(This is still not perfect, since combining those two with And, Or, or Not won't work).

RNN:= proc(M::{Array,Matrix},k::posint, t::{type,specfunc(procedure,satisfies)}:=numeric,$)
  local U,d,i,dk;
  d:= [rtable_dims(M)];
  U:= remove(r -> hastype(M[op(subsop(k=r,d))],Not(t),'exclude_container'),[seq(i,i=d[k])]);
  M[op(subsop(k=U,d))]
end proc;

@PatrickT Type real doesn't exist, so in the call

RNN(M,1,real);

RNN will use the default type, i.e. numeric.   RNN(M,1,xxx); has the same effect.

In order to catch such user errors you could place a dollar sign at the end of the sequence of formal parameters, indicating thereby that no other arguments are allowed. Alternatively the third argument t::type could be made required.

RNN:= proc(M::{Array,Matrix},k::posint, t::type:=numeric,$)
  local U,d,i,dk;
  d:= [rtable_dims(M)];
  U:= remove(r -> hastype(M[op(subsop(k=r,d))],Not(t),'exclude_container'),[seq(i,i=d[k])]);
  M[op(subsop(k=U,d))]
end proc;

@PatrickT Type real doesn't exist, so in the call

RNN(M,1,real);

RNN will use the default type, i.e. numeric.   RNN(M,1,xxx); has the same effect.

In order to catch such user errors you could place a dollar sign at the end of the sequence of formal parameters, indicating thereby that no other arguments are allowed. Alternatively the third argument t::type could be made required.

RNN:= proc(M::{Array,Matrix},k::posint, t::type:=numeric,$)
  local U,d,i,dk;
  d:= [rtable_dims(M)];
  U:= remove(r -> hastype(M[op(subsop(k=r,d))],Not(t),'exclude_container'),[seq(i,i=d[k])]);
  M[op(subsop(k=U,d))]
end proc;

@PatrickT Here is a way.

M:=Matrix([[HFloat(undefined),HFloat(undefined),HFloat(undefined)],[1,2,3],[HFloat(undefined),HFloat(undefined),HFloat(undefined)],[4,5,6]]);
m:=LinearAlgebra:-RowDimension(M):
U:=NULL:
for i to m do
   if has(LinearAlgebra:-Row(M,i),HFloat(undefined)) then U:=U,i end if
end do;
U;
LinearAlgebra:-DeleteRow(M,[U]);

@PatrickT Here is a way.

M:=Matrix([[HFloat(undefined),HFloat(undefined),HFloat(undefined)],[1,2,3],[HFloat(undefined),HFloat(undefined),HFloat(undefined)],[4,5,6]]);
m:=LinearAlgebra:-RowDimension(M):
U:=NULL:
for i to m do
   if has(LinearAlgebra:-Row(M,i),HFloat(undefined)) then U:=U,i end if
end do;
U;
LinearAlgebra:-DeleteRow(M,[U]);

First 202 203 204 205 206 207 208 Last Page 204 of 230