tomleslie

13836 Reputation

20 Badges

14 years, 342 days

MaplePrimes Activity


These are replies submitted by tomleslie

@mmcdara 

but the following paragraph (emphasis added) from https://en.wikipedia.org/wiki/Autocorrelation appeared significant.

Different fields of study define autocorrelation differently, and not all of these definitions are equivalent. In some fields, the term is used interchangeably with autocovariance.

@Carl Love 
Some excerpts from Maple help (emphasis added occasionally)

A set is an unordered sequence of distinct expressions enclosed in braces {}, representing a set in the mathematical sense.

Note:  This order could be changed in future versions of Maple, and/or objects could be represented in a different way in future versions. You should not assume that sets will be maintained in any particular order.

Please  feel free to use "order"  with sets!

 

 

 

@Ronan 

There is a bit of a trade-off to be considered. If everyy input is expressed in exact numbers ( eg rationals or integers) then all calculations will be performed using exact numbers. Depending on the complexity of the calculations you are performing, this can lead to very complicated expressions, which *may* skiw down processing. One can circumvent this problem by supplying iall numerica inputs as floats (see the attached, which will execute "faster" than my original response).

There are however drawbacks to using floats. Certain commands within the geometry package require computing exact equality between two different expressions (consider for example, IsOnCircle() or IsOnLine() ). As a general programming rule, testing for equality between two floating-point numbers, computed in two different calculations is a big no-no. Being off by 1 in the 10th decimal place will kill you.

You have a choice between time and code robustness - pick one because you can't have both!!

@arashghgood

  1. Your ode system can be solved analytically (see the attached), so why are you doing it numerically???
  2. Your worksheet states "u_hat[i]s are in Fourier space. I have to apply inverse Fourier transform and plot the u(t)". But your worksheet has the independent variable of all u_hat[i] as 't'. For clarity, should this be u_hat[i](omega) ? I know this may just be a notation issue, but you should make it really clear whether the uhat[i] are frequency- or time-domain functions. That way it is clear whether one needs to use a Fourier transfrom or an inverse Fourier transform to generate the correspondin time- or frequency-domain functions.


 

restart;

with(DEtools):

# define the complex numbers list1 and list2
list1 := [ [0., -5.496799068*10^(-15)-0.*I], [.1, 5.201897725*10^(-16)-1.188994754*I], [.2, 6.924043163*10^(-17)-4.747763855*I], [.3, 2.297497722*10^(-17)-10.66272177*I], [.4, 1.159126178*10^(-17)-18.96299588*I] ] ;

list2 :=[ [0., -8.634351786*10^(-7)-67.81404036*I], [.1, -0.7387644021e-5-67.76491234*I], [.2, -0.1433025271e-4-67.59922295*I], [.3, -0.2231598645e-4-67.25152449*I], [.4, -0.3280855430e-4-66.56357035*I] ];

[[0., -0.5496799068e-14-0.*I], [.1, 0.5201897725e-15-1.188994754*I], [.2, 0.6924043163e-16-4.747763855*I], [.3, 0.2297497722e-16-10.66272177*I], [.4, 0.1159126178e-16-18.96299588*I]]

 

[[0., -0.8634351786e-6-67.81404036*I], [.1, -0.7387644021e-5-67.76491234*I], [.2, -0.1433025271e-4-67.59922295*I], [.3, -0.2231598645e-4-67.25152449*I], [.4, -0.3280855430e-4-66.56357035*I]]

(1)

# define the differential equation system
ode_system := [];
ic_system :=[];
for i from 1 to 5 do
  ode_system := [op(ode_system), diff(u_hat[i](t),t,t) + I*(list1[i][2]+list2[i][2])*diff(u_hat[i](t),t) - list1[i][2]*list2[i][2]*u_hat[i](t) = 0];
  ic_system := [op(ic_system), u_hat[i](0) = 1, D(u_hat[i])(0) = 0]
end do:

[]

 

[]

(2)

#sol := dsolve( map(op, [ode_system, ic_system]), numeric, output = listprocedure );

(3)

#If it is correct, u_hat[i]s are in Fourier space. I have to apply inverse Fourier transform and plot the u(t).
#Is the dsolve above correct?
#How do next steps?

#
# Why is OP doing this problem numerically?
#
  sol:=evalf~(dsolve( map(op, [ode_system, ic_system]))):
  eval( u_hat[1](t), sol);
  eval( u_hat[2](t), sol);
  eval( u_hat[3](t), sol);
  eval( u_hat[4](t), sol);
  eval( u_hat[5](t), sol);
  

(1.000000000-0.83e-16*I)*exp((0.+0.53e-14*I)*t)+(0.+0.83e-16*I)*exp((-67.81404036+0.8634351787e-6*I)*t)

 

(1.017859232+0.198176232e-8*I)*exp((-1.188994760-0.1000000000e-14*I)*t)+(-0.178592318e-1-0.198176232e-8*I)*exp((-67.76491232+0.7387644021e-5*I)*t)

 

(1.075539437+0.172231360e-7*I)*exp((-4.747763855+0.*I)*t)+(-0.755394373e-1-0.172231360e-7*I)*exp((-67.59922295+0.1433025271e-4*I)*t)

 

(1.188424586+0.743058752e-7*I)*exp((-10.66272178-0.5000000000e-14*I)*t)+(-.1884245865-0.743058752e-7*I)*exp((-67.25152448+0.2231598646e-4*I)*t)

 

(1.398377458+0.2745804775e-6*I)*exp((-18.96299588+0.5000000000e-14*I)*t)+(-.3983774581-0.2745804775e-6*I)*exp((-66.56357035+0.3280855430e-4*I)*t)

(4)

 

 

 

 


 

Download FT.mw

@arashghgood 

the complete worksheet using the big green up-arrow in the Mapleprimes toolbar

@arashghgood 

Error, (in dsolve) too many arguments; some or all of the following are wrong: [{u[1](t), u[2](t), u[3](t), u[4](t), u[5](t)}, numerical, output = listprocedure]

should be numeric, as in

 [{u[1](t), u[2](t), u[3](t), u[4](t), u[5](t)}, numeric, output = listprocedure]

does this code offer compared with the NyQuistPlot() command in Maple's DynamicSystems() package?

See the help at ?NyQuistPlot

does not execute in Maple 2022. Too many errors for me to debug

n my Maple 2018, some of the execution groups do not produce the output which you display. I have no idea how you achieved this - and I am no longer prepared to guess.

The only thing I can suggest is that you stop writing code, and instead analyse the attached very carefully. When you understand it, you *may* be able to point out whether or not I have made a logical error.

It might also be useful to supply the original ODEs so that I  could run Maple's numerical ODE solver, to compare results with this implementation of the "hpm method"

  restart:

  N:= 3: M:= 0.1: Kp:= 0.1: Gr:= 0.01: Gc:= 0.01:
  Pr:= 1: S:= 0.01: Sc:= 0.78: Kc:= 0.01: La:= 1:

  f__N:=  add((p^(i))*f[i](x), i = 0 .. N):
  Theta__N:=  add((p^(i))*Theta[i](x), i = 0 .. N):
  Phi__N:= add((p^(i))*Phi [i] (x), i = 0 .. N):

  odeSys:= { (1-p)*(diff(f__N, x, x, x))+p*(diff(f__N, x, x, x)+(1/2)*(diff(f__N, x, x))*f__N-(M^2+Kp)*(diff(f__N, x)-La)+Gr*Theta__N+Gc*Phi__N),
             (1-p)*(diff(Theta__N, x, x))/Pr+p*((diff(Theta__N, x, x))/Pr+(1/2)*(diff(Theta__N, x))*f__N+S*Theta__N),
             (1-p)*(diff(Phi__N, x, x))/Sc+p*((diff(Phi__N, x, x))/Sc+(1/2)*(diff(Phi__N, x))*f__N+Kc*Phi__N)
           }:

  cond:= f[0](0) = 0,     D(f[0])(0) = 0,  D(f[0])(5) = 1,
         Theta[0](0) = 1, Theta[0](5) = 0,
         Phi[0](0) = 1,   Phi[0](5) = 0:
  ans:={}:

  for k from 0 by 1 to N do
      ans:= `union`
            ( ans,
              dsolve
              ( { eval
                  ( coeff~(odeSys, p, k),
                    ans
                  )[],
                  cond
                }
              )
           ):
      cond:= f[k+1](0) = 0, D(f[k+1])(0) = 0, (D(f[k+1]))(5) = 0,
             Theta[k+1](0) = 0, Theta[k+1](5) = 0,
             Phi[k+1](0) = 0, Phi[k+1](5) = 0:
  od:

  getfunc:= z-> z=eval( z, evalf~(ans)):

  for k from 0 to N do
      getfunc( f[k](x));
  od;
  for k from 0 to N do
      getfunc( Theta[k](x));
  od;
  for k from 0 to N do
      getfunc( Phi[k](x));
  od;
 

f[0](x) = .1000000000*x^2

 

f[1](x) = -0.1666666667e-3*x^5+0.1083333333e-2*x^4-0.2166666667e-1*x^3+.1604166667*x^2

 

f[2](x) = 0.5456349206e-6*x^8-0.4118253968e-5*x^7+0.7614500001e-4*x^6-0.6524055556e-3*x^5+0.1535381945e-2*x^4-0.4723015880e-2*x^2

 

f[3](x) = -0.1878908129e-8*x^11+0.1736124339e-7*x^10-0.3552027183e-6*x^9+0.3793981986e-5*x^8-0.1946734724e-4*x^7+0.1214666688e-3*x^6-0.4131483961e-3*x^5+0.3230273350e-4*x^4-0.1330516996e-1*x^2

 

Theta[0](x) = -.2000000000*x+1.

 

Theta[1](x) = 0.8333333333e-3*x^4+0.3333333333e-3*x^3-0.5000000000e-2*x^2-0.8750000000e-1*x

 

Theta[2](x) = -0.4365079365e-5*x^7+0.1666666666e-5*x^6-0.8350000000e-4*x^5+0.1705555556e-2*x^4+0.1458333333e-3*x^3-.1016567461*x

 

Theta[3](x) = 0.2066798942e-7*x^10-0.3597773368e-7*x^9+0.1128731151e-5*x^8-0.1580760582e-4*x^7-0.8846064811e-6*x^6-0.7364583333e-5*x^5+0.9690637402e-3*x^4+0.1694279102e-3*x^3+0.1449694976e-1*x

 

Phi[0](x) = -.2000000000*x+1.

 

Phi[1](x) = 0.6500000000e-3*x^4+0.2600000000e-3*x^3-0.3900000000e-2*x^2-0.6825000000e-1*x

 

Phi[2](x) = -0.2723809524e-5*x^7+0.1633666666e-5*x^6-0.6939140002e-4*x^5+0.1267055834e-2*x^4+0.8872500000e-4*x^3-0.7977616371e-1*x

 

Phi[3](x) = 0.1061288360e-7*x^10-0.2402855688e-7*x^9+0.7248453644e-6*x^8-0.9648079535e-5*x^7+0.4540935411e-6*x^6-0.4470852750e-5*x^5+0.5843971476e-3*x^4+0.1037090128e-3*x^3+0.8513437276e-2*x

(1)

  interface(rtablesize=25):
  Matrix( [ [ eta, f(eta), Theta(eta), Phi(eta) ],
              seq
              ( [ j,
                  eval(add( rhs(getfunc(f[k](x))), k=0..N), x=j),
                  eval(add( rhs(getfunc(Theta[k](x))), k=0..N), x=j),
                  eval(add( rhs(getfunc(Phi[k](x))), k=0..N), x=j)
                ],
                j=0..5, 0.25
              )
          ]
      );
  interface(rtablesize=25):

Matrix(22, 4, {(1, 1) = eta, (1, 2) = f(eta), (1, 3) = Theta(eta), (1, 4) = Phi(eta), (2, 1) = 0, (2, 2) = 0., (2, 3) = 1., (2, 4) = 1., (3, 1) = .25, (3, 2) = 0.1481993747e-1, (3, 3) = .9060462984, (3, 4) = .9148948366, (4, 1) = .50, (4, 2) = 0.5801888833e-1, (4, 3) = .8117174425, (4, 4) = .8294791624, (5, 1) = .75, (5, 2) = .1277817135, (5, 3) = .7175522121, (5, 4) = .7441353149, (6, 1) = 1.00, (6, 2) = .2223186376, (6, 3) = .6243876091, (6, 4) = .6594577256, (7, 1) = 1.25, (7, 2) = .3397907893, (7, 3) = .5333300263, (7, 4) = .5762338660, (8, 1) = 1.50, (8, 2) = .4782590267, (8, 3) = .4457112954, (8, 4) = .4954162503, (9, 1) = 1.75, (9, 2) = .6356553278, (9, 3) = .3630261073, (9, 4) = .4180833407, (10, 1) = 2.00, (10, 2) = .8097770164, (10, 3) = .2868483862, (10, 4) = .3453878152, (11, 1) = 2.25, (11, 2) = .9983046745, (11, 3) = .2187255595, (11, 4) = .2784914059, (12, 1) = 2.50, (12, 2) = 1.198844724, (12, 3) = .1600513756, (12, 4) = .2184864442, (13, 1) = 2.75, (13, 2) = 1.408997349, (13, 3) = .1119200428, (13, 4) = .1663053649, (14, 1) = 3.00, (14, 2) = 1.626449467, (14, 3) = 0.7496707269e-1, (14, 4) = .1226207957, (15, 1) = 3.25, (15, 2) = 1.849091027, (15, 3) = 0.4920537171e-1, (15, 4) = 0.8774050001e-1, (16, 1) = 3.50, (16, 2) = 2.075150559, (16, 3) = 0.3386893409e-1, (16, 4) = 0.6150341035e-1, (17, 1) = 3.75, (17, 2) = 2.303342838, (17, 3) = 0.2728096916e-1, (17, 4) = 0.4318528487e-1, (18, 1) = 4.00, (18, 2) = 2.533017374, (18, 3) = 0.2676858775e-1, (18, 4) = 0.3142526158e-1, (19, 1) = 4.25, (19, 2) = 2.764291275, (19, 3) = 0.2865226286e-1, (19, 4) = 0.2418766250e-1, (20, 1) = 4.50, (20, 2) = 2.998143347, (20, 3) = 0.283453391e-1, (20, 4) = 0.187770320e-1, (21, 1) = 4.75, (21, 2) = 3.236438297, (21, 3) = 0.206068477e-1, (21, 4) = 0.119284818e-1, (22, 1) = 5.00, (22, 2) = 3.481840121, (22, 3) = 0.5000000000e-9, (22, 4) = 0.8000000000e-9})

(2)

 

Download ODEnotPDE3.mw

@Muhammad Usman 

for example

If you want the actual data at a finer resolution, then just change the step size(s) in the final execution group.

and

just change the endpoints of the seq commands for example
Matrix([seq([seq(interfunc(i,j),i=0..1,0.001)],j=1..0, -0.001)]);

@KIRAN SAJJAN 

to the format you require (which is barely legible!). A quich check suggest that successive the equations in the attached  for 'Theta' and 'Phi' agree with you 'picture' , but those in 'f' do not. You should check this carefully.

Please remeber that your original code was so full of logical and syntax errors that I had to guess your intention. It is quite likely that I made a bad guess :-(


 

  restart:
  N := 4: M := .1: Kp := .1: Gr := 0.1e-1: Gc := 0.1e-1: Pr := 1: S := 0.1e-1: Sc := .78: Kc := 0.1e-1: La := 1:
  f__N:=  sum((p^(i))*f[i](x), i = 0 .. N) :
  Theta__N:=  sum((p^(i))*Theta[i](x), i = 0 .. N) :
  Phi__N:= sum((p^(i))*Phi [i] (x), i = 0 .. N):
  HPMEq1 := (1-p)*(diff(f__N, x, x, x))+p*(diff(f__N, x, x, x)+(1/2)*(diff(f__N, x, x))*f__N-(M^2+Kp)*(diff(f__N, x)-La)+Gr*Theta__N+Gc*Phi__N):
  HPMEq2 := (1-p)*(diff(Theta__N, x, x))/Pr+p*((diff(Theta__N, x, x))/Pr+(1/2)*(diff(Theta__N, x))*f__N+S*Theta__N):
  HPMEq3 := (1-p)*(diff(Phi__N, x, x))/Sc+p*((diff(Phi__N, x, x))/Sc+(1/2)*(diff(Phi__N, x))*f__N+Kc*Phi__N):

  for i from 0 to N do
      equ[1][i] := coeff(HPMEq1, p, i) = 0:
  end do:
  for i from 0 to N do
      equ[2][i] := coeff(HPMEq2, p, i) = 0:
  end do:
  for i from 0 to N do
      equ[3][i] := coeff(HPMEq3, p, i) = 0:
  end do:
  cond[1][0] := f[0](0) = 0, (D(f[0]))(0) = 0, Theta[0](0) = 1, Phi[0](0) = 1, Theta[0](5) = 0, Phi[0](5) = 0, (D(f[0]))(5) = 1:
  for j to N do
       cond[1][j] := f[j](0) = 0, (D(f[j]))(0) = 0, Theta[j](0) = 0, Phi[j](0) = 0, Theta[j](5) = 0, Phi[j](5) = 0, (D(f[j]))(5) = 0:
  end do:

  ans:=dsolve({equ[1][0], equ[2][0], equ[3][0], cond[1][0]}):
  for k from 1 by 1 to 4 do
      ans:=`union`( ans, dsolve( { eval({equ[1][k], equ[2][k], equ[3][k]}, ans)[], cond[1][k]})):
  od:
  for j from 0 by 1 to 4 do
      f[j](x)=eval( f[j](x), evalf~(ans));
  od;
  for j from 0 by 1 to 4 do
      Theta[j](x)=eval( Theta[j](x), evalf~(ans));
  od;
  for j from 0 by 1 to 4 do
      Phi[j](x)=eval( Phi[j](x), evalf~(ans));
  od;

f[0](x) = .1000000000*x^2

 

f[1](x) = -0.1666666667e-3*x^5+0.1083333333e-2*x^4-0.2166666667e-1*x^3+.1604166667*x^2

 

f[2](x) = 0.5456349206e-6*x^8-0.4118253968e-5*x^7+0.7614500001e-4*x^6-0.6524055556e-3*x^5+0.1535381945e-2*x^4-0.4723015880e-2*x^2

 

f[3](x) = -0.1878908129e-8*x^11+0.1736124339e-7*x^10-0.3552027183e-6*x^9+0.3793981986e-5*x^8-0.1946734724e-4*x^7+0.1214666688e-3*x^6-0.4131483961e-3*x^5+0.3230273350e-4*x^4-0.1330516996e-1*x^2

 

f[4](x) = 0.6399987799e-11*x^14-0.7215804519e-10*x^13+0.1619819726e-8*x^12-0.2016116095e-7*x^11+0.1472981866e-6*x^10-0.1207325236e-5*x^9+0.5883077911e-5*x^8-0.9303180532e-5*x^7-0.3315385078e-5*x^6+0.6960558200e-4*x^5-0.1315517192e-3*x^4-0.4510232982e-2*x^2

 

Theta[0](x) = -.2000000000*x+1.

 

Theta[1](x) = 0.8333333333e-3*x^4+0.3333333333e-3*x^3-0.5000000000e-2*x^2-0.8750000000e-1*x

 

Theta[2](x) = -0.4365079365e-5*x^7+0.1666666666e-5*x^6-0.8350000000e-4*x^5+0.1705555556e-2*x^4+0.1458333333e-3*x^3-.1016567461*x

 

Theta[3](x) = 0.2066798942e-7*x^10-0.3597773368e-7*x^9+0.1128731151e-5*x^8-0.1580760582e-4*x^7-0.8846064811e-6*x^6-0.7364583333e-5*x^5+0.9690637402e-3*x^4+0.1694279102e-3*x^3+0.1449694976e-1*x

 

Theta[4](x) = -0.8959982918e-10*x^13+0.3158683562e-9*x^12-0.8909098531e-8*x^11+0.1145236794e-6*x^10-0.1741583958e-6*x^9+0.2150994486e-5*x^8-0.1902330877e-4*x^7+0.1921094746e-5*x^6-0.5632953871e-4*x^5+0.4909768121e-3*x^4-0.2416158293e-4*x^3+0.3543341013e-1*x

 

Phi[0](x) = -.2000000000*x+1.

 

Phi[1](x) = 0.6500000000e-3*x^4+0.2600000000e-3*x^3-0.3900000000e-2*x^2-0.6825000000e-1*x

 

Phi[2](x) = -0.2723809524e-5*x^7+0.1633666666e-5*x^6-0.6939140002e-4*x^5+0.1267055834e-2*x^4+0.8872500000e-4*x^3-0.7977616371e-1*x

 

Phi[3](x) = 0.1061288360e-7*x^10-0.2402855688e-7*x^9+0.7248453644e-6*x^8-0.9648079535e-5*x^7+0.4540935411e-6*x^6-0.4470852750e-5*x^5+0.5843971476e-3*x^4+0.1037090128e-3*x^3+0.8513437276e-2*x

 

Phi[4](x) = -0.3896273449e-10*x^13+0.1697586667e-9*x^12-0.4688867837e-8*x^11+0.5906981367e-7*x^10-0.1174292121e-6*x^9+0.1327469799e-5*x^8-0.1074474492e-4*x^7+0.1506166234e-5*x^6-0.3446424640e-4*x^5+0.2912878380e-3*x^4-0.1106746846e-4*x^3+0.2239032281e-1*x

(1)

 

Download ODEnotPDE2.mw

just change the endpoints of the seq commands for example

Matrix([seq([seq(interfunc(i,j),i=0..1,0.001)],j=1..0, -0.001)]);

will generate a 1000x1000 matrix of values from 0..1 in both directions, in steps of 0.001

as a "dat file"

If you want the actual data at a finer resolution, then just change the step size(s) in the final execution group. You can then transfer the reults matrix anywhere you want using ExportMatrix()

@Mike Mc Dermott 

Post the worksheet which produces the error (Use big green uparrow in the Mapleprimes toolbar)

The Matlab code

>> M=rand(1800,1);
>> save('C:\Users\TomLeslie\Desktop\test.mat', 'M')

creates an 1800x1 matrix on my desktop.

Both of the maple commands shown below read it

ImportMatrix("C:/Users/TomLeslie/Desktop/test.mat", source=Matlab, output=matrices);
ImportMatrix("C:/Users/TomLeslie/Desktop/test.mat", source=MATLAB, output=matrices);

I suppose it *might* be a version issue.  Which version Matlab and Maple are you running?

(I'm using Maple 2022.2 and Matlab R2022b)

 

@Muhammad Usman 

fdiff() seems to be doing something pretty crazy - and I don't understand why, so, in the attached, I have changed the method of computing the numerical derivative - the answer looks a lot more plausible

At the moment I can't upload a worksheet here, because someone has broken the big green up-arrow! However you need to replace the code

Tv := eval(T(y, t), (pds[i]):-value(t = 1, output = listprocedure));
f := yv -> (1 + Nr*(Tv(yv) + 1))*fdiff(Tv(y), y = yv, workprec = 1.5);
plt1[i] := plot('f(y)', y = 0 .. 1, color = AA[i], size = [1000, 600], axes = boxed, axesfont = ["Arial", 14, Bold], thickness = 3);

with

h := 0.001;
Tv := eval(T(y, t), (pds[i]):-value(t = 1, output = listprocedure));
f := yv -> (1 + Nr*(Tv(yv) + 1))*(Tv(yv + h) - Tv(yv))/h;
plt1[i] := plot('f(y)', y = 0 .. 1, color = AA[i], size = [1000, 600], axes = boxed, axesfont = ["Arial", 14, Bold], thickness = 3);
4 5 6 7 8 9 10 Last Page 6 of 207