dharr

Dr. David Harrington

8205 Reputation

22 Badges

20 years, 338 days
University of Victoria
Professor or university staff
Victoria, British Columbia, Canada

Social Networks and Content at Maplesoft.com

Maple Application Center
I am a retired professor of chemistry at the University of Victoria, BC, Canada. My research areas are electrochemistry and surface science. I have been a user of Maple since about 1990.

MaplePrimes Activity


These are replies submitted by dharr

Interesting. Nested radicals frequently give me problems. It is interesting that solve thinks they are the same.

expr:=sqrt(x+2*sqrt(x-1));
expr2:=sqrt(x-1)+1;
solve(expr2-expr,x);

gives x.

Probably you can use polygon from the plottools package for this, but if you upload your worksheet using the green up-arrow in the Mapleprimes editor, someone will help you.

@salim-barzani You didn't attempt to use Diff - all your Q's are zero because your B1 are zero.

@salim-barzani Does Diff work for you?

restart

So if I understand correctly you want to carry out all the calculations omitting explicit dependence on x or t. So for example you want

Q := -2*alpha*u[0](x, t)*conjugate(u[0](x, t))*(diff(u[0](x, t), x))

-2*alpha*u[0](x, t)*conjugate(u[0](x, t))*(diff(u[0](x, t), x))

For some specific function. evalc assumes all variables real

f := t^2*cos(x)+I*t*exp(x); eval(Q, u[0](x, t) = f); Q1 := evalc(%)

t^2*cos(x)+I*t*exp(x)

-2*alpha*(t^2*cos(x)+I*t*exp(x))*conjugate(t^2*cos(x)+I*t*exp(x))*(-t^2*sin(x)+I*t*exp(x))

-(-2*alpha*t^4*cos(x)^2-2*alpha*t^2*(exp(x))^2)*t^2*sin(x)+I*(-2*alpha*t^4*cos(x)^2-2*alpha*t^2*(exp(x))^2)*t*exp(x)

But when you want to enter a short form without giving explicit x and t dependence, diff(u[0],x) gives zero. So you can use Diff to avoid this.

Q2 := -2*alpha*u[0]*conjugate(u[0])*(Diff(u[0], x))

-2*alpha*u[0]*conjugate(u[0])*(Diff(u[0], x))

Then when you want to evaluate it for an explicit function:
Next line needs subs, not eval

subs(u[0] = f, Q2); value(%); evalc(%); simplify(%-Q1)

-2*alpha*(t^2*cos(x)+I*t*exp(x))*conjugate(t^2*cos(x)+I*t*exp(x))*(Diff(t^2*cos(x)+I*t*exp(x), x))

-2*alpha*(t^2*cos(x)+I*t*exp(x))*conjugate(t^2*cos(x)+I*t*exp(x))*(-t^2*sin(x)+I*t*exp(x))

-(-2*alpha*t^4*cos(x)^2-2*alpha*t^2*(exp(x))^2)*t^2*sin(x)+I*(-2*alpha*t^4*cos(x)^2-2*alpha*t^2*(exp(x))^2)*t*exp(x)

0

NULL

Download Diff.mw

@salim-barzani I didn't understand that. Can you give a very simple example of where conjugate doesn't allow you to do something which you want to do?

@salim-barzani You say "for diff(conjugate(u(x,t)),x) i use v[i,x]", but diff(conjugate(u(x,t)),x) is a function of t but v[i,x] is not. So for example the Laplace transform wrt t of v[i,x] will not be correct. If you fix these things up, I'll take another look.

I don't exactly understand what you want, but here are some remarks:

1. The calculation needs to be done iteratively (I think the paper uses recursively where I would use iteratively). So you need to work out all the n=0 things before the n=1 and so on. You can have one big loop but you cannot work out, say, A[0]..A[4], before you work out u[0](x,t)..u[4](x,t).

2. For debugging at least I would not use "declare"; it hides what is really happening. For example u[0](x,t) will appear as u[0], but so will u[0]. When you define B[0], you use u[0] but I think this has to be entered as u[0](x,t).

3. You ask about mixing u[i] with u[i,x]. It seems you should never have u[i.x] - only ever one subscript. The display of derivatives as subscripts doesn't mean they are actually subscripts (see point 2). The paper says u(0,x) is an initial condition, but that should be u(x,0) since you have functions of (x,t). So you can have u[2](x,0) but never anything like v[0,x] (which should be diff(v[0](x,t),x) or perhaps it means an initial condition v(x,0) but for which there presumably is a missing subscript.)

4. It is bad practice to use both u(x,t) and u[0](x,t) since they are not independent of each other; instead use U(x,t) and u[0](x,t). It may work if you are not going to assign to u, but things are not what they seem - try u[0](x,t):=g; then eval(u);

@Christopher2222 Well, maybe the symbols were generated by some other calculation which might or might have made them co-linear, but I agree that getting the assumptions right makes using the geometry package frustrating. The hints about what to assume are not always as clear as in this case.

@rockyicer  You can make your permutation matrix for the permutation [1,2,3,4] -> [2,1,4,3] using.

P := IdentityMatrix(4)[[2, 1, 4, 3]]

or you can just do the permutations of the rows and columns by

Y4_R := Y4[[2, 1, 4, 3], [2, 1, 4, 3]];

@acer Nice. I thought I had tried that, but I guess not.

@emendes assuming real is implied by beta>0. You need rho>1. It works as modified below. Notice that solve may ignore the assumptions unless you add the "useassumptions" option for solve. However, the solution is in a different form suggesting that it does take some note of them. If you do use the "useassumptions" option, it fails to solve in a reasonable time.

So for this reason I only use assuming clauses after solve and never assume before.

restart;

assume(beta>0,xi[3]>0,xi[8]>0,rho>1);

eqqq := map(simplify,{sqrt(beta*rho*xi[8]^2 - beta*xi[8]^2)/xi[8] = sqrt(beta*rho - beta), (-rho + 1 + sqrt(beta*rho*xi[8]^2 - beta*xi[8]^2))/(xi[3]*xi[8] - 1) = sqrt(beta*rho - beta), -(-rho*xi[3]*xi[8] + sqrt(beta*rho*xi[8]^2 - beta*xi[8]^2) + xi[3]*xi[8])/(xi[8]*(xi[3]*xi[8] - 1)) = rho - 1}):

In general, simplification on an expression to give zero is easier than comparing both sides of an equation. So I convert the equations to solve to expressions. (I could do this on the solutions after solving.)

eq3:=map(eq->(rhs-lhs)(eq),eqqq);

{0, beta^(1/2)*(rho-1)^(1/2)-(-rho+1+xi[8]*beta^(1/2)*(rho-1)^(1/2))/(xi[3]*xi[8]-1), rho-1-(-beta^(1/2)*(rho-1)^(1/2)+xi[3]*(rho-1))/(xi[3]*xi[8]-1)}

sol:=solve(eq3,{xi[8],xi[3]});

Warning, solve may be ignoring assumptions on the input variables.

{xi[3] = RootOf((beta^(1/2)*rho-beta^(1/2))*_Z^2+(-beta^(1/2)*rho-beta*(rho-1)^(1/2)+(rho-1)^(1/2)*rho+beta^(1/2)-(rho-1)^(1/2))*_Z-beta^(1/2)*rho+beta*(rho-1)^(1/2)+beta^(1/2)), xi[8] = -(-RootOf((beta^(1/2)*rho-beta^(1/2))*_Z^2+(-beta^(1/2)*rho-beta*(rho-1)^(1/2)+(rho-1)^(1/2)*rho+beta^(1/2)-(rho-1)^(1/2))*_Z-beta^(1/2)*rho+beta*(rho-1)^(1/2)+beta^(1/2))*(rho-1)^(1/2)+beta^(1/2)-(rho-1)^(1/2))/(RootOf((beta^(1/2)*rho-beta^(1/2))*_Z^2+(-beta^(1/2)*rho-beta*(rho-1)^(1/2)+(rho-1)^(1/2)*rho+beta^(1/2)-(rho-1)^(1/2))*_Z-beta^(1/2)*rho+beta*(rho-1)^(1/2)+beta^(1/2))*(rho-1)^(1/2))}

simplify(subs(sol,eq3));

{0}

sol:=solve(eq3,{xi[8],xi[3]},useassumptions);

Download solve.mw

@Saalehorizontale It's a bug. I put it in a loop and for some reason the 9th one gives a problem (after verifying that index = 2 is correct). I have submitted a bug report.

RootOf_with_Error.mw

@Saalehorizontale Sorry, I mislead you. For a RootOf without an index, the index=1 is implied for evalf or other contexts. But you are right that it can be any of the roots of the minimal polynomial, which was just a polynomial until I turned it into a RootOf. You can check through the roots of the minimal polynomial with an exact calculation without having to worry about numerical issues; see attached.

RootOf.mw

@Carl Love @acer Thanks for the clarification; I've had that misconception for a long time. But why not have the output of p:=plot(...); the same as the actual plot? In most cases p:=foo(..); p; would give duplicate outputs.

@Saalehorizontale If not specified, it is the index = 1 root. I added a line to my answer above to check that. The order is given in the ?RootOf,indexed help page

3 4 5 6 7 8 9 Last Page 5 of 85