dharr

Dr. David Harrington

908 Reputation

13 Badges

15 years, 22 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 professor of chemistry at the University of Victoria, BC, Canada, where my research areas are electrochemistry and surface science. I have been a user of Maple since about 1992.

MaplePrimes Activity


These are answers submitted by dharr

In the File Menu under Document Properties, you should have an attribute named Active which is false for a regular help page and true for an active worksheet.

in 1D input:

ode:=diff(y(x),x,x)=2*y(x)+1;
dsolve(ode);
 

does work, so this is probably incorrect entry of the derivative in 2-D math. [Edit: actually the error message confirms this.] Use the right-click menu 2-D math/convert to 1D math input and see if it looks like the above. If not, use 1-D input (ctrl-M) before the input, or use the expression palette for the derivative and use "^" to raise the powers of 2.

I don't understand exactly what you mean - if you want real-only frequency domain, you need the time domain array to have the real part  symmetric about the centre and the imaginary part antisymmetric about the centre.

Edit: And here is a complex example that works pretty much as I would expect:

restart;

with(DiscreteTransforms):

N:=2^10;df:=.2;dt:=1/df;T1:=500.;

1024

.2

5.000000000

500.

tvec:=Vector(N,i->i*dt):
fvec:=Vector(N,i->i*df):

fidr:=Vector(N,i->cos(2*Pi*df*i)*exp(-dt*i/T1)):
fidi:=Vector(N,i->sin(2*Pi*df*i)*exp(-dt*i/T1)):
fid:=fidr+I*fidi:

plot(tvec,fidr);

spec:=FourierTransform(fid):

plot(fvec,map(abs,spec)); #magnitude

plot(fvec,map(Im,spec));  #imaginary part

plot(fvec,map(Re,spec));  #real part

 


 

Download fid.mw


 

restart;
with(ThermophysicalData);
with(ThermophysicalData[CoolProp]);
fluid := "R717"; T__in := 310; p__in := 11*10^5; v__in := 10;  A := 0.005;
h__in := Property(massspecificenthalpy, T = T__in, P = p__in, fluid);
rho__in := Property(density, T = T__in, P = p__in, fluid);
m := A*v__in*rho__in;
p__out := 2*10^5;
eq1 := h__out = Property("massspecificenthalpy", "temperature" = T__out, "P" = p__out, fluid);
eq2 := rho__out = Property("D", "temperature" = T__out, "P" = p__out, fluid);
eq3 := h__in + v__in^2/2 = h__out + v__out^2/2;
eq4 := m = A*v__out*rho__out;

res := fsolve({eq1, eq2, eq3, eq4});

[CoolProp, PHTChart, Property, PsychrometricChart, TemperatureEntropyChart]

[HAPropsSI, PhaseSI, Props1SI, PropsSI]

"R717"

310

1100000

10

0.5e-2

1655590.94731116970

8.15132757401520891

.4075663787

200000

h__out = ThermophysicalData:-Property("massspecificenthalpy", "temperature" = T__out, "P" = 200000, "R717")

rho__out = ThermophysicalData:-Property("D", "temperature" = T__out, "P" = 200000, "R717")

1655640.947 = h__out+(1/2)*v__out^2

.4075663787 = 0.5e-2*v__out*rho__out

{T__out = 285.0179004, h__out = 1654113.289, v__out = 55.27490598, rho__out = 1.474688637}

 


 

Download CoolProp.mw

Under the file/open menu, you can open a Mathematica notebook. I haven't tried this, but presumably it automates what can be done by the commands that @tomleslie pointed out.

See the help for the GraphTheory package, ?GraphTheory. This is a hard problem (see the Wikipedia page), and as far as I can see, Maple has no direct commands for this. Some of the commands there may help you, but if you want an efficient routine you would probably need to write something for the class of graphs you are interested in.


 

f := (a,b,c)->a*b*c;

proc (a, b, c) options operator, arrow; a*b*c end proc

F:=proc(f,val) local fargs;
fargs:=op(1,eval(f)); #parameter sequence
f(val,fargs[2..]);
end proc;

proc (f, val) local fargs; fargs := op(1, eval(f)); f(val, fargs[2 .. ()]) end proc

F(f,3);

3*b*c

 


 

Download fargs.mw

If you don't have tau = 0, then Maple will carry out operations that are generally valid, but may not be for tau=0. So if you then set tau=0, you may get an invalid result. For example here, the 2,2 entry has a denominator that becomes zero if tau=0, and so a division by zero problem arises, which would not have done if Maple had manipulated knowing tau=0.

To assume everything is positive works here
 

f := (Pi*x+2*c+2*m)/(`μ__c`*S)+2*`ε`/(`μ__a`*S)+(Pi*x+2*c)/(`μ__s`*S)

(Pi*x+2*c+2*m)/(mu__c*S)+2*epsilon/(mu__a*S)+(Pi*x+2*c)/(mu__s*S)

g := simplify(f, symbolic)

(((Pi*x+2*c+2*m)*mu__s+2*mu__c*((1/2)*Pi*x+c))*mu__a+2*epsilon*mu__c*mu__s)/(mu__c*S*mu__a*mu__s)

`assuming`([int(1/g, x = 0 .. w, AllSolutions)], [positive]) =
S*mu__c*mu__s*(ln(Pi*mu__a*mu__c*w+Pi*mu__a*mu__s*w+2*c*mu__a*mu__c+2*c*mu__a*mu__s+2*epsilon*mu__c*mu__s+2*m*mu__a*mu__s)-ln(2)-ln(c*mu__a*mu__c+c*mu__a*mu__s+epsilon*mu__c*mu__s+m*mu__a*mu__s))/(Pi*(mu__c+mu__s))
NULL

``


 

Download IntAssPositive.mw

 

Download Dirac2.mw
 

restart;

with(IntegrationTools):

int(Dirac(x),x=-infinity..infinity);

1

q:=Int(Dirac(x)^2,x=-infinity..infinity);
value(q);

Int(Dirac(x)^2, x = -infinity .. infinity)

int(Dirac(x)^2, x = -infinity .. infinity)

Now generally,

int(f(x)*Dirac(x-a),x=-infinity..infinity);

f(a)

So we may expect if a=0 and f(x)=Dirac(x), then the integral is Dirac(0). But we can't get it directly

int(Dirac(x)*Dirac(x),x=-infinity..infinity);

int(Dirac(x)^2, x = -infinity .. infinity)

Though integration by parts will do it.

Parts(q,Dirac(x));
value(%);

-(Int(Heaviside(x)*Dirac(1, x), x = -infinity .. infinity))

Dirac(0)

But it doesn't really help becasue Dirac(0) is not defined...


 

Download Dirac2.mw

 

Like this?


 

restart

rowX, colX := [2, 4], [11, 11, 12, 14, 14, 15]

rowY, colY := [1, 3], [2, 5, 8, 2, 5, 8]

rowlabels, collabels := [A, B], [a, b, c, d, e, f]

m, n := numelems(rowX), numelems(colX)

2, 6

T := Matrix(m, n, proc (i, j) options operator, arrow; sqrt((rowX[i]-colX[j])^2+(rowY[i]-colY[j])^2) end proc)

Distance := DataFrame(T, 'rows' = rowlabels, 'columns' = collabels)

Distance := Matrix(3, 7, {(1, 1) = ``, (1, 2) = a, (1, 3) = b, (1, 4) = c, (1, 5) = d, (1, 6) = e, (1, 7) = f, (2, 1) = A, (2, 2) = 82^(1/2), (2, 3) = 97^(1/2), (2, 4) = 149^(1/2), (2, 5) = 145^(1/2), (2, 6) = 4*10^(1/2), (2, 7) = 218^(1/2), (3, 1) = B, (3, 2) = 5*2^(1/2), (3, 3) = 53^(1/2), (3, 4) = 89^(1/2), (3, 5) = 101^(1/2), (3, 6) = 2*26^(1/2), (3, 7) = 146^(1/2)})

 


 

Download Datafrome.mw

Just for another variation. At least in Maple 2017, I can't export the DataFrame to Excel, even though it can import into a Dataframe.
 

restart;

with(GraphTheory):

X := [3, 6, 4, 13]:   Y := [8, 6, 5, 7]: lbls:=[A,B,C,D];
Pts:=zip((x,y)->[x,y],X,Y);
Pts2:=map(x->x[1]+I*x[2],Pts);
n:=numelems(Pts);

[A, B, C, D]

[[3, 8], [6, 6], [4, 5], [13, 7]]

[3+8*I, 6+6*I, 4+5*I, 13+7*I]

4

dists:=Matrix(n,n,(i,j)->abs(Pts2[i]-Pts2[j]),shape=symmetric):
df:=DataFrame(dists,'rows'=lbls,'columns'=lbls);

df := Matrix(5, 5, {(1, 1) = ``, (1, 2) = A, (1, 3) = B, (1, 4) = C, (1, 5) = D, (2, 1) = A, (2, 2) = 0, (2, 3) = 13^(1/2), (2, 4) = 10^(1/2), (2, 5) = 101^(1/2), (3, 1) = B, (3, 2) = 13^(1/2), (3, 3) = 0, (3, 4) = 5^(1/2), (3, 5) = 5*2^(1/2), (4, 1) = C, (4, 2) = 10^(1/2), (4, 3) = 5^(1/2), (4, 4) = 0, (4, 5) = 85^(1/2), (5, 1) = D, (5, 2) = 101^(1/2), (5, 3) = 5*2^(1/2), (5, 4) = 85^(1/2), (5, 5) = 0})

G := Graph(dists,lbls):
SetVertexPositions(G,Pts):
DrawGraph(G);

 


 

Download Points.mw

An example of solving a PDE with Laplace transforms (with both initial and boundary conditions) is given in the Application Center:

https://www.maplesoft.com/applications/view.aspx?SID=96958 

Try simplify(my_sol) assuming cos(2*x)>=0; Now it really is simpler. But is that valid for your case?

Maple doesn't want to make assumptions that aren't generally true. So if you want to know really what the conditions are, you need to think about why csgn or signum appeared and then make the appropriate assumptions, if they are valid for your problem. They often arise from sqrts of negative arguments, as here. If you want to be more reckless (I usually do this in these cases), just use simplify( , symbolic) and bear in mind that the answer has some unwritten assumptions.

In Maple 2017, the steps through to the standard separation of variable solution can be done step by step. Solution is complex (imaginary)


 

restart;

pde := diff(c(x, t), x, x) - h*diff(c(x, t), x) - diff(c(x, t), t);
iv := c(0, t) = 0, c(a, t) = 0, c(x, 0) = c0;

diff(diff(c(x, t), x), x)-h*(diff(c(x, t), x))-(diff(c(x, t), t))

c(0, t) = 0, c(a, t) = 0, c(x, 0) = c0

Maple suggests a separation of variables.

gensol:=pdsolve(pde);
de1:=op(2,gensol)[][1];

PDESolStruc(c(x, t) = _F1(x)*_F2(t), [{diff(_F2(t), t) = _F2(t)*_c[1], diff(diff(_F1(x), x), x) = _c[1]*_F1(x)+(diff(_F1(x), x))*h}])

diff(_F2(t), t) = _F2(t)*_c[1]

solution of the first de gives an exponential. Presumably t is time and so _c[1] will be negative - call it -lambda

dsolve(de1);

_F2(t) = _C1*exp(_c[1]*t)

and seek solution f(x)*exp(-lambda*t). Just the same as _F1(t) above

de2:=simplify(eval(pde,c(x,t)=f(x)*exp(-lambda*t))/exp(-lambda*t));

-h*(diff(f(x), x))+f(x)*lambda+diff(diff(f(x), x), x)

Solve this de with bc at x=0 c(0,t)=0 => f(0)=0. Divide by the scale factor _C2, which we will put in later (otherwise solving for zero will give the trivial solution _C2=0).

ans:=simplify(rhs(dsolve({de2,f(0)=0}))/_C2);

-exp((1/2)*(h+(h^2-4*lambda)^(1/2))*x)+exp(-(1/2)*(-h+(h^2-4*lambda)^(1/2))*x)

Now we need to find the eigenvalues using the other boundary condition - turns out there is an exact solution. _Z1 means any integer - rename it n, and substitute it back into above.

expand(solve(eval(ans,x=a),lambda,allsolutions));
lambda=subs(_Z1=n,%);
cc:=eval(ans*exp(-lambda*t),%);

(1/4)*h^2+Pi^2*_Z1^2/a^2

lambda = (1/4)*h^2+Pi^2*n^2/a^2

(-exp((1/2)*(h+(-4*Pi^2*n^2/a^2)^(1/2))*x)+exp(-(1/2)*(-h+(-4*Pi^2*n^2/a^2)^(1/2))*x))*exp(-((1/4)*h^2+Pi^2*n^2/a^2)*t)

Solution is complex. Since n=0 gives solution everywhere zero, eigenvalues start with n=1

ccc:=simplify(evalc(cc)) assuming n::posint,a::positive;
eval(ccc,n=0);

-(2*I)*exp(-(1/4)*(4*Pi^2*n^2*t+a^2*h^2*t-2*a^2*h*x)/a^2)*sin(n*Pi*x/a)

0

Check that the solution works for all positive n (except for the initial condition)

map(simplify,pdetest(c(x,t)=ccc,[pde,iv[1..2]])) assuming n::posint,a::positive;

[0, 0, 0]

General solution is a sum of these, where scale factor b is determined by the initial condition (and isn't easily found symbolically)

sol:=c(x,t)=b*Sum(ccc,n=1..infinity);
value(%);

c(x, t) = b*(Sum(-(2*I)*exp(-(1/4)*(4*Pi^2*n^2*t+a^2*h^2*t-2*a^2*h*x)/a^2)*sin(n*Pi*x/a), n = 1 .. infinity))

c(x, t) = b*(sum(-(2*I)*exp(-(1/4)*(4*Pi^2*n^2*t+a^2*h^2*t-2*a^2*h*x)/a^2)*sin(n*Pi*x/a), n = 1 .. infinity))

 


 

Download pdsolve.mw

1 2 3 4 5 6 7 Last Page 1 of 20