Rouben Rostamian

MaplePrimes Activity


These are answers submitted by Rouben Rostamian

If you are comfortable with C programming, you should be able to write your own implementation of KroneckerProduct() in C and compile it with the rest of your program.  When you call f() as exported by Maple, when it hits the call to KroneckerProduct(), it will execute your own version of that function.

The effective writing of such a KroneckerProduct() function will depend on your C programming skills, and some details that are missing in what you have written.  Here are some thoughts:

  1. In your example, A, B, and their Kronecker product are single-column matrices.  If single-columns matrices are all you need, then the C program becomes significantly simpler because you may use one-dimensional arrays to represent them.
  2. In your example, A and B have 3 rows each.  If 3-row matrices are all you need, then the C program becomes even simpler.
  3. How familiar are you with the various C standards?  The C99 standard introduced variable length arrays, which can help with your program.  The previous standard, C89, recognizes only arrays whose sizes are known at the compile time.  Variable length arrays may be simulated in C89 through dynamic memory allocation with malloc() and related functions.  You need to decide which method you want to use.

 

  • Look at your s[2].  On the left, you have E(t).  On the right you have E.  That should be E(t).  Also on the right you have lambda[2] and lambda[3].  Those should be lambda[2](t) and lambda[3](t).  Similar errors occurs in several other places.  Need to go over your input very carefully and fix those things.
  • In s[5] you have lambda[1]*t.  That should be lambda[1](t).
  • You have set tf := T, but you didn't say what T is.  Need to specify a numerical value for T.
  • Don't apply Maple commands blindly.  You have defined fcns[1] := ... and ended that line with a colon.  Replace the colon with a semicolon to verify that Maple understands you correctly.  Similarly, you call dsolve with the arugment
    {seq(s[i], i = 1 .. 8), seq(lambda[i](tf) = 0, i = 1 .. 4), E(0) = E0, In(0) = In0, R(0) = R0, S(0) = S0}

    Before calling dsolve, enter that argument on a line of its own and examine what Maple prints very carefully to verify that what you are later passing to dsolve is in agreement with what you have in mind.

 

I am not familiar with Mathematica, so I am just guessing from your example what the Cases command is expected to do.  It appears that it picks all instances of sin(...) in a given expression.  Here is how that is done in Maple:

expr := [sin(x)/(sin(2-x)+1)-12, sin(x/2)^2, cos(x)];
indets(expr, 'specfunc(sin)');

That yields {sin(x), sin(-2 + x), sin(x/2)}.

This site is on the blink again and won't let me display my worksheet.   Here is the link to a worksheet that shows how to solve the system of PDEs through finite differences.

Download strange-PDE.mw

restart;

with(plots):

A1 := proc(t)
        pointplot([t,t], symbol=solidcircle, symbolsize=50, color=red);
end proc:

A2 := proc(t)
        pointplot([t,t], symbol=solidcircle, symbolsize=50, color=blue);
end proc:

display([
        animate(A1, [t], t=-1..0),
        animate(A2, [t], t=0..1)
], insequence);

 

 

Download mw.mw

 

Your equations are uncoupled.  You may call pdsolve() to solve each of them separately.  That works on all versions of Maple that I have tried.

In principle, pdsolve() should be able to solve the two (uncoupled) equations together as a system, but that fails in Maple 2022 as we see in the attached worksheet.

Here is how things work on solving the system in various versions of Maple:

  • Maple 2017 and 2018 return no solutions, and no errors;

  • Maple 2019, 2020, 2021 return the correct solution;

  • Maple 2022 fails on error.

restart;

kernelopts(version);

`Maple 2022.2, X86 64 LINUX, Oct 23 2022, Build ID 1657361`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1354. The version installed in this computer is 1342 created 2022, November 2, 11:29 hours Pacific Time, found in the directory /home/rouben/maple/toolbox/2022/Physics Updates/lib/`

Pdsolve gets the correct solution here:

pde1 := diff(u(x,t),t) = 0;
ic1 := u(x,0) = f(x);

diff(u(x, t), t) = 0

u(x, 0) = f(x)

pdsolve({pde1,ic1});

u(x, t) = f(x)

Pdsolve gets also the correct solution here:

pde2 := diff(v(x,t),t) = 0;
ic2 := v(x,0) = g(x);

diff(v(x, t), t) = 0

v(x, 0) = g(x)

pdsolve({pde2,ic2});

v(x, t) = g(x)

BUG: Pdsolve gets confused when solving the two (uncoupled) equations together:

pdsolve({pde1, pde2, ic1, ic2});

Error, (in pdsolve) invalid input: indets expects 1 or 2 arguments, but received 3

 

Download mw.mw

Note added Nov 30, 2022

The outcome of the discussion that followed this post was that Maple 2022's pdsolve() was not at fault after all.  The trouble was due to a not-up-to-date version of the Physics package on my machine, and it was resolved after upgrading to the latest version of the Physics package.

 

I am not going to do the entire homework for you but here is something to get you started.
 

plot(8+8*sin(theta), theta=0..2*Pi, coords=polar, scaling=constrained);

 

plot3d(25 - x^2, x=0..5, y=1..8, view=[0..5,0..8,default]);

 

plots:-display(
    plot3d([10*cos(t)*cos(s), 10*cos(t)*sin(s), 10*sin(t)], t=-arccos(6/10)..arccos(6/10), s=-Pi..Pi),
    plot3d([6*cos(t), 6*sin(t), s], t=-Pi..Pi, s=-8..8),
color=["Green","Red"], style=surface, scaling=constrained, lightmodel=light4);

 


 

Download mw.mw

 

I have not examined the source of the error in your worksheet, but I would suggest using the facilities provided in the Physics[Vectors] package for encoding the Rodrigues formula rather than homogeneous transformation matrices, because the math works more naturally this way.  This worksheet shows how.

restart;

with(Physics[Vectors]):

Rodrigues'  formula:
Rotates the vectorNULL`#mover(mi("v"),mo("→"))` about the unit vecor `#mover(mi("k"),mo("→"))` by the angle alpha:

v__rot_ := v_*cos(alpha) + (k_ &x v_)*sin(alpha) + (k_ . v_)*(1 - cos(alpha))*k_;

v_*cos(alpha)+Physics:-Vectors:-`&x`(k_, v_)*sin(alpha)+Physics:-Vectors:-`.`(k_, v_)*(1-cos(alpha))*k_

Make that into a procedure: Usage:  v__rot = R(`#mover(mi("v"),mo("→"))`, `#mover(mi("k"),mo("→"))`, alpha)

R := unapply(v__rot_, v_, k_, alpha);

proc (v_, k_, alpha) options operator, arrow; v_*cos(alpha)+Physics:-Vectors:-`&x`(k_, v_)*sin(alpha)+Physics:-Vectors:-`.`(k_, v_)*(1-cos(alpha))*k_ end proc

Example 1

 

Pick a unit vector:

1*_i + 2*_j + 3*_k:
k_ := % / sqrt(% . %);

(1/14)*(_i+2*_j+3*_k)*14^(1/2)

Pick an arbitrary vector:

v_ := _i - 3*_j + 2*_k;

_i-3*_j+2*_k

Pick a rotation angle:

alpha := Pi/6;

(1/6)*Pi

Find the rotated vector:

R(v_, k_, alpha):
collect(%, [_i, _j, _k]);

((13/28)*3^(1/2)+(13/28)*14^(1/2)+1/14)*_i+(-(11/7)*3^(1/2)+(1/28)*14^(1/2)+1/7)*_j+((25/28)*3^(1/2)-(5/28)*14^(1/2)+3/14)*_k

 

Example 2

 

Composite rotation

A unit vector:

k__1_ := k_;

(1/14)*(_i+2*_j+3*_k)*14^(1/2)

Another unit vector

k__2_ := subs(_j=-_j, k__1_);

(1/14)*(_i-2*_j+3*_k)*14^(1/2)

Rotate `#mover(mi("v"),mo("→"))` about `#msub(mi("k"),mi("1_"))`by (1/6)*Pi and then rotate the result about `#mi("\`k__2\`")` by (1/4)*Pi:

R(R(v_, k__1_, Pi/6), k__2_, Pi/4):
collect(%, [_i, _j, _k], simplify);

((1/392)*(3*3^(1/2)-4*7^(1/2)+57)*2^(1/2)+(1/392)*(82*7^(1/2)+176)*3^(1/2)+(81/196)*7^(1/2)+3/98)*_i+((1/196)*(-66*3^(1/2)+4*7^(1/2)+174)*2^(1/2)+(1/196)*(7*7^(1/2)-176)*3^(1/2)+(3/196)*7^(1/2)-3/49)*_j+((1/392)*(-89*3^(1/2)-12*7^(1/2)+213)*2^(1/2)+(1/392)*(-18*7^(1/2)+528)*3^(1/2)-(25/196)*7^(1/2)+9/98)*_k

 

 

Download mw.mw

 

 

 

restart;

kernelopts(version);

`Maple 2022.2, X86 64 LINUX, Oct 23 2022, Build ID 1657361`

pd1 := diff(u(x,t),t) = diff(u(x,t),x,x) + (1-alpha)*u(x,t);

diff(u(x, t), t) = diff(diff(u(x, t), x), x)+(1-alpha)*u(x, t)

pd2 := diff(v(x,t),t) = mu*diff(v(x,t),x,x) + beta*v(x,t) + alpha*u(x,t);

diff(v(x, t), t) = mu*(diff(diff(v(x, t), x), x))+beta*v(x, t)+alpha*u(x, t)

ics := u(x,0) = Dirac(x), v(x,0) = 0;

u(x, 0) = Dirac(x), v(x, 0) = 0

Maple is unable solve the system sympolically on its own:

pdsolve({pd1, pd2, ics}) assuming t > 0, mu > 0;

but it can, with a little help.

 

The first PDE has only the unknown u, so we solve it for u:

sol1 := pdsolve({pd1,ics[1]}) assuming t > 0;

u(x, t) = (1/2)*exp((1/4)*((-4*alpha+4)*t^2-x^2)/t)/(t^(1/2)*Pi^(1/2))

Then, substitute the result in the second PDE, and solve that for v:

subs(sol1, pd2);
sol2 := pdsolve({%, ics[2]}) assuming t > 0, mu > 0;

diff(v(x, t), t) = mu*(diff(diff(v(x, t), x), x))+beta*v(x, t)+(1/2)*alpha*exp((1/4)*((-4*alpha+4)*t^2-x^2)/t)/(t^(1/2)*Pi^(1/2))

v(x, t) = alpha*((erf((1/2)*(-2*((-alpha-beta+1)/(mu-1))^(1/2)*t+x)/t^(1/2))-erf((1/2)*(-2*t*mu*((-alpha-beta+1)/(mu-1))^(1/2)+x)/(mu^(1/2)*t^(1/2))))*exp((-x*(mu-1)*((-alpha-beta+1)/(mu-1))^(1/2)-((-1+alpha)*mu+beta)*t)/(mu-1))-exp((x*(mu-1)*((-alpha-beta+1)/(mu-1))^(1/2)-((-1+alpha)*mu+beta)*t)/(mu-1))*(erf((1/2)*(2*((-alpha-beta+1)/(mu-1))^(1/2)*t+x)/t^(1/2))-erf((1/2)*(2*t*mu*((-alpha-beta+1)/(mu-1))^(1/2)+x)/(mu^(1/2)*t^(1/2)))))/(((-alpha-beta+1)/(mu-1))^(1/2)*(4*mu-4))

 

Download mw.mw

 

In several places you have used square brackets [...] and curly braces {...} for grouping your mathematical terms.  In Maple, the only delimiters that you can use for that purpose are the parentheses (...).

Adjust your code as necessary and write back if it still does not work.

delvin, you should know that your equations are not comprehensible to people who are unfamiliar with numerals written in the Farsi/Persian script.  If you desire to reach the widest available help, make an effort to write your mathematics in symbols which most of the readers of this forum can understand.

Anyway, here is the answer to your question.

 

restart;

You wish to perform your hand calculation in Maple.  Here is the original expression:

c := (-exp(4*d)*beta^2 + 4*alpha*exp(4*d) + beta^2 - 4*alpha)/(8*exp(2*d));

(1/8)*(-exp(4*d)*beta^2+4*alpha*exp(4*d)+beta^2-4*alpha)/exp(2*d)

and here is the simplified form obtained by Maple:

convert(simplify(c), trigh);

(-(1/4)*beta^2+alpha)*sinh(2*d)

      That agrees with your hand calculation.

 

 

 

restart;

g := x -> piecewise(x - 1/3 = 0, 1, 0);

g := proc (x) options operator, arrow; piecewise(x-1/3 = 0, 1, 0) end proc

g(3+1/3);

0

g(0+1/3);

1

 

Download mm.mw

 

 

restart;

Take m = 1 and renane "(∂phi)/(∂ xi)" to y:

1/2*y^2 + (1-cos(phi)) = h+2:
solve(%, y):
f := unapply(%[1], phi, h);

proc (phi, h) options operator, arrow; (2*cos(phi)+2*h+2)^(1/2) end proc

seq(f(phi,h), h in [-1,0,1]), seq(-f(phi,h), h in [-1,0,1]);
plot([%], phi=-Pi..3*Pi, size=[800,500]);

2^(1/2)*cos(phi)^(1/2), (2*cos(phi)+2)^(1/2), (2*cos(phi)+4)^(1/2), -2^(1/2)*cos(phi)^(1/2), -(2*cos(phi)+2)^(1/2), -(2*cos(phi)+4)^(1/2)

 

Download mw.mw

 

That initial value problem has infinitely many solutions.  Have a look at this worksheet.

restart;

ode := diff(v(t),t) = -2*v(t)^(2/3);

diff(v(t), t) = -2*v(t)^(2/3)

Find the general solution

dsolve(ode);
dsol := isolate(%, v(t));

v(t)^(1/3)+(2/3)*t-c__1 = 0

v(t) = (-(2/3)*t+c__1)^3

Let c__1 = 0:

eval(dsol, c__1 = 0);

v(t) = -(8/27)*t^3

That's a solution of the ODE with the initial condition v(0) = 0.

That, however, is not the only solution.  The following is also

a solution of the initial value problem for any choice of a > 0NULL

sol := piecewise(t < a, 0, -(8*(t-a)^3)/27);

sol := piecewise(t < a, 0, -8*(t-a)^3*(1/27))

Here is what the solution looks like when a = 2:

eval(sol, a=2);
plot(%, t=0..4, color=red, thickness=5);

piecewise(t < 2, 0, -8*(t-2)^3*(1/27))

Download mw.mw

 

 

The trailing tilde is not a part of  Omega; it is there to remind you that you have made assumptions on it.

If you don't want to see those reminders, disable them with inserting interface(showassumed=0); near the top of your worksheet.

4 5 6 7 8 9 10 Last Page 6 of 53