mmcdara

6149 Reputation

17 Badges

9 years, 62 days

MaplePrimes Activity


These are answers submitted by mmcdara

First: as you do not know a priori the number of iterations, it will be diffficult to predefine the array you talk about.
Secondly: the number of iterations depend on the method you use and on its parameters.
Thirdly: some methods have adaptive x steps and there is no simple relation between the number of the iteration and the physical time.

If yf1 and f2 do depend on the current iteration, why not write f1(x) and f2(x) instead ?

About events, look my answer to your previous question.

"Basically there is a very simply system of two differential equations and I would simply like to see an event triggered when the dependent variable is above 2"

In your worksheet you have written 

events = [[[0, 2-x < 0], [i(x) = i(x)+1]]]

but x is the independent variable.

Here are a few examples: the first and the second one correspond to what I understood (I arbitrarily used y(x) as the dependent variable used to monitor i(x)).

The third example is more complex: i(x) is augmented or reduce by one each time y(x) takes values +2 or -2. This example is purely illustrative.

The last example is a workaround to the condition "x > 2": it uses an auxuliary dependent variable w(x) defined by 

diff(w(x), x)=1, w(0)=0

Then, obviously, w(x)=x: "your" condition 

events = [[[0, 2-x < 0], [i(x) = i(x)+1]]]

then writes

events = [ [w(x)=2, i(x) = i(x)+1] ]

dsolve_events_mmcdara.mw

 

foo := proc(a, b) 
local x, y; 
x := a^2 - b; 
y := b^2 - a; 
printf("x=%a, y=%a, tests on return\n", x, y):
# or, if you prefer
# printf("%a, %a, tests on return\n", x, y):
return x, y
end proc:

A, B := foo(6, 3):
x=33, y=3, tests on return

A, B
                             33, 3

 

The simple way is 

ha := Histogram(
       samp
       , bincount = NumBins
       , size = [600, 400]
       , frequencyscale=absolute
       , gridlines=true
     ):
ha;

You can customise the plot this way

hb := plots:-display(
        ha
        , axis[2]=[tickmarks=[seq(i = nprintf("%2.1f%%", i), i = 0..8, 0.5)], color=red]
        , transparency=0.3
      ):
hb;

Histogram_percentage_mmcdara.m

Last improvement : in hb I set the max value of the y-axis to 8.
You can make this operation programatically:

pc_max := ceil(max(seq(plottools:-getdata(ha)[k][3][4, 2], k=1..NumBins))):

hb := plots:-display(
        ha
        , axis[2]=[tickmarks=[seq(i = nprintf("%2.0f%%", i), i = 0..pc_max, 1)], color=red]
        , transparency=0.3
      ):
hb;

... there is no way to do that with "standard" legend options.

Which doesn't mean it can't be done otherwise.
Here is a workaround: get inspired (if you want) and adapt it as you wish (if uou wtill want).

Remark: the values 0.95, 0.8, 1.2 and 0.03 have to be adjusted by hand

restart

with(plots):

opt := color=red, linestyle=1, thickness=3, font=[Tahoma, bold, 12]:
p := plot(sqrt(x), x=0..1, opt):

MyLegend := proc(a, b, l, t)
  display(
    plot([[a, b], [a+l, b]], opt)
    , textplot([a+l, b, t], align=right)
    , plottools:-rectangle([0.95*a, 0.8*b], [a+l+length(t)*0.03, 1.2*b], color=white)
  )
end proc:

# Set a, b, and l to suitable values

display(
  p,
  MyLegend(1/3, sqrt(1/3)/3, 0.1, "I am Legend"),
  gridlines=true
)

 

 

Download User_Legend.mw

To obtain the MajorAxis and the MinorAxis of an ellipse in canonical (cartesian) form just do this

restart
with(geometry):
_EnvHorizontalName := 'X': _EnvVerticalName := 'Y':
ellipse(ell, (9/4)*X^2+9*Y^2 = 1):
MajorAxis(ell), MinorAxis(ell);

Another way (same package) is 
 

restart with(geometry): _EnvHorizontalName := 'X': _EnvVerticalName := 'Y':
conic(c1, (9/4)*X^2+9*Y^2 = 1,[X, Y]):
detail(c1);
                 /                            
   GeometryDetail|["name of the object", c1], 
                 \                            

     ["form of the object", ellipse2d], ["center", [0, 0]], 

     [        [[  1  (1/2)   ]  [1  (1/2)   ]]]  
     ["foci", [[- - 3     , 0], [- 3     , 0]]], 
     [        [[  3          ]  [3          ]]]  

     [                            4]  
     ["length of the major axis", -], 
     [                            3]  

     [                            2]  
     ["length of the minor axis", -], 
     [                            3]  

     [                                9  2      2    ]\
     ["equation of the ellipse", -1 + - X  + 9 Y  = 0]|
     [                                4              ]/

Better if you are nor sure of the type of the conic

Firstly what you have written in your quesion is not syntactically correct, neither in Maple nor in mathematics.
Secondly, your "problem" is not well defined (2 equations and 7 formal quantities)

I guess you are a newbye in Maple.
So read the help page (search for solve, this should be a good start) to write syntactically correct relations: this will fix the first point baove.
For the second one it's up to you to correctly formalize what you want to do, for neither MAple, nor any other CAS will be able to give you the answer of your ill defined problem.

restart

How many syntax error does your pseudo-code contain ?
(You forgot almost everywhere the `*` sign!

After executing each line look where the pursor is set on the input line to see where the error comes from

{[[b/(sin(x-y-z))=a/(sin(z)),],[(a^(2)+b^(2)+2 abcos(x-y))cos(m(y+z)+n)=acos(mx+n)+bcos(my+n),]];

Error, `]` unexpected

 

{[[b/(sin(x-y-z))=a/(sin(z))],[(a^(2)+b^(2)+2 abcos(x-y))cos(m(y+z)+n)=acos(mx+n)+bcos(my+n),]];

Error, missing operator or `;`

 

{[[b/(sin(x-y-z))=a/(sin(z))],[(a^(2)+b^(2)+2*a*b*cos(x-y))cos(m(y+z)+n)=acos(mx+n)+bcos(my+n),]];

Error, missing operator or `;`

 

{[[b/(sin(x-y-z))=a/(sin(z))],[(a^(2)+b^(2)+2*a*b*cos(x-y))*cos(m(y+z)+n)=acos(mx+n)+bcos(my+n),]];

Error, `]` unexpected

 

{[[b/(sin(x-y-z))=a/(sin(z))],[(a^(2)+b^(2)+2*a*b*cos(x-y))*cos(m(y+z)+n)=acos(mx+n)+bcos(my+n)]];

Error, `;` unexpected

 

Here it is!

[[b/(sin(x-y-z))=a/(sin(z))],[(a^(2)+b^(2)+2*a*b*cos(x-y))*cos(m(y+z)+n)=acos(mx+n)+bcos(my+n)]];

[[b/sin(x-y-z) = a/sin(z)], [(a^2+b^2+2*a*b*cos(x-y))*cos(m(y+z)+n) = acos(mx+n)+bcos(my+n)]]

(1)

Nevertheless I think that acos is a typo mistake and should be a*cos?
Same thing for bcos, my instead of m*y, et caetera

[[b/(sin(x-y-z))=a/(sin(z))],[(a^(2)+b^(2)+2*a*b*cos(x-y))*cos(m*(y+z)+n)=a*cos(m*x+n)+b*cos(m*y+n)]];

[[b/sin(x-y-z) = a/sin(z)], [(a^2+b^2+2*a*b*cos(x-y))*cos(m*(y+z)+n) = a*cos(m*x+n)+b*cos(m*y+n)]]

(2)

There is no need for the inner square brackets

sys := [b/(sin(x-y-z))=a/(sin(z)), (a^(2)+b^(2)+2*a*b*cos(x-y))*cos(m*(y+z)+n)=a*cos(m*x+n)+b*cos(m*y+n)];

[b/sin(x-y-z) = a/sin(z), (a^2+b^2+2*a*b*cos(x-y))*cos(m*(y+z)+n) = a*cos(m*x+n)+b*cos(m*y+n)]

(3)

Two equalities and 7 indeterminates a, b, m, n, x, y, z
Here is a solution w.r.t [a, b]

solve(sys, [a, b])

[[a = 0, b = 0], [a = tan(z)*(-cos(x-y)*tan(z)*cos(m*y+n)+sin(x-y)*cos(m*y+n)+tan(z)*cos(m*x+n))/(sin(x-y)^2*cos(m*y+m*z+n)*(tan(z)^2+1)), b = -(tan(z)^2*sin(x-y)^2*cos(m*y+n)+tan(z)^2*cos(m*x+n)*cos(x-y)+2*tan(z)*sin(x-y)*cos(m*y+n)*cos(x-y)-tan(z)^2*cos(m*y+n)-tan(z)*sin(x-y)*cos(m*x+n)-sin(x-y)^2*cos(m*y+n))/(sin(x-y)^2*cos(m*y+m*z+n)*(tan(z)^2+1))]]

(4)

Harder: the solution  w.r.t [m, n] (no solution found)

solve(sys, [m, n])

Download Big_problems.mw

I am not very familiar with Python and even less with the HyperNext package.
So I cannot say if Maple 2022's GraphTheory package offers the same features that  HyperNext does.

But I believe the answer to your last question is "yes", at least if you accept to exchange the information between Maple and Python through files.

I use to use this mechanism to delegate to R (a programming language dedicated to statistics) things that Maple cannot do and recover in Maple the results from R.

Here is an example for Python
Python_Hypergraph_from_Maple.mw

restart:

interface(version)

`Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895`

(1)

with(GraphTheory):

e_nodes := seq(e||i, i=1..4):
v_nodes := seq(v||i, i=1..7):
nodes   := [e_nodes, v_nodes]:
G := Graph(nodes, {[e1, v1], [e1, v2], [e1, v3], [e2, v2], [e2, v3], [e3, v3], [e3, v5], [e3, v6], [e4, v4]})

GRAPHLN(directed, unweighted, [e1, e2, e3, e4, v1, v2, v3, v4, v5, v6, v7], Array(%id = 18446744078138018262), `GRAPHLN/table/15`, 0)

(2)

DrawGraph(G);

 

The Python code below come from this source
 https://stackoverflow.com/questions/9658373/using-hypergraphs-in-pygraph-need-verification-that-example-is-correct

from pygraph.classes.hypergraph import hypergraph

from pygraph.readwrite.dot import write_hypergraph

 

h = hypergraph()

 

h.add_nodes(['v1', 'v2', 'v3', 'v4', 'v5', 'v6', 'v7'])

h.add_hyperedges(['e1', 'e2', 'e3', 'e4'])

 

h.link('v1', 'e1')

h.link('v2', 'e1')

h.link('v3', 'e1')

h.link('v2', 'e2')

h.link('v3', 'e2')

h.link('v3', 'e3')

h.link('v5', 'e3')

h.link('v6', 'e3')

h.link('v4', 'e4')

 

with open('hypergraph.dot', 'w') as f:

    f.write(write_hypergraph(h))

 

edges := IncidentEdges(G, [e_nodes]);

# how to Maple write the code above?

printf("from pygraph.classes.hypergraph import hypergraph\n"):
printf("from pygraph.readwrite.dot import write_hypergraph\n"):
printf("h = hypergraph()\n"):
printf(cat("h.add_nodes([", seq(cat("'", u, "', "), u in v_edges[1..-2]), cat("'", v_edges[-1], "'"), "])\n"));
printf(cat("h.add_hyperedges([", seq(cat("'", u, "', "), u in e_edges[1..-2]), cat("'", e_edges[-1], "'"), "])\n"));
for edge in edges do
  printf(cat("h.link(", "'", edge[2], "', '", edge[1], "')\n"))
end do;
printf("with open('hypergraph.dot', 'w') as f:\n"):
printf("f.write(write_hypergraph(h))\n")
 

from pygraph.classes.hypergraph import hypergraph
from pygraph.readwrite.dot import write_hypergraph

h = hypergraph()
h.add_nodes(['v1', 'v2', 'v3', 'v4', 'v5', 'v6', 'v7'])
h.add_hyperedges(['e1', 'e2', 'e3', 'e4'])
h.link('v1', 'e1')
h.link('v2', 'e1')
h.link('v3', 'e1')
h.link('v2', 'e2')
h.link('v3', 'e2')
h.link('v3', 'e3')
h.link('v5', 'e3')
h.link('v6', 'e3')
h.link('v4', 'e4')
with open('hypergraph.dot', 'w') as f:
f.write(write_hypergraph(h))

 

# Instead of using printf use fprintf to write these lines in some ".py" script file
# for instance test.py
#
# run Python with script file "test.py"
# ssystem("python3 test.py")

In case you would like to recover in Maple the results produced by Python it'is "enough" to read from Maple the output file created by Python.
"enough" means "provided that the output format is compatible with Maple"

Here is your file corrected.
The corrections and/or explanations are written in brown (courier font when you will open the file with Maple).

(1) Question1: why the follwing solve output nothing???
In such a cas I use to use infolevel[the_function_I_use] to try and see what could happen.
Here infolevel[solve] := 4; says that 

Main: Entering solver with 15 equations in 1 variable
Transformer:   solving the uncoupled linear subsystem in {Ia1}
Linear: solving 15 linear equations
Polynomial: # of equations is: 2
Transformer:   system has a inconsistent linear subsystem
Main: solving successful - now forming solutions
Main: Exiting solver returning 0 solutions
solve: Warning: no solutions found

The important message is the first one.
Follow some brown commands which should (IMO) give some insights about the structure of your system and the collection of its "unknowns".

(2) From this quick look, and from what I understand when you write "what I expected is Ia1=f(Va1) which Va1 as indepentent,but the above solution have no Va1 ", I suggest you this:

  • The system of 15 equations contains 16 indeterminates.
  • One of them is Ia1.
  • Give Ia1 the special status of a "parameter".
    ( You could have define equList_Y11all := unapply(equList_Y11all, Ia1)) and solve(equList_Y11all(Ia1)) )
  • Define the "true unknowns" by 
    unknowns := remove(has, var_Y11, Ia1);
  • Solve equList_Y11all with respect to unknowns .
  • Let Y11_all the solution : Select from Y11_all the component of the form Va1 = ... .
  • Check that this component depends on Ia1
  • Isolate Ia1 from this component to get the desired (?) expression Ia1=f(Va1, ...)

     

Series Connect Couple Line Question

 

restart

with(LinearAlgebra): 

 

 

1.the first 4 equation

Ia(4*1)=Ya(4*4)*Va(4*1)

 

Ia := Vector(4, [Ia1, Ia2, Ia3, Ia4])

Vector[column]([[Ia1], [Ia2], [Ia3], [Ia4]])

(1)

Va := [Va1, Va2, Va3, Va4]; #must be a list!

[Va1, Va2, Va3, Va4]

(2)

Ya := Matrix([[Ya11, Ya12, Ya13, Ya14], [Ya21, Ya22, Ya23, Ya24], [Ya31, Ya32, Ya33, Ya34], [Ya41, Ya42, Ya43, Ya44]])

Matrix([[Ya11, Ya12, Ya13, Ya14], [Ya21, Ya22, Ya23, Ya24], [Ya31, Ya32, Ya33, Ya34], [Ya41, Ya42, Ya43, Ya44]])

(3)

equList_Ya := GenerateEquations(Ya, Va, Ia);

[Va1*Ya11+Va2*Ya12+Va3*Ya13+Va4*Ya14 = Ia1, Va1*Ya21+Va2*Ya22+Va3*Ya23+Va4*Ya24 = Ia2, Va1*Ya31+Va2*Ya32+Va3*Ya33+Va4*Ya34 = Ia3, Va1*Ya41+Va2*Ya42+Va3*Ya43+Va4*Ya44 = Ia4]

(4)

equation(4)is the first 4 equation set

 

 

 

2.the 2nd 4 equation

Ib(4*1)=Yb(4*4)*Vb(4*1)

 

Ib := Vector(4, [Ib1, Ib2, Ib3, Ib4])

Vector[column]([[Ib1], [Ib2], [Ib3], [Ib4]])

(5)

Vb := [Vb1, Vb2, Vb3, Vb4]; #must be a list!

[Vb1, Vb2, Vb3, Vb4]

(6)

Yb := Matrix([[Yb11, Yb12, Yb13, Yb14], [Yb21, Yb22, Yb23, Yb24], [Yb31, Yb32, Yb33, Yb34], [Yb41, Yb42, Yb43, Yb44]])

Matrix([[Yb11, Yb12, Yb13, Yb14], [Yb21, Yb22, Yb23, Yb24], [Yb31, Yb32, Yb33, Yb34], [Yb41, Yb42, Yb43, Yb44]])

(7)

equList_Yb := LinearAlgebra:-GenerateEquations(Yb, Vb, Ib);

[Vb1*Yb11+Vb2*Yb12+Vb3*Yb13+Vb4*Yb14 = Ib1, Vb1*Yb21+Vb2*Yb22+Vb3*Yb23+Vb4*Yb24 = Ib2, Vb1*Yb31+Vb2*Yb32+Vb3*Yb33+Vb4*Yb34 = Ib3, Vb1*Yb41+Vb2*Yb42+Vb3*Yb43+Vb4*Yb44 = Ib4]

(8)

equation(8)is the 2nd 4 equation set

 

 

3.the 3nd 4 equation

equList_ConnectCondition := [Ia3 = -Ib1, Ia4 = -Ib2, Va3 = Vb1, Va4 = Vb2];

[Ia3 = -Ib1, Ia4 = -Ib2, Va3 = Vb1, Va4 = Vb2]

(9)

 

 

 

unitl now,we have 12 equations

equList_all := {op(equList_Ya), op(equList_Yb), op(equList_ConnectCondition)}

{Ia3 = -Ib1, Ia4 = -Ib2, Va3 = Vb1, Va4 = Vb2, Va1*Ya11+Va2*Ya12+Va3*Ya13+Va4*Ya14 = Ia1, Va1*Ya21+Va2*Ya22+Va3*Ya23+Va4*Ya24 = Ia2, Va1*Ya31+Va2*Ya32+Va3*Ya33+Va4*Ya34 = Ia3, Va1*Ya41+Va2*Ya42+Va3*Ya43+Va4*Ya44 = Ia4, Vb1*Yb11+Vb2*Yb12+Vb3*Yb13+Vb4*Yb14 = Ib1, Vb1*Yb21+Vb2*Yb22+Vb3*Yb23+Vb4*Yb24 = Ib2, Vb1*Yb31+Vb2*Yb32+Vb3*Yb33+Vb4*Yb34 = Ib3, Vb1*Yb41+Vb2*Yb42+Vb3*Yb43+Vb4*Yb44 = Ib4}

(10)

equList_all_num := nops(equList_all)

12

(11)

 

what we want to get is Yparameter

(Vector(4, {(1) = Ia1, (2) = Ia2, (3) = Ib3, (4) = Ib4})) = Typesetting[delayDotProduct](Matrix(4, 4, {(1, 1) = Y11, (1, 2) = Y12, (1, 3) = Y13, (1, 4) = Y14, (2, 1) = Y21, (2, 2) = Y22, (2, 3) = Y23, (2, 4) = Y24, (3, 1) = Y31, (3, 2) = Y32, (3, 3) = Y33, (3, 4) = Y34, (4, 1) = Y41, (4, 2) = Y42, (4, 3) = Y43, (4, 4) = Y44}), Vector(4, {(1) = Va1, (2) = Va2, (3) = Vb3, (4) = Vb4}), true)

 

extra equations to get Y11

equList_Y11Condition := [Va2 = 0, Vb3 = 0, Vb4 = 0]

[Va2 = 0, Vb3 = 0, Vb4 = 0]

(12)

 

all equations for Y11

equList_Y11all := {op(equList_all), op(equList_Y11Condition)}

{Ia3 = -Ib1, Ia4 = -Ib2, Va2 = 0, Va3 = Vb1, Va4 = Vb2, Vb3 = 0, Vb4 = 0, Va1*Ya11+Va2*Ya12+Va3*Ya13+Va4*Ya14 = Ia1, Va1*Ya21+Va2*Ya22+Va3*Ya23+Va4*Ya24 = Ia2, Va1*Ya31+Va2*Ya32+Va3*Ya33+Va4*Ya34 = Ia3, Va1*Ya41+Va2*Ya42+Va3*Ya43+Va4*Ya44 = Ia4, Vb1*Yb11+Vb2*Yb12+Vb3*Yb13+Vb4*Yb14 = Ib1, Vb1*Yb21+Vb2*Yb22+Vb3*Yb23+Vb4*Yb24 = Ib2, Vb1*Yb31+Vb2*Yb32+Vb3*Yb33+Vb4*Yb34 = Ib3, Vb1*Yb41+Vb2*Yb42+Vb3*Yb43+Vb4*Yb44 = Ib4}

(13)

 

equList_all_num := nops(equList_Y11all)

15

(14)

 

16 var15 equation, so I hope to get Ia1=f(Va1) to calculate Y11=Ia1/Va1

var_Y11 := [Va1, Va2, Va3, Va4, Ia1, Ia2, Ia3, Ia4, Vb1, Vb2, Vb3, Vb4, Ib1, Ib2, Ib3, Ib4]

[Va1, Va2, Va3, Va4, Ia1, Ia2, Ia3, Ia4, Vb1, Vb2, Vb3, Vb4, Ib1, Ib2, Ib3, Ib4]

(15)

 

Question1: why the follwing solve output nothing???

infolevel[solve] := 4:

Main: Entering solver with 15 equations in 1 variable

Transformer:   solving the uncoupled linear subsystem in {Ia1}
Linear: solving 15 linear equations

Polynomial: # of equations is: 2
Transformer:   system has a inconsistent linear subsystem

Main: solving successful - now forming solutions
Main: Exiting solver returning 0 solutions
solve: Warning: no solutions found

 

 

# 15 equations and 47 indeterminates
# note that 3 equations are trivial : Va2=Vb3=Vb4=0


print~(equList_Y11all):
print():
`number of equations` = numelems(equList_Y11all);
indeterminates := indets(equList_Y11all, name);
`number of indeterminates` = numelems(indeterminates);
 

Ia3 = -Ib1

 

Ia4 = -Ib2

 

Va2 = 0

 

Va3 = Vb1

 

Va4 = Vb2

 

Vb3 = 0

 

Vb4 = 0

 

Va1*Ya11+Va2*Ya12+Va3*Ya13+Va4*Ya14 = Ia1

 

Va1*Ya21+Va2*Ya22+Va3*Ya23+Va4*Ya24 = Ia2

 

Va1*Ya31+Va2*Ya32+Va3*Ya33+Va4*Ya34 = Ia3

 

Va1*Ya41+Va2*Ya42+Va3*Ya43+Va4*Ya44 = Ia4

 

Vb1*Yb11+Vb2*Yb12+Vb3*Yb13+Vb4*Yb14 = Ib1

 

Vb1*Yb21+Vb2*Yb22+Vb3*Yb23+Vb4*Yb24 = Ib2

 

Vb1*Yb31+Vb2*Yb32+Vb3*Yb33+Vb4*Yb34 = Ib3

 

Vb1*Yb41+Vb2*Yb42+Vb3*Yb43+Vb4*Yb44 = Ib4

 

 

`number of equations` = 15

 

{Ia1, Ia2, Ia3, Ia4, Ib1, Ib2, Ib3, Ib4, Va1, Va2, Va3, Va4, Vb1, Vb2, Vb3, Vb4, Ya11, Ya12, Ya13, Ya14, Ya21, Ya22, Ya23, Ya24, Ya31, Ya32, Ya33, Ya34, Ya41, Ya42, Ya43, Ya44, Yb11, Yb12, Yb13, Yb14, Yb21, Yb22, Yb23, Yb24, Yb31, Yb32, Yb33, Yb34, Yb41, Yb42, Yb43, Yb44}

 

`number of indeterminates` = 48

(16)

member(Ia1, indeterminates)

true

(17)

# in your command solve the 2nd argument is intended to represent the variables you want to solve the system for
# one problem is that Ia1 is not an indeterminate of the system equList_Y11all)

if member(Ia1, indeterminates) then
  print("Ia1 is an indeterminate of the system"):
else
  print("Ia1 is not an indeterminate of the system"):
end if:
 

print~(equList_Y11all):

"Ia1 is an indeterminate of the system"

 

Ia3 = -Ib1

 

Ia4 = -Ib2

 

Va2 = 0

 

Va3 = Vb1

 

Va4 = Vb2

 

Vb3 = 0

 

Vb4 = 0

 

Va1*Ya11+Va2*Ya12+Va3*Ya13+Va4*Ya14 = Ia1

 

Va1*Ya21+Va2*Ya22+Va3*Ya23+Va4*Ya24 = Ia2

 

Va1*Ya31+Va2*Ya32+Va3*Ya33+Va4*Ya34 = Ia3

 

Va1*Ya41+Va2*Ya42+Va3*Ya43+Va4*Ya44 = Ia4

 

Vb1*Yb11+Vb2*Yb12+Vb3*Yb13+Vb4*Yb14 = Ib1

 

Vb1*Yb21+Vb2*Yb22+Vb3*Yb23+Vb4*Yb24 = Ib2

 

Vb1*Yb31+Vb2*Yb32+Vb3*Yb33+Vb4*Yb34 = Ib3

 

Vb1*Yb41+Vb2*Yb42+Vb3*Yb43+Vb4*Yb44 = Ib4

(18)

# the 4th message seems to say that solve operates on 12 equations only: remember 
# that 3 are trivial (see above).

unknowns := remove(has, var_Y11, Ia1);

Y11_all := solve(equList_Y11all, unknowns, symbolic = true):

[Va1, Va2, Va3, Va4, Ia2, Ia3, Ia4, Vb1, Vb2, Vb3, Vb4, Ib1, Ib2, Ib3, Ib4]

 

Main: Entering solver with 15 equations in 15 variables
Main: attempting to solve as a linear system
Linear: solving 15 linear equations
Polynomial: # of equations is: 12
Polynomial: best equation / unknown Ib1 Ia3 1
Polynomial: # of equations is: 11
Polynomial: best equation / unknown Ib2 Ia4 1
Polynomial: # of equations is: 10
Polynomial: best equation / unknown -Vb1 Va3 1
Polynomial: # of equations is: 9
Polynomial: best equation / unknown -Vb2 Va4 1
Polynomial: # of equations is: 8
Polynomial: best equation / unknown Vb1*Yb11+Vb2*Yb12 Ib1 -1
Polynomial: # of equations is: 7
Polynomial: best equation / unknown Vb1*Yb21+Vb2*Yb22 Ib2 -1
Polynomial: # of equations is: 6
Polynomial: best equation / unknown Vb1*Yb31+Vb2*Yb32 Ib3 -1
Polynomial: # of equations is: 5
Polynomial: best equation / unknown Vb1*Yb41+Vb2*Yb42 Ib4 -1
Polynomial: # of equations is: 4
Polynomial: best equation / unknown Vb1*Ya13+Vb2*Ya14-Ia1 Va1 Ya11
Polynomial: # of equations is: 3
Polynomial: best equation / unknown (Ya11*Ya23-Ya13*Ya21)*Vb1+(Ya11*Ya24-Ya14*Ya21)*Vb2+Ia1*Ya21 Ia2 -Ya11
Polynomial: # of equations is: 2
Polynomial: best equation / unknown (Ya11*Ya34+Ya11*Yb12-Ya14*Ya31)*Vb2+Ia1*Ya31 Vb1 Ya11*Ya33+Ya11*Yb11-Ya13*Ya31
Polynomial: # of equations is: 1
Polynomial: best equation / unknown -Ia1*Ya31*Ya43-Ia1*Ya31*Yb21+Ia1*Ya33*Ya41+Ia1*Ya41*Yb11 Vb2 Ya11*Ya33*Ya44+Ya11*Ya33*Yb22-Ya11*Ya34*Ya43-Ya11*Ya34*Yb21-Ya11*Ya43*Yb12+Ya11*Ya44*Yb11+Ya11*Yb11*Yb22-Ya11*Yb12*Yb21-Ya13*Ya31*Ya44-Ya13*Ya31*Yb22+Ya13*Ya34*Ya41+Ya13*Ya41*Yb12+Ya14*Ya31*Ya43+Ya14*Ya31*Yb21-Ya14*Ya33*Ya41-Ya14*Ya41*Yb11
Polynomial: backsubstitution at: 12
Polynomial: backsubstitution at: 11
Polynomial: backsubstitution at: 10
Polynomial: backsubstitution at: 9
Polynomial: backsubstitution at: 8
Polynomial: backsubstitution at: 7
Polynomial: backsubstitution at: 6
Polynomial: backsubstitution at: 5
Polynomial: backsubstitution at: 4
Polynomial: backsubstitution at: 3
Polynomial: backsubstitution at: 2
Polynomial: backsubstitution at: 1
Main: Linear solver successful. Exiting solver returning 1 solution

 

 

# let's check the solution

whattype(Y11_all);
numelems(Y11_all);  # consistent with the last displayed message by the solve command

# so let's redefine Y11_all this way:

Y11_all := Y11_all[1]:
whattype(Y11_all);
numelems(Y11_all);

list

 

1

 

list

 

15

(19)

# what unknown do depend on Ia1?

for k from 1 to numelems(Y11_all) do
  if  indets(Y11_all[k], name) intersect {Ia1} <> {} then
    printf("%a depends on Ia1\n", lhs(Y11_all[k]));
  else
    printf("%a does not depend on Ia1\n", lhs(Y11_all[k]));
  end if:
end do;

Va1 depends on Ia1

Va2 does not depend on Ia1
Va3 depends on Ia1
Va4 depends on Ia1
Ia2 depends on Ia1
Ia3 depends on Ia1
Ia4 depends on Ia1
Vb1 depends on Ia1
Vb2 depends on Ia1
Vb3 does not depend on Ia1
Vb4 does not depend on Ia1
Ib1 depends on Ia1
Ib2 depends on Ia1
Ib3 depends on Ia1
Ib4 depends on Ia1

 

# select Va1 from Y11_all

Va1_expr := select(has, Y11_all, Va1)[]

Va1 = Ia1*(Ya33*Ya44+Ya33*Yb22-Ya34*Ya43-Ya34*Yb21-Ya43*Yb12+Ya44*Yb11+Yb11*Yb22-Yb12*Yb21)/(Ya11*Ya33*Ya44+Ya11*Ya33*Yb22-Ya11*Ya34*Ya43-Ya11*Ya34*Yb21-Ya11*Ya43*Yb12+Ya11*Ya44*Yb11+Ya11*Yb11*Yb22-Ya11*Yb12*Yb21-Ya13*Ya31*Ya44-Ya13*Ya31*Yb22+Ya13*Ya34*Ya41+Ya13*Ya41*Yb12+Ya14*Ya31*Ya43+Ya14*Ya31*Yb21-Ya14*Ya33*Ya41-Ya14*Ya41*Yb11)

(20)

# isolate Ia1

isolate(Va1_expr, Ia1);

Ia1 = Va1*(Ya11*Ya33*Ya44+Ya11*Ya33*Yb22-Ya11*Ya34*Ya43-Ya11*Ya34*Yb21-Ya11*Ya43*Yb12+Ya11*Ya44*Yb11+Ya11*Yb11*Yb22-Ya11*Yb12*Yb21-Ya13*Ya31*Ya44-Ya13*Ya31*Yb22+Ya13*Ya34*Ya41+Ya13*Ya41*Yb12+Ya14*Ya31*Ya43+Ya14*Ya31*Yb21-Ya14*Ya33*Ya41-Ya14*Ya41*Yb11)/(Ya33*Ya44+Ya33*Yb22-Ya34*Ya43-Ya34*Yb21-Ya43*Yb12+Ya44*Yb11+Yb11*Yb22-Yb12*Yb21)

(21)

 

NULL

Download CoupleLineSeriesConnect_mmcdara.mw


... waiting for probably more astute proposals:

(be careful, not all H matrices define an ellipse)
ellipse_mmcdara.mw

restart:

H := Matrix(2$2, [3, 1, 1, 1]);
eigv := LinearAlgebra:-Eigenvectors(H)[2];

H := Matrix(2, 2, {(1, 1) = 3, (1, 2) = 1, (2, 1) = 1, (2, 2) = 1})

 

eigv := Matrix(2, 2, {(1, 1) = 1/(2^(1/2)-1), (1, 2) = 1/(-1-2^(1/2)), (2, 1) = 1, (2, 2) = 1})

(1)

c   := <1, 2>:
xy  := <x, y>:
d   := xy-c;
ell := expand(d^+ . H . d)=1

d := Vector(2, {(1) = x-1, (2) = y-2})

 

3*x^2+2*x*y+y^2-10*x-6*y+11 = 1

(2)

solve(ell, x)[1]:
select(has, [op(%)], y^2)[]:
y_bounds := solve(%^2, y):

solve(ell, y)[1]:
select(has, [op(%)], x^2)[]:
x_bounds := solve(%^2, x):

ranges := x=x_bounds[1]..x_bounds[2], y=y_bounds[1]..y_bounds[2];

plots:-display(
  plot([convert(c, list)], style=point, symbol=circle, symbolsize=20, color=blue)
  , plots:-implicitplot(ell, ranges, grid=[50, 50])
  , plots:-implicitplot(eigv[..,1].d=0, ranges, linestyle=3, color=blue)
  , plots:-implicitplot(eigv[..,2].d=0, ranges, linestyle=3, color=blue)
  , view=[0..2, 0..4]
  , scaling=constrained
);

 

 
 

 

 

Here is a quick example for 

x := [-2, -3/2, -1, -1/2, 0, 1/2, 1, 3/2, 2]
(-2)^~x;
[1/4, (1/4)*sqrt(-2), -1/2, -(1/2)*sqrt(-2), 1, sqrt(-2), -2, -2*sqrt(-2), 4]

A workaround might be to use plots:-complexplot (sorry I can only insert the link not the content of the file)

Maple Worksheet - Error
Failed to load the worksheet /maplenet/convert/explanation.mw

Download explanation.mw


Here is a proposal where the OperatorForm is used for NLPSolve.
One interest here is to trace the evolution of the optimization process (I use MAPLE 2015 and it doesn't seem that a trace mode is avliable through some option ???)
(To trace the evolution uncomment the yellow highlighted command)
 

restart:with(LinearAlgebra):

N:=3:

m:=Vector([ 1 , log(x+b3) , b2/(x+b3) ]):

A:=m.m^+:

for i to N do
m||i:=eval(A,[x=x||i]);
od:

M:=add(w||i*m||i,i=1..N-1)+(1-add(w||i,i=1..N-1))*m||N:

MM:=( LinearAlgebra:-Trace(MatrixInverse(M)) ):

IF1 := proc(__w1, __w2, __x1, __x2, __x3)
  local J:
  J := evalf(
         Int(
           eval(MM, [w1=__w1, w2=__w2, x1=__x1, x2=__x2, x3=__x3])
           , [b2=1..2,b3=1..2]
           , method = _d01ajc
           , epsilon=0.001
         )
       ):
  # print([_passed], J);
  return J:
end proc:

# check

IF1(0.6, .1, 8, 7, 5);

2204832.780

(1)

s:= Optimization:-NLPSolve(
  IF1
  , 0..1, 0..1, 7..10, 5..10, 1..10
  , initialpoint=[0.6, .1, 8, 7, 5]
  , maximize=false
)

s := [482.354032179177977, Vector(5, {(1) = 1.0, (2) = 1.0, (3) = 10.0, (4) = 5.0, (5) = 1.0}, datatype = float[8])]

(2)

 

 

Download LinearLog-A-Bayesian_1_mmcdara.mw

 


Functions 1 and 4 are of the form 

+/-sqrt(-2+2*cos(z))

and are purely imaginary for any valu of z.

It's up to you to know how to fix this :-)



 

s this possible?

  • formally : NO YES
  • numerically YES

Here is my first reply where solve gave no results. I keep the file for it contains a plot you might find useful.

Half_Width_mmcdara.mw

And here is the file where the two points are computed formally:

restart

f := (x, x__0, S, C) -> -C*(exp(S*(x - x__0)^2*(-1/2)) - 1)*Heaviside(x - x__0)

proc (x, x__0, S, C) options operator, arrow; -C*(exp(-(1/2)*S*(x-x__0)^2)-1)*Heaviside(x-x__0) end proc

(1)

X0   := 0:
fDOG := unapply(f(x, X0, S__a, 1) - f(x, X0, S__d, 1), (x, S__a, S__d))

proc (x, S__a, S__d) options operator, arrow; -(exp(-(1/2)*S__a*x^2)-1)*Heaviside(x)+(exp(-(1/2)*S__d*x^2)-1)*Heaviside(x) end proc

(2)

DfDOG := diff(fDOG(x, S__a, S__d), x) assuming x > X0

S__a*x*exp(-(1/2)*S__a*x^2)-S__d*x*exp(-(1/2)*S__d*x^2)

(3)

solve({DfDOG=0, x > X0}, x) assuming S__a > S__d;
tpeak := eval(x, %[1])

[{x = 2^(1/2)*((S__a-S__d)*ln(S__a/S__d))^(1/2)/(S__a-S__d)}, x = x]

 

2^(1/2)*((S__a-S__d)*ln(S__a/S__d))^(1/2)/(S__a-S__d)

(4)

hpeak := fDOG(tpeak, S__a, S__d) assuming S__a > S__d, S__d > 0

-exp(-S__a*ln(S__a/S__d)/(S__a-S__d))+exp(-S__d*ln(S__a/S__d)/(S__a-S__d))

(5)

half_hpeak := hpeak/2;

-(1/2)*exp(-S__a*ln(S__a/S__d)/(S__a-S__d))+(1/2)*exp(-S__d*ln(S__a/S__d)/(S__a-S__d))

(6)

eq := fDOG(x, S__a, S__d) = half_hpeak assuming x > X0;

MyChange := ln(S__a/S__d) = (u/sqrt(2))^2*(S__a-S__d); # u is > 0
eval(eq, MyChange);
eval(%, [S__a=2, S__d=1]);
 

-exp(-(1/2)*S__a*x^2)+exp(-(1/2)*S__d*x^2) = -(1/2)*exp(-S__a*ln(S__a/S__d)/(S__a-S__d))+(1/2)*exp(-S__d*ln(S__a/S__d)/(S__a-S__d))

 

ln(S__a/S__d) = (1/2)*u^2*(S__a-S__d)

 

-exp(-(1/2)*S__a*x^2)+exp(-(1/2)*S__d*x^2) = -(1/2)*exp(-(1/2)*S__a*u^2)+(1/2)*exp(-(1/2)*S__d*u^2)

 

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

(7)

xofu := [solve(%, x)];
 

[(-2*ln(1/2+(1/2)*(1+2*(exp(-(1/2)*u^2))^2-2*exp(-(1/2)*u^2))^(1/2)))^(1/2), -(-2*ln(1/2+(1/2)*(1+2*(exp(-(1/2)*u^2))^2-2*exp(-(1/2)*u^2))^(1/2)))^(1/2), (-2*ln(1/2-(1/2)*(1+2*(exp(-(1/2)*u^2))^2-2*exp(-(1/2)*u^2))^(1/2)))^(1/2), -(-2*ln(1/2-(1/2)*(1+2*(exp(-(1/2)*u^2))^2-2*exp(-(1/2)*u^2))^(1/2)))^(1/2)]

 

2^(1/2)*((S__a-S__d)*ln(S__a/S__d))^(1/2)/(S__a-S__d), -2^(1/2)*((S__a-S__d)*ln(S__a/S__d))^(1/2)/(S__a-S__d)

(8)

solve(MyChange, u);
x_half_peak := eval(xofu, u=%[1]);

2^(1/2)*((S__a-S__d)*ln(S__a/S__d))^(1/2)/(S__a-S__d), -2^(1/2)*((S__a-S__d)*ln(S__a/S__d))^(1/2)/(S__a-S__d)

 

[(-2*ln(1/2+(1/2)*(1+2*(exp(-ln(S__a/S__d)/(S__a-S__d)))^2-2*exp(-ln(S__a/S__d)/(S__a-S__d)))^(1/2)))^(1/2), -(-2*ln(1/2+(1/2)*(1+2*(exp(-ln(S__a/S__d)/(S__a-S__d)))^2-2*exp(-ln(S__a/S__d)/(S__a-S__d)))^(1/2)))^(1/2), (-2*ln(1/2-(1/2)*(1+2*(exp(-ln(S__a/S__d)/(S__a-S__d)))^2-2*exp(-ln(S__a/S__d)/(S__a-S__d)))^(1/2)))^(1/2), -(-2*ln(1/2-(1/2)*(1+2*(exp(-ln(S__a/S__d)/(S__a-S__d)))^2-2*exp(-ln(S__a/S__d)/(S__a-S__d)))^(1/2)))^(1/2)]

(9)

{abs~(x_half_peak)[]}

{2^(1/2)*abs(ln(1/2-(1/2)*(1+2*(exp(-ln(S__a/S__d)/(S__a-S__d)))^2-2*exp(-ln(S__a/S__d)/(S__a-S__d)))^(1/2)))^(1/2), 2^(1/2)*abs(ln(1/2+(1/2)*(1+2*(exp(-ln(S__a/S__d)/(S__a-S__d)))^2-2*exp(-ln(S__a/S__d)/(S__a-S__d)))^(1/2)))^(1/2)}

(10)

sa := 2:
sd := 1:

eval(x_half_peak, [S__a=sa, S__d=sd]):
select(is@`>`, %, 0);
evalf(%);

[(-2*ln(1/2+(1/4)*2^(1/2)))^(1/2), (-2*ln(1/2-(1/4)*2^(1/2)))^(1/2)]

 

[.5627560464, 1.960150176]

(11)

# Applying "select" directly on x_half_peak doesn't work.
# I believe the following is correct but this must be checked

`correct?` := {abs~(x_half_peak)[]};
eval(`correct?`, [S__a=sa, S__d=sd]):
evalf(%);

{2^(1/2)*abs(ln(1/2-(1/2)*(1+2*(exp(-ln(S__a/S__d)/(S__a-S__d)))^2-2*exp(-ln(S__a/S__d)/(S__a-S__d)))^(1/2)))^(1/2), 2^(1/2)*abs(ln(1/2+(1/2)*(1+2*(exp(-ln(S__a/S__d)/(S__a-S__d)))^2-2*exp(-ln(S__a/S__d)/(S__a-S__d)))^(1/2)))^(1/2)}

 

{.5627560463, 1.960150176}

(12)

 

Download Formal__Half_Width_mmcdara.mw

This has been made possible after introducing a change of variables

u = sqrt(2)*sqrt((S__a-S__d)*ln(S__a/S__d))/(S__a-S__d)


 

restart:

H_lines := seq(CURVES([[0, i], [1, i]], LINESTYLE(2)), i in [seq](0..1, 0.1)):
V_lines := seq(CURVES([[i, 0], [i, 1]], LINESTYLE(2)), i in [seq](0..1, 0.1)):
H_vec   := plottools:-arrow([0, 0], [0.1, 0], .005, .02, .4, color=black):
V_vec   := plottools:-arrow([0, 0], [0, 0.1], .005, .02, .4, color=black):

p := PLOT(H_lines, V_lines, H_vec, V_vec):
plots:-display(p, axes=none);

 

T := (a, b) -> plottools:-transform((x, y) -> [x+a*y, y+b*x]):

plots:-display(T(2, 3)(p), axes=none)

 

 


 

Download One_method.mw

First 19 20 21 22 23 24 25 Last Page 21 of 52