Carl Love

Carl Love

28025 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

If you were going to define and declare a new constant, I don't see any point in making it anything other than global. Thus there's no point in having the value of constants revert when you exit a procedure. 

But perhaps you can convince me otherwise on either of those two points. 

Okay, with your additional information, I now understand your Question, which otherwise seemed trivial.

To answer your titular question: You get solve to ignore certain independent variables by including an identity clause in the solve command. So, here is the solution to your example:

ind_V:= {r, phi, Z}: #independent variables
Eqn:= 
    8*r^5*_C1*((alpha[4,4] - alpha[5,5])*cos(2*phi) 
    + sin(2*phi)*alpha[4,5]) = 0:
Sols:= {
    solve(
        identity(Eqn, phi), 
        indets(Eqn, And(name, Not(constant))) minus ind_V
    )
};
Sols2:= remove~(evalb, Sols); #Remove trivialities.

    {{_C1 = 0}, {alpha[4,4] = alpha[5,5], alpha[4,5] = 0}}

#Optional step: Put solution in the exact and/or form that you 
#presented:
OrAnd_form:= `or`((``@`and`@op)~(Sols2)[]);

    (_C1 = 0) or (alpha[4,4] = alpha[5,5] and alpha[4,5] = 0)

An identity clause is currently limited to declaring only 1 variable as the independent variable. It is obvious in this case that that variable should be phi, not r.

[Edit: This Answer, which seems trivial, was based on the original version of the Question. The OP subsequently added much clarifying material, and a new Answer is needed.

I hereby grant permission to any Moderator to delete this Answer if they feel, as I do, that that is appropriate. I don't think that it'd be appropriate for me to delete it myself, so I recuse myself.]

You wrote: 

  • I would like to solve this type of equations for all values of the variables, namely phi in the example above.

If you want to solve for phi, the command is solve(..., {phi}) (complete example below).

  • If I do not choose the variables for which to solve, I get phi=phi as one of the equations in the solution.
  • If i choose all the variables except phi, i get an the expression for the constants containing the variable phi.

You seem to have tried every combination except the only obvious one: Choose phi (and phi alone) as the variable for which to solve.

Eqn:= 
   sin(phi)*_C1*a[3,5] + cos(phi)*_C1*a[3,4] = 
   sin(phi)*_C11*a[1,3] - cos(phi)*_C11*a[2,3]
;
solve({Eqn}, {phi});

  • Is there a way to solve these equations automatically?

I consider  the above "automatic". If you do not, we can work on it---there are many options.

  • Or do I have to separate them manually using collect and coeffs?

No, you shouldn't need to use those commands just to solve equations.

  • Or could the solution be the comand Parameters from Physics package?

No, and don't you think that that would be a rather obscure way to perform one of the most important functions of a computer-algebra package---solving an equation?

 

You're using d and dt as if they were variables when you obviously intend them to be a differential operator. Your equation can be entered like this:

dl1:= C[th]*diff(T[ovn](t), t) = 
    P[el](t) - (T[ovn](t) - T[a](t))/R[th] - A*sigma*(T[ovn](t)^4 - T[a](t)^4);

Note in particular the derivative: diff(T[ovn](t), t). The above is written in the "1D" (aka plaintext aka "Maple Input") form that NM was refering to. You can copy-and-paste these lines into a worksheet. It'll work regardless of the input mode.

I don't think that there's much hope of getting a solution as long as there are unknown functions of t (such as P[el](t) and T[a](t)) present. The dsolve will just return NULL, I think because it gives up, not because it thinks that there's no solution. (There is definitely a solution assuming that the unknown functions are suitably smooth.)

You might as well define the nonhomogenous part as 

F:= t-> (P[el](t) + T[a](t)/R[th] + A*sigma*T[a](t)^4)/C[th];

This won't help dsolve to solve it; it's just to keep things tidy.

There's no symbolic representation of the solution other than RootOf(...). But you can do

fsolve(beta = cot(beta), beta= 0..Pi/2);

Eq:= a*x+b*y+c = 0:
expand(solve({Eq}, {y})[]);

 

The following will work for any set of equations (regardless of whether 0 is on either side). Like Kitonum's solution, it puts terms with derivatives on the left side and those without derivatives on the right side.

SepDiff:= (s::set(`=`))->
    local Z, S:= (lhs-rhs)~(subs(0= Z, s));
    subs(Z= 0, map(e-> `=`((1,-1)*~selectremove(has, e, diff)), S))
: 

To use it in your case, simply do

SepDiff(sols1);

If you have a working plot3d command such as 

plo3d(u, x= -3..3, t= -3..3);

then simply change it to

plots:-contourplot(u, x= -3..3, t= -3..3);

Note that I use u rather than [u]. The [u] is acceptable to plot3d but not to contourplot.

Here is the solution with plots for the equation solved as a BVP and solved via HPM (Homotopy Perturbation Method). I didn't make the table, but you could extract the data for the table from the matrices in the plots (indeed, for 201 values of eta in 0..1) just like I did in the code below. To my mind, all that matters is the maximum error over the interval 0..1, so that's what I computed. I think that the table was just filler for a relatively short paper.
 

restart #Remove restart if using Maple 2019.2 due to a serious bug.
:

All Equation Eq numbers refer to the corresponding Equations in the paper.

 

The fundamental BVP:

Eq6:= diff(f(eta),eta$3) +
    alpha*(2*R*f(eta) + (4-H)*alpha)*diff(f(eta),eta)
= 0;
Eq7:= f(0)=1, D(f)(0)=0, f(1)=0:
BVP:= {Eq6, Eq7}:

#Parameters:
params:= {alpha= 7.5*Pi/180, R= 50}:
#Note that I converted alpha to radians!
#R is "Re" in the paper.

Hlist:= [0, 250, 500, 1000]: #Hartmann numbers

diff(diff(diff(f(eta), eta), eta), eta)+alpha*(2*R*f(eta)+(4-H)*alpha)*(diff(f(eta), eta)) = 0

for k to nops(Hlist) do
    Ha:= Hlist[k];
    Sol_f[Ha]:= dsolve(eval(BVP, params union {H= Ha}), numeric);
    P[Ha]:= plots:-odeplot(
       Sol_f[Ha], [eta, f(eta)], legend= [H=Ha],
       color= COLOR(HUE, (k-1)/(nops(Hlist)-1)*.85)
    )
od:

#Fig. 2:
plots:-display(
   [seq(P[k], k= Hlist)], gridlines= false,
   title= "Velocity profiles, solved as BVPs"
);

Homotopy Perturbation Method (HPM)

Eq17:= {diff(F0(eta), eta$3) = 0, F0(0)=1, D(F0)(0)=0, (D@@2)(F0)(0)=a};
Eq18:= {
   diff(F1(eta), eta$3) +
      2*alpha*R*F0(eta)*diff(F0(eta),eta) +
      alpha^2*(4-H)*diff(F0(eta),eta)
   = 0,
   F1(0)=0, D(F1)(0)=0, (D@@2)(F1)(0)=0
};
Eq19:= {
   diff(F2(eta), eta$3) + alpha^2*(4-H)*diff(F1(eta),eta) +
      2*alpha*R*F0(eta)*diff(F1(eta),eta) +
      2*alpha*R*F1(eta)*diff(F0(eta),eta)
   = 0,
   F2(0)=0, D(F2)(0)=0, (D@@2)(F2)(0)=0
};

{F0(0) = 1, diff(diff(diff(F0(eta), eta), eta), eta) = 0, (D(F0))(0) = 0, ((D@@2)(F0))(0) = a}

{diff(diff(diff(F1(eta), eta), eta), eta)+2*alpha*R*F0(eta)*(diff(F0(eta), eta))+alpha^2*(4-H)*(diff(F0(eta), eta)) = 0, F1(0) = 0, (D(F1))(0) = 0, ((D@@2)(F1))(0) = 0}

{diff(diff(diff(F2(eta), eta), eta), eta)+alpha^2*(4-H)*(diff(F1(eta), eta))+2*alpha*R*F0(eta)*(diff(F1(eta), eta))+2*alpha*R*F1(eta)*(diff(F0(eta), eta)) = 0, F2(0) = 0, (D(F2))(0) = 0, ((D@@2)(F2))(0) = 0}

Eq20:= dsolve(Eq17);

F0(eta) = (1/2)*a*eta^2+1

Sol:= dsolve(eval(Eq18, Eq20)):
Eq21:= collect(Sol, eta);

F1(eta) = -(1/120)*alpha*a^2*R*eta^6+alpha*a*((1/24)*H*alpha-(1/12)*R-(1/6)*alpha)*eta^4

Sol:= dsolve(eval(Eq19, {Eq20, Eq21})):
Eq22:= collect(Sol, eta);

F2(eta) = (1/10800)*alpha^2*a^3*R^2*eta^10+(1/30)*alpha^2*a*(-(3/112)*alpha*H*R*a+(3/56)*R^2*a+(3/28)*R*alpha*a)*eta^8+(1/30)*alpha^2*a*((1/24)*alpha^2*H^2-(1/6)*alpha*H*R-(1/3)*alpha^2*H+(1/6)*R^2+(2/3)*R*alpha+(2/3)*alpha^2)*eta^6

f_HPM:= unapply(eval(F0(eta)+F1(eta)+F2(eta), {Eq20,Eq21,Eq22}), eta);

proc (eta) options operator, arrow; (1/2)*a*eta^2+1-(1/120)*alpha*a^2*R*eta^6+alpha*a*((1/24)*H*alpha-(1/12)*R-(1/6)*alpha)*eta^4+(1/10800)*alpha^2*a^3*R^2*eta^10+(1/30)*alpha^2*a*(-(3/112)*alpha*H*R*a+(3/56)*R^2*a+(3/28)*R*alpha*a)*eta^8+(1/30)*alpha^2*a*((1/24)*alpha^2*H^2-(1/6)*alpha*H*R-(1/3)*alpha^2*H+(1/6)*R^2+(2/3)*R*alpha+(2/3)*alpha^2)*eta^6 end proc

Solve for a:

a_sol:= solve({f_HPM(1)=0}, {a})[1]: #[1] is only real solution.

for k to nops(Hlist) do
    Ha:= Hlist[k];
    PH[Ha]:= plot(
       eval(eval(f_HPM(eta), a_sol), params union {H= Ha}),
       eta= 0..1, legend= [H=Ha],
       sample= [seq(op([1,1], P[Ha])[..,1])], adaptive= false,
       color= COLOR(HUE, (k-1)/(nops(Hlist)-1)*.85)
    )
od:

#Fig. 2:
plots:-display(
    [seq(PH[k], k= Hlist)], gridlines= false,
    title= "Velocity profiles, solved via HPM",
    labels= ['eta', 'f']
);

Compute maximum difference between the two solutions for each H.

for Ha in Hlist do
    err[` H`=Ha]:= LinearAlgebra:-Norm(
        Vector(op([1,1], P[Ha])[..,2] - op([1,1], PH[Ha])[..,2]),
        infinity #max norm
    )
od;

.129520180880002722

0.240134111942442163e-1

0.149072751558998462e-2

0.698175154954450150e-2

 


 

Download BVPvsHPM.mw

If your goal is simply to represent objects defined in real vector spaces with more than 3 dimensions, you can use animation and/or color. Animation makes time a dimension. There are several schemes (RGB, HSV, etc.) for squeezing in 3 dimensions of color. 

I can't look at your worksheet because MaplePrimes doesn't accept the .maple format. If you resave and repost it as a .mw, I'll be able to look at it. This should be no problem because your work shouldn't require any auxilliary data.

There are two errors in the printed statement of the problem:

  • and Re are used to represent the same thing. I just changed Re to R.
  • The first initial condition for the third equation should be F2(0)=0, not 
    F0(0)=0.

Here's my solution, which matches what's stated in the paper:


 

Eq0:= {diff(F0(eta), eta$3) = 0, F0(0)=1, D(F0)(0)=0, (D@@2)(F0)(0)=a}:

Sol0:= dsolve(Eq1);

F0(eta) = (1/2)*a*eta^2+1

(1)

Eq1:= {
   diff(F1(eta), eta$3) +
      2*alpha*R*F0(eta)*diff(F0(eta),eta) +
      alpha^2*(4-H)*diff(F0(eta),eta)
   = 0,
   F1(0)=0, D(F1)(0)=0, (D@@2)(F1)(0)=0
}:

Sol1:= dsolve(eval(Eq1, Sol0));

F1(eta) = a*alpha*(-(1/120)*R*a*eta^6+(1/24)*(H*alpha-2*R-4*alpha)*eta^4)

(2)

Sol1:= collect(Sol1, eta);

F1(eta) = -(1/120)*a^2*alpha*R*eta^6+a*alpha*((1/24)*H*alpha-(1/12)*R-(1/6)*alpha)*eta^4

(3)

Eq2:= {
   diff(F2(eta), eta$3) + alpha^2*(4-H)*diff(F1(eta),eta) +
      2*alpha*R*F0(eta)*diff(F1(eta),eta) +
      2*alpha*R*F1(eta)*diff(F0(eta),eta)
   = 0,
   F2(0)=0, D(F2)(0)=0, (D@@2)(F2)(0)=0
}:      

Sol2:= dsolve(eval(Eq2, {Sol0, Sol1}));

F2(eta) = (1/30)*a*alpha^2*((1/360)*R^2*a^2*eta^10+(1/336)*(-9*H*R*a*alpha+18*R^2*a+36*R*a*alpha)*eta^8+(1/120)*(5*H^2*alpha^2-20*H*R*alpha-40*H*alpha^2+20*R^2+80*R*alpha+80*alpha^2)*eta^6)

(4)

Sol2:= collect(Sol2, eta);

F2(eta) = (1/10800)*a^3*alpha^2*R^2*eta^10+(1/30)*a*alpha^2*(-(3/112)*H*R*a*alpha+(3/56)*R^2*a+(3/28)*R*a*alpha)*eta^8+(1/30)*a*alpha^2*((1/24)*alpha^2*H^2-(1/6)*alpha*H*R-(1/3)*alpha^2*H+(1/6)*R^2+(2/3)*R*alpha+(2/3)*alpha^2)*eta^6

(5)

 


 

Download SequentialDsolve.mw

 

The command is currentdir. Example:

currentdir("C:/Users/carl/desktop");

The forward slash / can always be used as the directory separator in Maple filenames, even on Windows.

A distinction needs to be made between equations and assignments. This distinction can be a slightly difficult concept to grasp for new programmers. It is often the first nontrivial concept one encounters when learning a first computer language. This distinction exists in all computer languages, but it is more pronounced in symbolic languages such as Maple, where variables can be meaningful even when they don't have values (we say that such variables are symbolic).

Equations are declarative statements (in the logical/linguistic sense). They can be true or false depending on the values of their variables. With symbolic variables, "truth" can be more subtle: An equation may be true for all, for some, or for no values of its variables. In Maple, equations are expressed with the equals sign =.

On the other hand, assignments are imperative statements (i.e., commands) that force a variable to be a certain value. (That certain value may possibly still contain symbolic variables.) Thus, there is no question of their truth. In Maple, assignments are expressed with := or occasionally with the assign or unassign commands. Assignments are often expressed in mathematical writing with "let", as in "Let x = 3."

Your problem would be best done using equations. Like Acer, I disdain making assignments to the directly meaningful variables of a problem---those variables that are meaningful outside the context of a computer program. 

Here is the solution to your problem. Note how conveniently the Solution is expressed: It shows the numeric values of all variables in one place. These numbers are not assigned to the variables. Rather, solve is saying that if the variables had those values, the equations would be true.

System:= {
   totalsalesx = 60.1 + tax + profit,
   tax = 0.3*profit,
   profit = 0.1*totalsalesx
}:
Solution:= solve(System);
           {profit = 6.908045977, tax = 2.072413793, totalsalesx = 69.08045977}

 

Here is a procedure for it:

DroppedContourPlot3d:= proc(
   Z::name= algebraic, #function to plot
   X::name= range(realcons), #x-axis-parameter range
   Y::name= range(realcons), #y-axis-parameter range
   {
      #fraction of empty space above and below plot (larger "below"
      #value improves view of dropped-shadow contourplot):
      zmargin::[realcons,realcons]:= [.05,0.15],
      contouropts::list({name, name= anything}):= [],
      surfaceopts::list({name, name= anything}):= []    
   }
)
option `Author: Carl Love <carl.j.love@gmail.com> 19-Nov-2019`;
local
   LX:= lhs(X), RX:= rhs(X), LY:= lhs(Y), RY:= rhs(Y),
   C:= plots:-contourplot(
      rhs(Z), X, Y,
      #These default plot options can be changed by setting 'contouropts': 
      'contours'= 5, 
      'filled', 'coloring'= ['yellow', 'orange'], 'color'= 'green', 
      contouropts[]
   ),
   P:= plot3d(
      rhs(Z), X, Y,
      #These default plot options can be changed by setting 'surfaceopts': 
      'style'= 'surfacecontour', 'contours'= 6,
      surfaceopts[]
   ),
   U, L #z-axis endpoints after margin adjustment
;
   #Stretch z-axis to include margins:
   (U,L):= ((Um,Lm,M,m)-> (M*(Lm-1)+m*Um, M*Lm+m*(Um-1)) /~ (Um+Lm-1))(
      zmargin[],
      (max,min)(op(3, indets(P, 'specfunc'('GRID'))[])) #actual z-axis range
   );
   plots:-display(  #final plot to display/return
      [
         plots:-spacecurve(
            { 
               [  #(y,z)-plane backwall:
                  [lhs(RX),rhs(RY),U], [rhs(RX),rhs(RY),U],
                  [rhs(RX),rhs(RY),L]
               ],
               [  #((x,z)-plane backwall:
                  [rhs(RX),rhs(RY),U], [rhs(RX),lhs(RY),U],
                  [rhs(RX),lhs(RY),L]
               ] 
            },
            'color'= 'grey', 'thickness'= 0
         ),
         plottools:-transform((x,y)-> [x,y,L])(C), #dropped contours
         P
      ],
      #These default plot options can be changed simply by putting the option
      #in the DroppedCountourPlot3d call:
      'view'= ['DEFAULT', 'DEFAULT', L..U], 'orientation'= [-135, 75], 
      'axes'= 'frame',
      'labels'= [lhs(X), lhs(Y), 'z'], 
      'labelfont'= ['TIMES', 'BOLDOBLIQUE', 16],
      'axesfont'= ['TIMES', 12],
      'projection'= 2/3,   
      _rest
   )
end proc
: 

Example usage:

DroppedContourPlot3d(z=x^2+y^2, x= -2..2, y= -2..2);

I didn't plot the same function that you specified because it's too difficult to read your unformatted Question, but it should be straightforward to plot it as above.

My procedure automatically chooses a plane for the 2d plot to optimize the view; it doesn't necessarily use plane z=0.

Since you tried partial fractions, I thought that maybe you'd want a step-by-step work through of the "telescoping" method by which the sum of such a series is found. Here it is.
 

restart:

T:= 1/i/(i+1)/(i+2)/(i+3);

1/(i*(i+1)*(i+2)*(i+3))

(1)

We want this sum:

S:= Sum(T, i= 1..infinity);

Sum(1/(i*(i+1)*(i+2)*(i+3)), i = 1 .. infinity)

(2)

We suspect "telescoping" when the general term contains parts that also occur in subsequent terms, i.e., i+1, i+2, i+3. An analysis of it usually begins by breaking the general term itself into a sum. In this case, that means a partial-fraction decomposition.

F:= unapply(convert(T, parfrac, i), i);

proc (i) options operator, arrow; (1/6)/i+(1/2)/(i+2)-(1/6)/(i+3)-(1/2)/(i+1) end proc

(3)

Add an arbitrary number of consecutive terms from anywhere in the series to see the effect of "telescoping" cancellations.

sum(F(i+j), j= 0..n);

-(1/6)/(i+n+1)+(1/3)/(i+n+2)-(1/6)/(i+n+3)+(1/6)/i-(1/3)/(i+1)+(1/6)/(i+2)

(4)

This is called a partial sum of the series. Its limit is the sum of the series. Obviously the terms with n in the denominator go to 0.

limit(%, n= infinity);

(1/3)/(i*(i+1)*(i+2))

(5)

The actual sum that we want begins at i=1.

eval(%, i= 1);

1/18

(6)

Check if Maple concurs:

value(S);

1/18

(7)

 


 

Download TelescopingSeries.mw

First 124 125 126 127 128 129 130 Last Page 126 of 395