Carl Love

Carl Love

28070 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

AFAIK, Maple's for loop syntax is pretty much the same as most other languages. It's done like this:

list_A:= table():  list_B:= table():  list_C:= table():
more:= true:
for k while more do
     #Do computation that computes A, B, and C and sets the
     #boolean value `more`.
     list_A[k]:= A;  list_B[k]:= B;  list_C[k]:= C
end do:
list_A:= convert(list_A, list);
list_B:= convert(list_B, list);
list_C:= convert(list_C, list);

You'll get a much smoother ellipsoid if you use regular plot3d and parametric plotting, like this:

plot3d(
     [2*sin(t)*cos(u), 3*cos(t)*cos(u), 4*sin(u)], t= 0..2*Pi, u= -Pi/2..Pi/2,
     scaling= constrained
);

cos(2*t) is the same thing as 2*cos(t)^2 - 1.

You need more points. One thousand points is a very small amount for an implicitplot. Use numpoints= 10000 and also add gridrefine= 3.

The student[showtangent] command is old and deprecated. It's better to use Student:-Calculus1:-Tangent, which automatically shows the point of tangency and puts a good caption on the plot.

f:= x-> x^2-2*x:
a:= 1.5:
T:= Student:-Calculus1:-Tangent(
     f(x), x= a, -10..10, output= plot,
     pointoptions= [symbol= diamond, symbolsize= 24, color= red]
):
N:= plot(-1/D(f)(a)*(x-a)+f(a), x= -10..10, color= black, legend= ["the normal"]):
plots:-display(
     [subs(" and a tangent line."= " and a tangent line and a normal line.", T), N],
     view= [-10..10, -10..10], scaling= constrained
);

You can cut and paste to MaplePrimes plaintext (1D) Maple input and most 2D Maple output. It won't work for Matrices, Vectors, and plots. For plots, you can Export them using a right-click context menu. I always export to PNG (except for animations, for which I use GIF). Then upload them to MaplePrimes using the green uparrow tool, which is the last item on the second row of the toolbar in the MaplePrimes editor. You can also use this tool to upload entire worksheets.

First question: Click on the Edit menu, select Execute, then select either Selection or Worksheet.

Second question: Use the time() command. The most common way is to place

st:= time():

at the beginning of the block of code that you want to time. Also place

time()-st;

at the end of the block.

The two-argument form of map is called zip. So, for that command that doesn't work, change map to zip.

Here is an implementation of your algorithm for the univariate case. I show Examples 1, 3, and 4 from your paper. I don't understand Example 2; please explain it further.

If you like the below, I'll try to work on the multivariate case.

 

BiazarShafiofAdomian:= proc(G::algebraic, u::name, n::nonnegint)
local lambda, i, k, A:= table([0= subs(u= u[0], G)]);
     for k to n do
          A[k]:=
               eval(
                    diff(
                         subs(
                              seq(u[i]= u[i]+(i+1)*u[i+1]*lambda, i= 0..k-1),
                              A[k-1]
                         ), lambda
                    ), lambda= 0
               )/k
     end do;
     convert(A, list)
end:     
     

Example 1:

BiazarShafiofAdomian(u^3+u^4, u, 3);

[u[0]^4+u[0]^3, 4*u[0]^3*u[1]+3*u[0]^2*u[1], 4*u[0]^3*u[2]+6*u[0]^2*u[1]^2+3*u[0]^2*u[2]+3*u[0]*u[1]^2, 4*u[0]^3*u[3]+12*u[0]^2*u[1]*u[2]+4*u[0]*u[1]^3+3*u[0]^2*u[3]+6*u[0]*u[1]*u[2]+u[1]^3]

(1)

Example 2:

     I don't understand this example, so I can't show it. Please explain it further.

 

Example 3:

BiazarShafiofAdomian(sinh(u)+sin(u)^2*cos(u)^2, u, 3);

[sinh(u[0])+sin(u[0])^2*cos(u[0])^2, u[1]*cosh(u[0])+2*sin(u[0])*cos(u[0])^3*u[1]-2*sin(u[0])^3*cos(u[0])*u[1], u[2]*cosh(u[0])+(1/2)*u[1]^2*sinh(u[0])+u[1]^2*cos(u[0])^4-6*sin(u[0])^2*cos(u[0])^2*u[1]^2+2*sin(u[0])*cos(u[0])^3*u[2]+sin(u[0])^4*u[1]^2-2*sin(u[0])^3*cos(u[0])*u[2], u[3]*cosh(u[0])+u[2]*u[1]*sinh(u[0])+(1/6)*u[1]^3*cosh(u[0])+2*u[1]*cos(u[0])^4*u[2]-(16/3)*u[1]^3*cos(u[0])^3*sin(u[0])+(16/3)*sin(u[0])^3*cos(u[0])*u[1]^3-12*sin(u[0])^2*cos(u[0])^2*u[1]*u[2]+2*sin(u[0])*cos(u[0])^3*u[3]+2*sin(u[0])^4*u[1]*u[2]-2*sin(u[0])^3*cos(u[0])*u[3]]

(2)

Example 4:

BiazarShafiofAdomian(exp(u)+ln(u), u, 3);

[exp(u[0])+ln(u[0]), u[1]*exp(u[0])+u[1]/u[0], u[2]*exp(u[0])+(1/2)*u[1]^2*exp(u[0])+u[2]/u[0]-(1/2)*u[1]^2/u[0]^2, u[3]*exp(u[0])+u[2]*u[1]*exp(u[0])+(1/6)*u[1]^3*exp(u[0])+u[3]/u[0]-u[2]*u[1]/u[0]^2+(1/3)*u[1]^3/u[0]^3]

(3)

 

``


Download Biazar-Shafiof_Adomian.mw

Generate the animations of each curve separately, then merge the animations with plots:-display. Here is an example with basic animations:

A1:= plots:-animate(plot, [x, x= 0..T, color= blue], frames= 5, T= 1..5):
A2:= plots:-animate(plot, [-x, x= 0..T, color= green], frames= 5, T= 1..5):
plots:-display([A1,A2]);

If you still need help, please post the complete code for your pdsolve command.

Your original expression contains integral expressions of the form Int(f(N), 1). That's nonsense to Maple. The second argument, "1", means nothing. Unfortunately, the plot command's response to nonsense is often to return an empty plot rather than a meaningful error message.

I tried to keep it as much the same as the Matlab code as I could. But I can't abide by repetitious code or a needless lack of generality, so I made it a procedure. Note that I made the number of steps, n, the parameter rather than making the stepsize, h, the parameter.

EulersMethod:= proc(
     Yprime::algebraic, Yt::function, y0::numeric, R::range(numeric), n::posint
)
local
     h:= -`-`(op(R))/n, #Independent variable step
     a:= op(1,R),       #Initial value of independent variable
     T:= Vector(n+1, k-> a+(k-1)*h),
     Ystar:= Vector(n+1, [y0]), #Preallocate array (good coding practice)
     t:= op(Yt), #Independent variable
     i, k1
;
     for i from 1 to n do
          #Previous approx for y gives approx for derivative.
          k1:= eval(Yprime, [Yt= Ystar[i], t= T[i]]);
          #Approximate solution for next value of y
          Ystar[i+1]:= Ystar[i] + k1*h
     end do;
     plot(<T | Ystar>, args[6..])
end proc:
       
ode:= 0.0207*V(t)^2 - 893.58:
EulersMethod(ode, V(t), 0, 0..5, 50);
EulersMethod(ode, V(t), 0, 0..1, 100);

 

 

Well, two commands that will be useful for that are plots:-animate and sum. The first argument to animate is another plot command. In this case, that should be plot. The second argument is a list that contains the arguments to that plot command, except that there's an animation parameter somewhere. In this case, the animation parameter will be your N. The third argument specifies the range of the animation parameter. In this case, that'll be N= 1..10. The next argument, in this case, must be frames= 10 (because this can't be a continuous animation; only integer values of the parameter make sense).

I'm assuming that the author did not supply the source code with the package, or you wouldn't be asking.

Not all of the following steps are necessarily needed. Let's say you want procedure P1 in package P:

interface(verboseproc= 2);
kernelopts(opaquemodules= false);
lprint(eval(P:-P1));

Now select and copy the output. Paste it to an input prompt, a Code Edit Region, or your own text editor. Your first editting step should be to add the line breaks and indenting.

Here are four things that you can do to get more information. I have listed them in order by how structured the information is, with the most structured first.

1. Set

infolevel[all]:= 5;

That will cause programs to print out additional information of the programmers' choosing. You can use higher or lower numbers for more or less information. Most programs don't use levels higher than 5.

2. Print the code of procedures with showstat:

showstat(int);
showstat(sin);
showstat(cos);

3. Trace the execution of particular procedures with trace:

trace(int);
trace(sin);

4. Trace the execution of everything with printlevel:

printlevel:= 10000:

You can use higher or lower numbers for more or less information.

 

 

For RSA to work, d and e must be multiplicative inverses mod ((p-1)*(q-1)). That is, we must have

e = 1/d mod ((p-1)*(q-1)).

That does not hold for your d and e.

First 270 271 272 273 274 275 276 Last Page 272 of 395