Preben Alsholm

13728 Reputation

22 Badges

20 years, 249 days

MaplePrimes Activity


These are replies submitted by Preben Alsholm

@PatrickT I think that

try
.....
catch:
.....
end try;

catches all errors (not warnings!).

The addition of StringTools:-FormatMessage after the colon just has the effect of printing the message. If you want the relevant message printed you can use

StringTools:-FormatMessage(lastexception[2..-1]);

Example:

a:="56";
try
sin(a)
catch: StringTools:-FormatMessage(lastexception[2..-1]);
45
end try;

@samiyare 

Try

fsolve(p(-1.2, pp2) = 0, pp2 = -10 .. 10);
plot(p(-1.2, pp2) , pp2 = 1..1.15);
fsolve(p(-1.2, pp2) = 0, pp2 = 1.05);


@samiyare 

Try

fsolve(p(-1.2, pp2) = 0, pp2 = -10 .. 10);
plot(p(-1.2, pp2) , pp2 = 1..1.15);
fsolve(p(-1.2, pp2) = 0, pp2 = 1.05);


@koonduck Save the plots and use 'display'.

odeplot(dsol, [x, theta(x)], 0 .. 40);
p1 := %;
Omega := sqrt(omega^2-(g/(omega*R))^2);
#It is inadvisable to use theta and theta[a] in the same worksheet, so I have used another name:
thetaapprox := x->(1/3)*Pi+cos(Omega*x);
#You need an 'x' in the plotting interval when plotting an expression containing x. When plotting a procedure, however, you should only have the interval itself.
plot(thetaapprox(x), x = 0 .. 40, color = blue); p2:=%:
display(p1, p2);

If thetaapprox is supposed to be an approximation then certainly the amplitude is way off!

@koonduck Save the plots and use 'display'.

odeplot(dsol, [x, theta(x)], 0 .. 40);
p1 := %;
Omega := sqrt(omega^2-(g/(omega*R))^2);
#It is inadvisable to use theta and theta[a] in the same worksheet, so I have used another name:
thetaapprox := x->(1/3)*Pi+cos(Omega*x);
#You need an 'x' in the plotting interval when plotting an expression containing x. When plotting a procedure, however, you should only have the interval itself.
plot(thetaapprox(x), x = 0 .. 40, color = blue); p2:=%:
display(p1, p2);

If thetaapprox is supposed to be an approximation then certainly the amplitude is way off!

Although this method is very fast, it seems to run into problems when the degree is 10000:

restart;
F:=randpoly(epsilon,degree=10000,dense):
simplify(F, {epsilon^2=1});

Error, (in solve_eqn) too many levels of recursion

Added: It seems that the revised version SE2 of my proposed procedure SE above is faster than using simplify/siderels.

Although this method is very fast, it seems to run into problems when the degree is 10000:

restart;
F:=randpoly(epsilon,degree=10000,dense):
simplify(F, {epsilon^2=1});

Error, (in solve_eqn) too many levels of recursion

Added: It seems that the revised version SE2 of my proposed procedure SE above is faster than using simplify/siderels.

@koonduck Yes, you can use odeplot like this

odeplot(dsol,[x,theta(x)],0..40);

# or you can use plot since in your worksheet you pulled out the theta-procedure in the line
dsol1 := subs(dsol, theta(x));
plot(dsol1,0..40);

@koonduck Yes, you can use odeplot like this

odeplot(dsol,[x,theta(x)],0..40);

# or you can use plot since in your worksheet you pulled out the theta-procedure in the line
dsol1 := subs(dsol, theta(x));
plot(dsol1,0..40);

You may try using a smaller number of steps (or a smaller stepsize), then you will see wiggling.

Your system is similar to a model for the damped pendulum (except for the factor 1/1.03 in the sine function).

Thus I would have expected to see damping. However, I don't.

Now try Maple's own Euler method for comparison with your version and also with Maple's default numerical method rk45:

eq:=diff(x(t),t,t)=f2(t,x(t),diff(x(t),t));
resEuler:=dsolve({eq,x(0)=5,D(x)(0)=0},numeric,method=classical[foreuler],stepsize=.05);
plots:-odeplot(resEuler,[t,x(t)],0..5);
#Now the default Runge-Kutta-Fehlberg method:
resRKF45:=dsolve({eq,x(0)=5,D(x)(0)=0},numeric,stepsize=.05);
plots:-odeplot(resRKF45,[t,x(t)],0..5);

I guess this says something about Euler's method!

You may try using a smaller number of steps (or a smaller stepsize), then you will see wiggling.

Your system is similar to a model for the damped pendulum (except for the factor 1/1.03 in the sine function).

Thus I would have expected to see damping. However, I don't.

Now try Maple's own Euler method for comparison with your version and also with Maple's default numerical method rk45:

eq:=diff(x(t),t,t)=f2(t,x(t),diff(x(t),t));
resEuler:=dsolve({eq,x(0)=5,D(x)(0)=0},numeric,method=classical[foreuler],stepsize=.05);
plots:-odeplot(resEuler,[t,x(t)],0..5);
#Now the default Runge-Kutta-Fehlberg method:
resRKF45:=dsolve({eq,x(0)=5,D(x)(0)=0},numeric,stepsize=.05);
plots:-odeplot(resRKF45,[t,x(t)],0..5);

I guess this says something about Euler's method!

I tried your two equations with b = 1.

I got the same result in the two cases.

I believe it is because Maple starts by solving for f''', which involves squaring both sides.

I tried your two equations with b = 1.

I got the same result in the two cases.

I believe it is because Maple starts by solving for f''', which involves squaring both sides.

@mah00 The system is not autonomous, i.e. the right hand sides depend explicitly on t (not only on x(t) and y(t)).

In that case arrows cannot be drawn since they would not depend on (x, y) only.

The wrapping in 'evalc' makes f1 and g1 into explicit real valued functions of the real variable t before being given to DEplot. Apparently DEplot doesn't handle Re and Im very well, if at all. 

Try e.g. the simple example

DEplot(diff(x(t),t)=evalc(Re(-x(t)+I*sin(t))),x(t),t=0..5,[x(0)=1]);

and try removing 'evalc'. You may want to look at the help for 'evalc'.

@mah00 The system is not autonomous, i.e. the right hand sides depend explicitly on t (not only on x(t) and y(t)).

In that case arrows cannot be drawn since they would not depend on (x, y) only.

The wrapping in 'evalc' makes f1 and g1 into explicit real valued functions of the real variable t before being given to DEplot. Apparently DEplot doesn't handle Re and Im very well, if at all. 

Try e.g. the simple example

DEplot(diff(x(t),t)=evalc(Re(-x(t)+I*sin(t))),x(t),t=0..5,[x(0)=1]);

and try removing 'evalc'. You may want to look at the help for 'evalc'.

First 200 201 202 203 204 205 206 Last Page 202 of 230