Carl Love

Carl Love

28025 Reputation

25 Badges

12 years, 313 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

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.

(N,R):= selectremove(has, [a], I);

After executing the above, N will contain the nonreals and R will contain the reals.

The commands codegen:-cost, exprofile, excallgraph, and CodeTools:-Profiling:- may be useful to you.

Since you have provided increments for each variable, each variable takes on only a finite number of values. Hence there are only a finite number of possible evaluations for the profit expressions. Maple can process these quickly. Using the values of the "constants" that you provided, I was able to verify that ProfitB is greater than ProfitC at every evaluation. That is done like this:

restart:
c:= 1/10:  w:= 1/2:  p:= 1:
ProfitB:= (Pb*(p-w)/(1-Pb)-c)*Hb+w*(Pb*(1-Pa)*Hb+Pa*Pb*Hb)+wu*Pa*(1-Pb)*Ha;
ProfitC:= (Pa*(wu-w+Pb*(p-wu))/(1-Pa)-c)*(Ha+Hb)+w*(Pa*(1-Pb)*Ha+Pb*(1-Pa)*Hb+Pa*Pb*(Ha+Hb));

greater:= simplify(ProfitB - ProfitC);

for PB from 0 to 1/4 by 1/40 do
     for PA from 0 to 1/4 by 1/40 while PA < PB do
          for HB from 0 to 50 by 5 do
               for HA from 0 to HB by 5 while HA < HB do
                    for WU from 1/2 to 1 by 1/10 do
                         if eval(greater, [Pb,Pa,Hb,Ha,wu]=~ [PB,PA,HB,HA,WU]) <= 0 then
                              print(PB,PA,HB,HA,WU)
                         end if
                    end do
               end do
          end do
     end do
end do;  

Since there is no output printed, that verifies the result. If you want to supply ranges and increments for the "constants", a similar verification could be coded.

If you plot(v3, y= -1..1), you will see that v3 approaches two different limiting values as y approaches 0 from the left or right. So, Maple's answer of undefined is correct. But, I suppose that you are interested in the limit as y approaches 0 from the right. If you ask Maple directly for this limit, it will return unevaluated. You can also ask for a numeric evaluation of the limit like this:

Digits:= 4:
evalf(Limit(v3, y= 0, right));

That will take a few minutes to compute. The answer I got was 0.9996. You can get a faster result by using Digits:= 3:

Further advice: Change all occurences of int in your worksheet to Int. This will prevent Maple from repeatedly wasting time trying to evaluate integrals that it can't do anyway.

Yes, in Maple any expression whatsoever can be made into an assignable name by enclosing it in single back quotes ` `. However, names created thus won't necessarily display the same way as their mathematical counterparts. If you want it to display the same way, the Answer by Edgardo shows how to do that. However, the names created by that method may be too long to be of practical value.

In the example that you gave with subs, the command whose syntax you're emulating is applyrule, not subs.

applyrule(sin(c::anything)= c, sin(x)+f);

So, applying this to your integrals yields

ex:= Int(x*f(x), x= 0..1) + Int(x, x= 0.. 1/3) + 3*Int(x*f(x), x= 0..2/3):
applyrule(Int(c::anything, d::anything)= c, ex);

Since the value of n is necessarily integer, you won't hit 1 exactly, but you can use a loop to find the nearest integer.

a:= 0.2:  b:= 0.09:  c:= 0.57:  p:= 0.3:  q:= 0.7:
A_n:= ((1+c*p)*a/q+(2+c*p)*b)*product((1+c*q^k)*p, k= 1..n-1)+
     sum((a+b+k*b*q)*product((1+c*q^j)*p, j= k..n-1), k= 2..n):
for N from 2 while eval(A_n, n= N) < 1 do end do;
N;

     7

eval(A_n, n=6);

     0.9567704620

eval(A_n, n= 7);

     1.037279427

Please post your code as plaintext, not as images. That way I won't have to retype your code.

Note that I used sum rather than add above.

 

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