Carl Love

Carl Love

28110 Reputation

25 Badges

13 years, 120 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are replies submitted by Carl Love

There is probably a syntax error, perhaps unmatched parentheses, in one of the statements after the if and before the else. Please post the code: I can find it quicker than it took me to type this.

Are the time values evenly spaced?

Are the time values evenly spaced?

@Carl Love I should add that the functional way is not always the best way to plot a numeric integration. It can prevent Maple from being able to choose the most efficient numeric algorithm. In particular, if you have an analytic expression for the integrand, then you should not use a procedure as the integrand. You can do this:

plot(z-> Int(x-floor(x), x= 0..z), -4..4);

Jay's method of solving a differential equation and using DEplot is also a fine idea when the plotting variable is one of the limits of integration. But if the plotting variable appears as a parameter in the integrand, that can be difficult or impossible to implement.

@Carl Love I should add that the functional way is not always the best way to plot a numeric integration. It can prevent Maple from being able to choose the most efficient numeric algorithm. In particular, if you have an analytic expression for the integrand, then you should not use a procedure as the integrand. You can do this:

plot(z-> Int(x-floor(x), x= 0..z), -4..4);

Jay's method of solving a differential equation and using DEplot is also a fine idea when the plotting variable is one of the limits of integration. But if the plotting variable appears as a parameter in the integrand, that can be difficult or impossible to implement.

@N00bstyle 

[] means "take the brackets off of a set or list".

So, if L = [a,b,c], then L[] = a,b,c.

Let's go through how the parser interprets rhs(test[2][]). Index expressions associate to the left (*footnote), so the first thing is test[2]. That means the second item of list test. That item is itself a list. The [] means "take the brackets off that", leaving the equation t = number. Then the rhs selects number. In the case of test[2][1], it means "take the second item, then take the first item of that". It could also be expressed test[2,1].

*footnote: "Associates to the left" means that test[2][] is parsed the same as (test[2])[] and not as test([2][]).

Is that a sufficient explanantion?

@N00bstyle 

[] means "take the brackets off of a set or list".

So, if L = [a,b,c], then L[] = a,b,c.

Let's go through how the parser interprets rhs(test[2][]). Index expressions associate to the left (*footnote), so the first thing is test[2]. That means the second item of list test. That item is itself a list. The [] means "take the brackets off that", leaving the equation t = number. Then the rhs selects number. In the case of test[2][1], it means "take the second item, then take the first item of that". It could also be expressed test[2,1].

*footnote: "Associates to the left" means that test[2][] is parsed the same as (test[2])[] and not as test([2][]).

Is that a sufficient explanantion?

@tobsam Please post your worksheet.

@Markiyan Hirnyk Your timings and memory data are confounded by the fact that simplify is using remember tables. Here's a more accurate comparison:

(**)

f:= x^5+a*x^4+b*x^3+c*x^2+d*x+e:

(**)

st:= time():
to 10^4 do
     simplify(f, {x^3=1});
     forget(simplify)
end do:
time()-st;

7.831

(**)

st:= time():
to 10^4 do
     algsubs(x^3=1, f);
     forget(algsubs)
end do:
time()-st;

14.555

(**)

st:= time():
to 10^4 do
     rem(f, x^3-1, x);
     forget(rem)
end do:
time()-st;

7.675

(**)

macro(CTU= CodeTools:-Usage):

(**)

CTU(simplify(f, {x^3-1}));

memory used=12.90KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns

e+b+(a+d)*x+(c+1)*x^2

(**)

CTU(algsubs(x^3=1, f));

memory used=34.76KiB, alloc change=0 bytes, cpu time=0ns, real time=1000.00us

e+b+(a+d)*x+(c+1)*x^2

(**)

CTU(rem(f, x^3-1, x));

memory used=18.67KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns

e+b+(a+d)*x+(c+1)*x^2

(**)

 

 

Download algsubs_vs_rem.mw

 

@Markiyan Hirnyk Your timings and memory data are confounded by the fact that simplify is using remember tables. Here's a more accurate comparison:


(**)

f:= x^5+a*x^4+b*x^3+c*x^2+d*x+e:

(**)

st:= time():
to 10^4 do
     simplify(f, {x^3=1});
     forget(simplify)
end do:
time()-st;

11.031

(**)

st:= time():
to 10^4 do
     algsubs(x^3=1, f);
     forget(algsubs)
end do:
time()-st;

17.766

(**)

st:= time():
to 10^4 do
     rem(f, x^3-1, x);
     forget(rem)
end do:
time()-st;

10.562

(**)

macro(CTU= CodeTools:-Usage):

(**)

CTU(simplify(f, {x^3-1}));

memory used=12.90KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns

(c+1)*x^2+(a+d)*x+b+e

(**)

CTU(algsubs(x^3=1, f));

memory used=34.76KiB, alloc change=0 bytes, cpu time=0ns, real time=1000.00us

(c+1)*x^2+(a+d)*x+b+e

(**)

CTU(rem(f, x^3-1, x));

memory used=18.67KiB, alloc change=0 bytes, cpu time=0ns, real time=0ns

(c+1)*x^2+(a+d)*x+b+e

(**)

 


Download algsubs_vs_rem.mw

@Xucu Sorry, I have no ideas about your problem.

Why not just do two substitutions, one to get rid of the W[n](t) and the other to get rid of the A?

 

pdsolve(..., numeric) is very fussy about how you put the extra equations into the system, much more so than dsolve. I can't describe precisely what makes it work; I need to play with it. So, you should post your system and say which second derivative you want.

This is with Digits = 15, and all dsolve options (other than method, of course) at their defaults.

Method     digits of accuracy

adaptive
methods

dverk78            5
taylorseries       4
rosenbrock        2
ck45                1
gear                 1
rkf45                0
mebdfi              0
lsode               -3

classical
methods

rk4                    7 (!!!)
abmoulton          6  (!!)
adambash           6 (!!)
impoly                4
rk3                    4
rk2                    4
foreuler              0

For the lsode, my -3 means that the answer was wrong by three orders of magnitude!

Can anyone explain why these classical fixed-step-size methods with no modern error control fare so much better? Could it be that they are using a very small stepsize?

This is with Digits = 15, and all dsolve options (other than method, of course) at their defaults.

Method     digits of accuracy

adaptive
methods

dverk78            5
taylorseries       4
rosenbrock        2
ck45                1
gear                 1
rkf45                0
mebdfi              0
lsode               -3

classical
methods

rk4                    7 (!!!)
abmoulton          6  (!!)
adambash           6 (!!)
impoly                4
rk3                    4
rk2                    4
foreuler              0

For the lsode, my -3 means that the answer was wrong by three orders of magnitude!

Can anyone explain why these classical fixed-step-size methods with no modern error control fare so much better? Could it be that they are using a very small stepsize?

First 633 634 635 636 637 638 639 Last Page 635 of 710