mmcdara

7886 Reputation

22 Badges

9 years, 49 days

MaplePrimes Activity


These are answers submitted by mmcdara

In my Maple 2015 version plot/device doesn't hangle JPEG format.
Check what formats are supported in your version and change accordingly the first argument of plotsetup in the attached file.
(Note: the optional arguments of plotsetip I used are just a copy-paste of the example provided in the corresponding help page, so feel free to adapt them to your own needs)

q_new_mmcdara.mw

The saved file is uploaded below
 



Note: It might be useful to download the saved image file in a maple worksheet.
This can be done using ImageTools:-Read and ImageTools:-Embed ... provided the format you used in plotsetup is supported by ImageTools:-Read.
aple 2015 only supports three image file formats: JPEG, TIFF, and BMP; so, here again check what can be done with your own Maple version.
 

Here is one way to achieve this

One_way.mw

@Andiguys 

proposal.mw 
(meanwhile I replaced the difference plot by a ratio plot in order to avoid using a log scale on axis[2] as this introduces some problems).


 

Let F some real valued function of x and y (both assumed real valued).
Then

implicitplot(F(x, y), x=a..b, y=c..d) 

is aimed to draw the graph of the equation F(x, y) = 0 over the domain [a, b] x [c, d]

If F(x, y) is a complex valued function what does F(x, y) = 0 mean for you?
Considering F(x, y) = 0 means  abs(F(x, y)) = 0,  then the graph is either a continuous curve a finite set of isolated points, possibly empty.

The attached file seems to show that there are only 6 isolated points where abs(FF) = 0 (WATCHOUT: maybe there are more points or maybe less, pushing the computtions with a larger number of digits or finer grids might give different results... but I doubt the graph of abs(FF) =0 is continuous)

I suggest you tostart reading this Notional_example.mw
Next here is Your_example.mw

@dharr Sorry to intrude, it took me so long to write my reply that you posted yours in the meantime.
Basically we both took the same path.

simplify( (Re(term2) assuming t::real, n::real) );

              / (-n)  \             / (-n)  \       
           cos\2     t/ cos(t) + sin\2     t/ sin(t)

 

restart:
kernelopts(version):
     Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895

`print/truefalse` := proc(t)
  if t > 1 then
   `#mi("true",mathcolor="red")`
  else
   `#mi("false",mathcolor="blue")`
  end if:
end proc:

truefalse(0);
                          false
truefalse(3);
                          true

TF.mw


... even if it is small for the values of theta and epsilon you chosed.

More of this the pictures one gets with your code stongly differ from those in the paper you provide.
See here an illustration wich emphasizesthe sine effect

chaotic-2_mmcdara.mw

To the moderators: please avoid converting this comment into an answer for I don't to interfer with @acer nor @Rouben Rostamian who already exchanged with the OP
[reply from moderator: respectfully, no. Your code that provides an answer should have the same status (with ability of readers to order) as anyone else's. Your answer (for answering the topic, it does address) doesn't get to be placed above all others'.]


if you want to compute the limit of r2 wrt a2:

restart

with(Student[Calculus1]):

lambda1 := I*mu1:

{a1 = -2*x/mu1+mu1*t, a2 = -2*x/mu2+mu2*t}

(1)

numer_r := lambda2*cosh(a1)-lambda1*cosh(a2):

denom_r := (lambda1^2+lambda2^2)*cosh(a1)*cosh(a2)-2*lambda1*lambda2*(1+sinh(a1)*sinh(a2)):

r2 := I*(-lambda1^2+lambda2^2)*numer_r/denom_r:

numer_dq := (sinh(a1)-sinh(a2))^2:

dq2 := 1-2*(lambda1^2-lambda2^2)^2*numer_dq/denom_dq:

r2

I*(mu1^2-mu2^2)*(I*mu2*cosh(a1)-I*mu1*cosh(a2))/((-mu1^2-mu2^2)*cosh(a1)*cosh(a2)+2*mu1*mu2*(1+sinh(a1)*sinh(a2)))

(2)

limit_r2 := limit(r2, a2 = -infinity); map(factor, limit_r2); convert(%, cosh); map(simplify, %)

(-mu1^3+mu1*mu2^2)/(cosh(a1)*mu1^2+cosh(a1)*mu2^2+2*mu1*mu2*sinh(a1))

 

-mu1*(mu1-mu2)*(mu1+mu2)/(cosh(a1)*mu1^2+cosh(a1)*mu2^2+2*mu1*mu2*sinh(a1))

 

-mu1*(mu1-mu2)*(mu1+mu2)/(cosh(a1)*mu1^2+cosh(a1)*mu2^2+(2*I)*mu1*mu2*cosh(((1/2)*I)*Pi-a1))

 

-mu1*(mu1-mu2)*(mu1+mu2)/(cosh(a1)*mu1^2+cosh(a1)*mu2^2+2*mu1*mu2*sinh(a1))

(3)

 

limit_r2_pos := limit(r2, a2 = infinity):

-mu1*(mu1-mu2)*(mu1+mu2)/(cosh(a1)*mu1^2+cosh(a1)*mu2^2-2*mu1*mu2*sinh(a1))

(4)

r2pv := eval(r2, phase_variables)

I*(mu1^2-mu2^2)*(I*mu2*cosh(-2*x/mu1+mu1*t)-I*mu1*cosh(-2*x/mu2+mu2*t))/((-mu1^2-mu2^2)*cosh(-2*x/mu1+mu1*t)*cosh(-2*x/mu2+mu2*t)+2*mu1*mu2*(1+sinh(-2*x/mu1+mu1*t)*sinh(-2*x/mu2+mu2*t)))

(5)

has(r2pv, a2)

false

(6)

limit(r2pv, a2)

Error, invalid input: limit expects its 2nd argument, p, to be of type Or(name = algebraic, set(name = algebraic)), but received a2

 

 

NULL


 

Download asymptotic_mmcdara.mw

With Firefox your question was asked 1 hour ago and @acer's answer did not appeared 10 minutes ago.
So I write my answer  and then saw with Safari that you asked it 2 hours ago and  @acer's answer was posted 45 minutes ago.

Because both @acer and I used the same approach (define a random variable and ask for its Median -numeric-), I decided not to write an answer but a simple comment.

This comment seems justified by the fact that you fill also find in my attached file Median_mmcdara.mw the exact expression of the median... for what it's worth...


If I am not mistaken ra[1] does not contain the right hand sides of subs1, subs6, ...subs7

subs1 := a1 = ...;
subs2 := a2 = ...; 
subs3 := a3 = ...; 
subs4 := a4 = ...; 
subs5 := (identical to subs1);
subs6 := a6 = ...;
subs7 := a7 = ...; 
subs8 := a8 = ...;

So a rewritten expression of ra[1] can only contain a2, a3 and a4... and it is not even certain because the final result will depend on the substitution order you use.

Look the attached file r_mmcdara.mw

If your goal is to rewrite ra[1] under a more concise form (the most concise one maybe?) you could find some ideas here.

@Rouben Rostamian  

Here is a workaround to make dsolve provide the correct solution.

The main idea is to consider a(x) as a shock and to use the fact that a weak solution of viscosity solution type, is the limit of a a regularized solution when the regularization parameter tends to 0.

 

Problem with dsolve()

restart;

kernelopts(version);

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)

A boundary value problem for an ODE

 

Let's solve the following boundary value problem:

de := Diff(a(x)*Diff(u(x),x),x) = -1;

Diff(a(x)*(Diff(u(x), x)), x) = -1

(1.1)

bc := u(-1)=0, u(1)=0;

u(-1) = 0, u(1) = 0

(1.2)

Maple's dsolve() fails to find a solution:

dsolve({de,bc});

 

Solution obtained by hand

 

The solution may be obtained by hand, as follows.

 

Integrate the DE once

a(x)*(diff(u(x), x)) = c-x.

where c is the integration constant.  Therefore

diff(u(x), x) = (c-x)/a(x) and (c-x)/a(x) = c/a(x)-x/a(x).

To determine the value of the constant c, integrate the above over [-1, 1]

and apply the boundary conditions:

c*(int(1/a(x), x = -1 .. 1))+int(x/a(x), x = -1 .. 1) = u(1)-u(-1) and u(1)-u(-1) = 0

whence
c = (int(x/a(x), x = -1 .. 1))/(int(1/a(x), x = -1 .. 1)).

Having thus determined c, we integrate the expression for diff(u(x), x) obtained above, and arrive at the solution
u(x) = int((c-xi)/a(xi), xi = -1 .. x).

Remark: The solution obtained here is valid for any a(x) as long as

the integrals encountered above make sense.  Note that there is
no requirement on the differentiability or even continuity of a(x).

Technically, a(x) can be any function such that 1/a(x) is integrable.

 

 

Wrong solution returned by dsolve()

 

Let us consider a special choice of the coefficient a(x):

a := x -> 1 + 2*Heaviside(x);

proc (x) options operator, arrow; 1+2*Heaviside(x) end proc

(3.1)

According the the calculations above, we have:

c := int(x/a(x),x=-1..1) / int(1/a(x),x=-1..1) ;

-1/4

(3.2)

and therefore the correct solution is

int((c-xi)/a(xi), xi=-1..x):
sol := u(x) = collect(%, Heaviside);

u(x) = ((1/6)*x+(1/3)*x^2)*Heaviside(x)-(1/4)*x-(1/2)*x^2+1/4

(3.3)

Here is what the solution looks like:

plot(rhs(sol), x=-1..1, color=blue, thickness=3);

 

Let's attempt to solve the same boundary value problem with Maple's dsolve().

dsolve({de,bc}):
bad_sol := collect(%, Heaviside);

plot(
  [rhs(sol), rhs(bad_sol)]
  , x=-1..1
  , color=[blue, red]
  , legend=["sol", "bad_sol"]
)

u(x) = ((1/3)*x^2-(1/3)*exp(-2)*x/(exp(-2)+1)+(1/3)*x/(exp(-2)+1))*Heaviside(x)-(1/2)*x^2-(1/3)*x/(exp(-2)+1)+(1/6)*(3*exp(-2)+1)/(exp(-2)+1)

 

 

That's very different from the correct solution obtained above.   To see the problem with it, let's recall that according to the DE, the expression a(x)*(diff(u(x), x))NULLshould evaluate to  c-x for some constant c,  but what we get through bad_sol is nothing like c-x;  in fact, it's not even continuous:

a(x)*diff(rhs(bad_sol), x):
collect(%, Heaviside, simplify);
plot(%, x = -0.5 .. 0.5);

(2/3)*(2*exp(-2)*x-exp(-2)+2*x+1)*Heaviside(x)^2/(exp(-2)+1)+(-(4/3)*x-1/3)*Heaviside(x)-(1/3)*(3*exp(-2)*x+3*x+1)/(exp(-2)+1)

 

 


As solution that you  provided is a weak solution of the boundary value problem, (lets sayBVP(0)) one might think to it as the limit solution of
some regularized ("viscous") boundary value problem BVP(λ), λ ≥ 0, when proc (lambda) options operator, arrow; 0 end proc (from the right).
With this in mind on may think to a(x) as some "shock" ad a way to damp it by adding a "viscosity" can be modeled by replacing a(x) by alpha(x):

proc (lambda) options operator, arrow; 0 end proc

 

1+2*Heaviside(x)

 

1+2*Heaviside(x)

 

alpha(x)

(3.4)

alpha := x -> 1 + (1+tanh(x/lambda));

proc (x) options operator, arrow; 2+tanh(x/lambda) end proc

(3.5)

asol := unapply( rhs(dsolve({Diff(alpha(x)*Diff(u(x),x),x) = -1, bc})), (x, lambda)):

lambdas := 10^~[$-4..0]:
colors := cyan, green, gold, red, purple:

plot(
  [rhs(sol), seq(asol(x, L), L in lambdas)]
  , x=-1..1
  , color=[blue, colors]
  , style=[line, point$5]
  , numpoints=30
  , legend=["sol", seq(typeset(lambda=L), L in lambdas)]
  , size=[800, 600]
)

 

plot(
  [seq(sqrt((asol(x, L)-rhs(sol))^2), L in lambdas)]
  , x=-1..1
  , color=[colors]
  , legend=[seq(typeset(lambda=L), L in lambdas)]
  , axis[2]=[mode=log]
  , size=[500, 500]
  , title=typeset('asol'(x, lambda) - 'sol')
)

 


The limit case proc (lambda) options operator, arrow; 0 end proc (from the right)
Then alpha(x)"->a(x)"

Error, invalid arrow procedure

"->a(x)"

 

eval(asol(x, lambda)) assuming x <= 0, lambda >= 0:
limit(%, x=0, left):
limit(%, lambda=0, right);

1/4

(3.6)

eval(asol(x, lambda)) assuming x >= 0, lambda >= 0:
limit(%, x=0, right):
limit(%, lambda=0, right);

1/4

(3.7)

NL := limit(asol(x, lambda), lambda=0, right) assuming x < 0;
PL := limit(asol(x, lambda), lambda=0, right) assuming x > 0;

limit(-(1/2)*x^2-(1/4)*x+(1/24)*lambda^2*(polylog(2, -3*exp(2/lambda))*lambda-polylog(2, -3*exp(-2/lambda))*lambda+2*ln(1+3*exp(2/lambda))+2*ln(1+3*exp(-2/lambda)))*ln(1+3*exp(2*x/lambda))+1/4, lambda = 0, right)

 

limit(-(1/6)*x^2-(1/4)*x+(1/24)*lambda^2*(polylog(2, -3*exp(2/lambda))*lambda-polylog(2, -3*exp(-2/lambda))*lambda+2*ln(1+3*exp(2/lambda))+2*ln(1+3*exp(-2/lambda)))*ln(1+3*exp(2*x/lambda))+1/4, lambda = 0, right)

(3.8)


Case x < 0

hasx, nothasx := selectremove(has, [op(op([1, 3], NL))], x);

limit(mul(nothasx), lambda=0, right);
limit(hasx[], lambda=0, right) assuming x < 0;

# Then

LeftLimit := add([op(1..2, op(1, NL)), op(-1, op(1, NL))])

[ln(1+3*exp(2*x/lambda))], [1/24, lambda^2, polylog(2, -3*exp(2/lambda))*lambda-polylog(2, -3*exp(-2/lambda))*lambda+2*ln(1+3*exp(2/lambda))+2*ln(1+3*exp(-2/lambda))]

 

0

 

0

 

1/4-(1/2)*x^2-(1/4)*x

(3.9)


Case x > 0

hasx := select(has, [op(op([1, 3], PL))], x)[];

q := asympt(eval(hasx, lambda=1/xi), xi, 3) assuming x > 0, x < 1;
q := add(op(1..2, q));

# Then

op(1, PL);

# behaves like

eval(op(1, PL), hasx = eval(q, xi=1/lambda));
RightLimit := limit(%, lambda=0, right);

ln(1+3*exp(2*x/lambda))

 

2*x*xi+ln(3)+(1/3)/(exp(x*xi))^2+O(1/(exp(x*xi))^4)

 

2*x*xi+ln(3)

 

-(1/6)*x^2-(1/4)*x+(1/24)*lambda^2*(polylog(2, -3*exp(2/lambda))*lambda-polylog(2, -3*exp(-2/lambda))*lambda+2*ln(1+3*exp(2/lambda))+2*ln(1+3*exp(-2/lambda)))*ln(1+3*exp(2*x/lambda))+1/4

 

-(1/6)*x^2-(1/4)*x+(1/24)*lambda^2*(polylog(2, -3*exp(2/lambda))*lambda-polylog(2, -3*exp(-2/lambda))*lambda+2*ln(1+3*exp(2/lambda))+2*ln(1+3*exp(-2/lambda)))*(2*x/lambda+ln(3))+1/4

 

-(1/6)*x^2-(1/12)*x+1/4

(3.10)

Weak_solution := piecewise(x=0, 1/4, x < 0, LeftLimit, x > 0, RightLimit)

Weak_solution := piecewise(x = 0, 1/4, x < 0, 1/4-(1/2)*x^2-(1/4)*x, 0 < x, -(1/6)*x^2-(1/12)*x+1/4)

(3.11)

plot(
  [rhs(sol), Weak_solution]
  , x=-1..1
  , color=[blue, red]
  , style=[line, point]
  , numpoints=30
  , symbol=circle
  , symbolsize=15
  , legend=["by-hand solution", "limit of visvous solution"]
)

 

 

 

Download dsolve-bug_mmcdara.mw

 

Indeed none of A[0], ..., A[4] contain any of abs(U[i](x, t))2p, i=0..6, p=1..5.
Look here Substitutions.mw

Please clarify your problem.

Coding errors, bad construction the CCD (Central Composite Design: what you builr is just a 24 Factorial Design to wich you had four times the central point -replicates are useful only when noisy observations"- ... but you forgot the  axial points) and unidentifiable model (because of the absence of those axial points).

Quadratic effects CANNOT be independently identified with your fesign because of aliasing (confusion between quadratic effects due to the fact the design matrix of your design of experiment is not an orthogonal array). 
This is pretty obvious because your design is basically a (slightly) augmented a 24 Factorial Design and that which doesn't enable identifying quadratic effects.
Use a true CCD, a 3 level fractional design with adpated resolution, a  D-optimal design, or more simply any Monte-Carlo or LHS design.

All the corrections are in red in the atatched file. I don't have time right now for more detailed explanations, hope those in the worksheet will be enough for you.

restart

with(Statistics): with(LinearAlgebra): with(plots):

local A, B, C, D;

Digits := 10:

# Step 1: Define the variables

vars := [A, B, C, D];

[A, B, C, D]

(1)

# Step 2: Generate Central Composite Design (CCD) coded matrix

coded := Matrix([

    [ 1,  1,  1,  1],

    [ 1,  1,  1, -1],

    [ 1,  1, -1,  1],

    [ 1,  1, -1, -1],

    [ 1, -1,  1,  1],

    [ 1, -1,  1, -1],

    [ 1, -1, -1,  1],

    [ 1, -1, -1, -1],

    [-1,  1,  1,  1],

    [-1,  1,  1, -1],

    [-1,  1, -1,  1],

    [-1,  1, -1, -1],

    [-1, -1,  1,  1],

    [-1, -1,  1, -1],

    [-1, -1, -1,  1],

    [-1, -1, -1, -1],

    [ 0,  0,  0,  0],

    [ 0,  0,  0,  0],

    [ 0,  0,  0,  0],

    [ 0,  0,  0,  0]

]):

# Step 3: Define uncoded variable ranges

rangeA := [0.1, 0.5]:

rangeB := [0.1, 0.5]:

rangeC := [0.1, 0.5]:

rangeD := [0.1, 0.5]:

decode := (val, r) -> r[1] + (val + 1)*(r[2] - r[1])/2:

# Step 4: Create actual values matrix

actual := Matrix(20, 4):

for i from 1 to 20 do

    for j from 1 to 4 do

        r := eval(cat("range", vars[j])):

        actual[i, j] := evalf(decode(coded[i, j], r));

    end do;

end do:


# Verify "actual":

actual[1..2];

Matrix([["a", "a", "a", "a"], ["a", "a", "a", "r"]])

(2)

# I propose you this construction (it gives the correct result and avoid loops)

Low  := DiagonalMatrix(map2(op, 1, [rangeA, rangeB, rangeC, rangeD])):
High := DiagonalMatrix(map2(op, 2, [rangeA, rangeB, rangeC, rangeD])):

actual := coded . (High - Low) /~ 2 + Matrix(20, 4, 1) . (High + Low) /~ 2;

actual := Vector(4, {(1) = ` 20 x 4 `*Matrix, (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

(3)

# Step 5: Define model coefficients (for simulation purposes)

beta := [1.5, 0.8, 0.6, 0.5, 0.3,  # Linear terms

         0.1, 0.2, 0.15, 0.18,  # Square terms

         0.05, 0.04, 0.03, 0.02, 0.01, 0.025]; # Interaction terms
vars

[1.5, .8, .6, .5, .3, .1, .2, .15, .18, 0.5e-1, 0.4e-1, 0.3e-1, 0.2e-1, 0.1e-1, 0.25e-1]

 

[A, B, C, D]

(4)

# Step 6: Simulate Response (Nusselt number)
Nu := Vector(20):

for i from 1 to 20 do
    # The next line, if executed changes changes "var".
    # indeed A is set to O.3 and thus vars = [A, B, C, D] becomes [0.3, B, C, D] and so on

    # A := actual[i,1]; B := actual[i,2]; C := actual[i,3]; D := actual[i,4];

    Nu[i] := evalf(
               eval(

                 beta[1] + beta[2]*A + beta[3]*B + beta[4]*C + beta[5]*D +

                 beta[6]*A^2 + beta[7]*B^2 + beta[8]*C^2 + beta[9]*D^2 +

                 beta[10]*A*B + beta[11]*A*C + beta[12]*A*D +

                 beta[13]*B*C + beta[14]*B*D + beta[15]*C*D
                 ,
                 vars =~ convert(actual[i], list)
               )

             ):

end do:

# Verify that "Nu" is a numeric vector

Nu[1..5];

# Verify that "vars" has not been changed

vars

Vector(5, {(1) = 2.80125000000000, (2) = 2.62505000000000, (3) = 2.54825000000000, (4) = 2.37605000000000, (5) = 2.49725000000000})

 

[A, B, C, D]

(5)

# My Step 7a: Build the coded design matrix

basis           := [ 1, A, B, C, D, A^2, B^2, C^2, D^2, A*B, A*C, A*D, B*C, B*D, C*D]:
StructuralModel := add(cat(`alpha__`, b) * b, b in basis);

N := numelems(coded[..,1]);

CodedDesign := `<|>`( Vector(N, 1), coded ):

for i from 6 to numelems(basis) do
  opb := op(basis[i]):
  if opb[2]::numeric then
    col := ListTools:-Search(opb[1], basis) - 1;
    CodedDesign := `<|>`( CodedDesign, coded[.., col]^~opb[2] );
  else
    col := ListTools:-Search(opb[1], basis) - 1, ListTools:-Search(opb[2], basis) - 1;
    CodedDesign := `<|>`( CodedDesign, coded[.., col[1]]*~coded[.., col[2]] ):
  end if;
end do:

CodedDesign;
 

StructuralModel := A^2*`#msub(mi("&alpha;",fontstyle = "normal"),mi("A^2"))`+A*B*`#msub(mi("&alpha;",fontstyle = "normal"),mi("A*B"))`+A*C*`#msub(mi("&alpha;",fontstyle = "normal"),mi("A*C"))`+A*D*`#msub(mi("&alpha;",fontstyle = "normal"),mi("A*D"))`+B^2*`#msub(mi("&alpha;",fontstyle = "normal"),mi("B^2"))`+B*C*`#msub(mi("&alpha;",fontstyle = "normal"),mi("B*C"))`+B*D*`#msub(mi("&alpha;",fontstyle = "normal"),mi("B*D"))`+C^2*`#msub(mi("&alpha;",fontstyle = "normal"),mi("C^2"))`+C*D*`#msub(mi("&alpha;",fontstyle = "normal"),mi("C*D"))`+D^2*`#msub(mi("&alpha;",fontstyle = "normal"),mi("D^2"))`+A*`#msub(mi("&alpha;",fontstyle = "normal"),mi("A"))`+B*`#msub(mi("&alpha;",fontstyle = "normal"),mi("B"))`+C*`#msub(mi("&alpha;",fontstyle = "normal"),mi("C"))`+D*`#msub(mi("&alpha;",fontstyle = "normal"),mi("D",fontstyle = "normal"))`+`#msub(mi("&alpha;",fontstyle = "normal"),mi("1"))`

 

N := 20

 

Vector(4, {(1) = ` 20 x 15 `*Matrix, (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

(6)

# My Step 7b: Compute the rank of "CodedDesign"

Rank(CodedDesign);

# You observe that "CodedDesign" is not of full rank (15) which means that it's not an orthogonal
# design matrix and thus some effects are aliased with some others.
#

12

(7)

# My Step 7c: Aliased effets:

for i from 1 to numelems(basis)-1 do
  for j from i+1 to numelems(basis) do
    if [min, max](CodedDesign[.., i] - CodedDesign[.., j]) = [0, 0] then
      print(cat("Aliasing between effects ", basis[i], " and ", basis[j]))
    end if:
  end do:
end do:

# So all the quadratic terms are mutualy aliased and cannot be identified independently
# Moer precisely it is impossible to say is some observed quadratic effect is A^2, or
# B^2, or C^2, or D^2

"Aliasing between effects A^2 and B^2"

 

"Aliasing between effects A^2 and C^2"

 

"Aliasing between effects A^2 and D^2"

 

"Aliasing between effects B^2 and C^2"

 

"Aliasing between effects B^2 and D^2"

 

"Aliasing between effects C^2 and D^2"

(8)

# My Step 7b: Build the design matrix with quadratic terms removed

reduced_basis   := [ 1, A, B, C, D, A*B, A*C, A*D, B*C, B*D, C*D]:
StructuralModel := add(cat(`alpha__`, b) * b, b in reduced_basis);

N := numelems(actual[..,1]);

DesignMatrix := `<|>`( Vector(N, 1), actual );
for i from 6 to numelems(reduced_basis) do
  opb := op(reduced_basis[i]):
  col := ListTools:-Search(opb[1], reduced_basis) - 1, ListTools:-Search(opb[2], reduced_basis) - 1;
  DesignMatrix := `<|>`( DesignMatrix, actual[.., col[1]]*~actual[.., col[2]] ):
  print(i, reduced_basis[i], [opb], [col]):
end do:

DesignMatrix;

Rank(DesignMatrix); # should be numelems(reduced_basis), thus 11
 

StructuralModel := A*B*`#msub(mi("&alpha;",fontstyle = "normal"),mi("A*B"))`+A*C*`#msub(mi("&alpha;",fontstyle = "normal"),mi("A*C"))`+A*D*`#msub(mi("&alpha;",fontstyle = "normal"),mi("A*D"))`+B*C*`#msub(mi("&alpha;",fontstyle = "normal"),mi("B*C"))`+B*D*`#msub(mi("&alpha;",fontstyle = "normal"),mi("B*D"))`+C*D*`#msub(mi("&alpha;",fontstyle = "normal"),mi("C*D"))`+A*`#msub(mi("&alpha;",fontstyle = "normal"),mi("A"))`+B*`#msub(mi("&alpha;",fontstyle = "normal"),mi("B"))`+C*`#msub(mi("&alpha;",fontstyle = "normal"),mi("C"))`+D*`#msub(mi("&alpha;",fontstyle = "normal"),mi("D",fontstyle = "normal"))`+`#msub(mi("&alpha;",fontstyle = "normal"),mi("1"))`

 

N := 20

 

DesignMatrix := Vector(4, {(1) = ` 20 x 5 `*Matrix, (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

 

6, A*B, [A, B], [1, 2]

 

7, A*C, [A, C], [1, 3]

 

8, A*D, [A, D], [1, 4]

 

9, B*C, [B, C], [2, 3]

 

10, B*D, [B, D], [2, 4]

 

11, C*D, [C, D], [3, 4]

 

Vector(4, {(1) = ` 20 x 11 `*Matrix, (2) = `Data Type: `*anything, (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

 

11

(9)

# The direct way to get the coefficient of the model

model_coeffs := (DesignMatrix^+ . DesignMatrix)^(-1) . (DesignMatrix^+ . Nu);

model_fitted := < reduced_basis > . model_coeffs assuming real;
 

model_coeffs := Vector(4, {(1) = ` 1 .. 11 `*Vector[column], (2) = `Data Type: `*float[8], (3) = `Storage: `*rectangular, (4) = `Order: `*Fortran_order})

 

HFloat(1.4634599999999889)+HFloat(0.8600000000001192)*A+HFloat(0.7200000000000486)*B+HFloat(0.5900000000000176)*C+HFloat(0.408000000000051)*D+HFloat(0.04999999999990477)*A*B+HFloat(0.039999999999936496)*A*C+HFloat(0.02999999999991024)*A*D+HFloat(0.01999999999999437)*B*C+HFloat(0.009999999999999242)*B*D+HFloat(0.025000000000005684)*C*D

(10)

# compare to your a prior model

evalf[3](model_fitted);

model_prior := beta[1] + beta[2]*A + beta[3]*B + beta[4]*C + beta[5]*D +
               beta[6]*A^2 + beta[7]*B^2 + beta[8]*C^2 + beta[9]*D^2 +
               beta[10]*A*B + beta[11]*A*C + beta[12]*A*D +
               beta[13]*B*C + beta[14]*B*D + beta[15]*C*D;


cmf := coeffs(evalf[3](model_fitted), vars, 'fmon');
fmon;

cmp := coeffs(model_prior, vars, 'cmon');
cmon;

# Agreement between "beta" and "cmf"

interface(rtablesize=16):
`<,>`(
  `<|>`(["effect", "beta", "fit"]),
  `<|>`(
    `<,>`(fmon),
    `<,>`(cmp[1..numelems([fmon])]),
    `<,>`(cmf)
  )
);

1.46+.860*A+.720*B+.590*C+.408*D+0.500e-1*A*B+0.400e-1*A*C+0.300e-1*A*D+0.200e-1*B*C+0.100e-1*B*D+0.250e-1*C*D

 

model_prior := .1*A^2+0.5e-1*A*B+0.4e-1*A*C+0.3e-1*A*D+.2*B^2+0.2e-1*B*C+0.1e-1*B*D+.15*C^2+0.25e-1*C*D+.18*D^2+.8*A+.6*B+.5*C+.3*D+1.5

 

cmf := 1.46, .860, .720, .590, .408, 0.500e-1, 0.400e-1, 0.300e-1, 0.200e-1, 0.100e-1, 0.250e-1

 

1, A, B, C, D, A*B, A*C, A*D, B*C, B*D, C*D

 

cmp := 1.5, .8, .6, .5, .3, 0.5e-1, 0.4e-1, 0.3e-1, 0.2e-1, 0.1e-1, 0.25e-1, .1, .2, .15, .18

 

1, A, B, C, D, A*B, A*C, A*D, B*C, B*D, C*D, A^2, B^2, C^2, D^2

 

Matrix(12, 3, {(1, 1) = "effect", (1, 2) = "beta", (1, 3) = "fit", (2, 1) = 1, (2, 2) = 1.5, (2, 3) = 1.46, (3, 1) = A, (3, 2) = .8, (3, 3) = .860, (4, 1) = B, (4, 2) = .6, (4, 3) = .720, (5, 1) = C, (5, 2) = .5, (5, 3) = .590, (6, 1) = D, (6, 2) = .3, (6, 3) = .408, (7, 1) = A*B, (7, 2) = 0.5e-1, (7, 3) = 0.500e-1, (8, 1) = A*C, (8, 2) = 0.4e-1, (8, 3) = 0.400e-1, (9, 1) = A*D, (9, 2) = 0.3e-1, (9, 3) = 0.300e-1, (10, 1) = B*C, (10, 2) = 0.2e-1, (10, 3) = 0.200e-1, (11, 1) = B*D, (11, 2) = 0.1e-1, (11, 3) = 0.100e-1, (12, 1) = C*D, (12, 2) = 0.25e-1, (12, 3) = 0.250e-1})

(11)

# the discrepancy between columns 2 and 3 comes from the quadratic effects which are considered
# as a model error or as an "observation" error due to some additive "noise.

# Step 8: Using Fit
model, Alpha := Fit(
           StructuralModel,
           actual,
           Nu,
           vars,
           output=["leastsquaresfunction", "parametervalues"]
         )[]:

model;

print():

# Observe you get the same results as above).

evalf[3](Alpha)

HFloat(1.4634599999999969)+HFloat(0.8600000000000063)*A+HFloat(0.04999999999999174)*A*B+HFloat(0.03999999999999232)*A*C+HFloat(0.029999999999991842)*A*D+HFloat(0.7200000000000056)*B+HFloat(0.019999999999993086)*B*C+HFloat(0.009999999999992097)*B*D+HFloat(0.5900000000000042)*C+HFloat(0.024999999999995408)*C*D+HFloat(0.4080000000000051)*D

 

 

[alpha__1 = 1.46, alpha__A = .860, `alpha__A*B` = 0.500e-1, `alpha__A*C` = 0.400e-1, `alpha__A*D` = 0.300e-1, alpha__B = .720, `alpha__B*C` = 0.200e-1, `alpha__B*D` = 0.100e-1, alpha__C = .590, `alpha__C*D` = 0.250e-1, alpha__D = .408]

(12)

# Finally

Predictor := unapply(model_fitted, vars);

display(
  pointplot([seq([i, Nu[i]], i = 1..20)], style=point, symbol=circle,

          color=red, title="Nusselt Number vs Run Index",

          labels=["Run", "Nusselt Number"]
          , legend="Observations")
  ,
  pointplot([seq([i, Predictor(convert(actual[i], list)[])], i = 1..20)], style=point, symbol=cross, color=blue
          , legend="Predictions")
);
  

proc (A, B, C, D) options operator, arrow; HFloat(1.4634599999999889)+HFloat(0.8600000000001192)*A+HFloat(0.7200000000000486)*B+HFloat(0.5900000000000176)*C+HFloat(0.408000000000051)*D+HFloat(0.04999999999990477)*A*B+HFloat(0.039999999999936496)*A*C+HFloat(0.02999999999991024)*A*D+HFloat(0.01999999999999437)*B*C+HFloat(0.009999999999999242)*B*D+HFloat(0.025000000000005684)*C*D end proc

 

 

# I don't understand what you are trying to achieve using ANOVA?
#
# Clarification is required

# Step 9: ANOVA table

anovaTable := ANOVA(model, significancelevel=0.05):

# Step 10: Display results with 8 decimal places

printf("RSM Model for Nu (Nusselt number):\n");

print(evalf[8](model));

printf("\nANOVA Table:\n");

print(anovaTable);

 

 

Download Nusselt_RSM_Model_mmcdara.mw



I started from eq (3.42) in the paper you provide in order to verify I got eq (3.43) .
Adapt it to your own example
 

restart

approx_sol := 3 -8*x + 24*x^2 - 208/3*x^3 + 200*x^4 - 8656/15*x^5 + 24976/15*x^6 + 553339/315*x^7 + 15550/21*x^8 + 502784/2835*x^9 + 125536/4725*x^10 + 78362/31185*x^11

3-8*x+24*x^2-(208/3)*x^3+200*x^4-(8656/15)*x^5+(24976/15)*x^6+(553339/315)*x^7+(15550/21)*x^8+(502784/2835)*x^9+(125536/4725)*x^10+(78362/31185)*x^11

(1)

p0 := numapprox:-pade(approx_sol, x, [3,3]);

(3+x+(6/5)*x^2+(1/15)*x^3)/(1+3*x+(2/5)*x^2+(1/5)*x^3)

(2)

p1 := map(sort, p0, x, ascending)

(3+x+(6/5)*x^2+(1/15)*x^3)/(1+3*x+(2/5)*x^2+(1/5)*x^3)

(3)

 


 

Download Pad.mw


... plus you used braces [to be used to define sets] instead of parenthesis in rge definition of dif2sag.

Once corrected a simple plot3d shows that lhs(G) is everywhere negative over the plotting range, which explains why implicitplot(G, ...) is "void".
Indeed Optimisation:-NLPSolve indicates max(G) = -0.60315e-5 within the plotting range.

m1(1)_mmcdara.mw

UPDATED:
Simply write this to see what happens

H := unapply(lhs(G), [kappa, M]):

Digits := 15:
plot(H(2.5, M), M=1e-6..1e-5); #, axis[1]=[mode=log]):

# You see that there is some M value such that H(2.5, M) = 0

fsolve(H(2.5, M)=0, M=1e-6..1e-5)
                     0.00000197261016360721

This means your M range starts at too high a value (0.05) for lhs(G) might be equal to 0.
Here is the locus of (kappa, M) points such that H(kappa, M) = 0:

# Finally the contour lhs(G) = 0 can be drawn this way

Contour0 := proc(k)   
  fsolve(H(k, M)=0, M=1e-6..1e-5) 
end proc: 

plot('Contour0'(kappa), kappa=2..3, numpoints=11, labels=[typeset(kappa), M])

# Image below


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