mmcdara

3728 Reputation

17 Badges

6 years, 26 days

MaplePrimes Activity


These are replies submitted by mmcdara

@tangentspace 

Unless I'm mistaken your problem has no solution.
You will find in the attache file:

  • the solution of the "lagrange multipliers problem"
  • a quick way to prove there is no solution
  • the proof that even the unconstrained maximization problem has no solution  

Download constrained_maximization.mw

@vv 

Thank you vv. It's clearer now.

@vv 

Great.

When you compute 

series(eval(i3_r,[x=t*x,y=t*y,z=t*z]),t=0)

x, y, z tend to 0 simultanously along the first diagonal: why does this give the same result as mtaylor?

For instance, if you do this

convert(mtaylor(f(x, y), [x,y], 3), Diff)

there is no evidence that mtaylor uses directional derivatives.
End even if it doe so, why would they be taken alonq the direction (1, 1) ?

@Kitonum 

That's probably the explanation.

This question was asked to me by a colleague who said it had obtained the mtaylor expansion of i2(x,y) in ... 1996 !!!
Something that even MAPPLE 2015.2 can't do.
Probably an example of code regression that has since been fixed.

@Kitonum 

It was my very, very first idea, but it returns an error with MAPLE 2015.2:
Error, (in mtaylor) does not have a taylor expansion, try series()

I guess you use a more recent version?

Thanks

@permanoon123

If you prefer to fit a straight line to the data, instead of a plane, things are a little bit more complex.

From a philosophical point of view:

  • Seeking for a statistical model Z= f(X, Y) by the usual least squares method means that you consider X and Y are the common causes of Z.
    If f(X, Y) = a+b*X+c*Y the graph of this model is a plane.
     
  • But you might have no prior knowledge about who is the cause of who.
    In this case a classical approach is to find the 2D curve C(X, Y, Z) such that the sum of the square distances of the observed points to this curve is minimum (also termed "Orthogonal Least Squares"). In some sense you avoid orienting the causal effects and give X, Y and Z equivalent roles.

From a technical point of view:
Up to my knowledge Maple doesn't have built-in functions to find suche a curve, meaning you must do some of the work "by hand".
You will find in the attached file how to construct the 3D straight line which minimizes ehe Orhtogonal Least Squares.

The las plot contains the 11 empirical points, the best plane in the ordinaty least squares (philosophical point of view number 1) and the best straight laine in the orthogonl least squares sense  (philosophical point of view number 2).

It's up to you to determine what you want according to your knowledge of the "physical" problem.

restart

with(plottools):

with(plots):

with(CurveFitting):

with(Statistics):

Digits := 10:

NULL

L := point([146, 146, 207], color = red, symbol = cross, symbolsize = 50), point([143, 143, 205], color = red, symbol = cross, symbolsize = 50), point([55, 55, 140], color = red, symbol = cross, symbolsize = 50), point([65, 65, 148], color = red, symbol = cross, symbolsize = 50), point([733, 275, 632], color = red, symbol = cross, symbolsize = 50), point([379, 379, 379], color = red, symbol = cross, symbolsize = 50), point([186, 153, 418], color = red, symbol = cross, symbolsize = 50), point([48, 31, 88], color = red, symbol = cross, symbolsize = 50), point([753, 753, 655], color = red, symbol = cross, symbolsize = 50), point([33, 33, 124], color = red, symbol = cross, symbolsize = 50), point([90, 54, 66], color = red, symbol = cross, symbolsize = 50):

display(L, axes = boxed, view = [-800 .. 800, -800 .. 800, -800 .. 800], orientation = [125, 65], title = `Thoracic IDEM`, labels = [First, Min, Predicted], labelfont = ["HELVETICA", 20], titlefont = ["ROMAN", 30]):

pts := `<,>`(op~(1, [L])[]);
fit := LinearFit([1, x, y], pts, [x, y]);
 

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

 

HFloat(97.30505582057918)+HFloat(0.7138648126312153)*x+HFloat(0.054368022971203536)*y

(1)

# Fit the straight line L to the points by mimizing the sum of the square distances
# from the points to this line.
#
# Line L necessarily passes from the barycenter M (a vector) of the points.
# Line L is then defined by M + t*U where U is the vector of director cosines.

M := Mean(pts);
straight_line := (a, b, c) -> t -> M + `<|>`(a, b, c) *~ t:

M := Vector[row](3, {(1) = 239.181818181818, (2) = 189.727272727273, (3) = 278.363636363636})

(2)

# The distance dist(P, U) from point P to the line L is

dist := (P, U) -> norm( (M-P) - ((M-P) . U) /~ norm(U, 2)^2 *~ U^+, 2)^2:

# The objective function is the sum of the square distances dist(P,U) over all the data points:

N := numelems(pts[..,1]);
obj := (a, b, c) -> simplify(add(dist(pts[k],  `<,>`(a, b, c)), k=1..N))

11

 

proc (a, b, c) options operator, arrow; simplify(add(dist(pts[k], `<,>`(a, b, c)), k = 1 .. N)) end proc

(3)

# Simplify the objective function vy considering ythat U has norm 1

OBJ := simplify(obj(a, b, c), {abs(a)^2+abs(b)^2+abs(c)^2=1}):

# Find (a, b, c) such that grad(OBJ) = 0

sol := fsolve([seq(diff(OBJ, p)=0, p in [a, b, c])])

{a = -.6763853273, b = -.5151945705, c = -.5263814619}

(4)

# Construct the straight line L

straight_line := t -> convert(M + t *~ eval(`<|>`(a, b, c), sol), list):

print~( [x, y, z] =~ straight_line(t) ):

x = HFloat(239.1818181818182)-.6763853273*t

 

y = HFloat(189.72727272727272)-.5151945705*t

 

z = HFloat(278.3636363636364)-.5263814619*t

(5)

# Do the plotting

display(
  L,
  plot3d(fit, x=(min..max)(pts[..,1]), y=(min..max)(pts[..,2]), style=wireframe, color="Gray"),
  plots:-spacecurve(straight_line(t), t=-1000..1000, color=blue, thickness=5),
  axes = boxed,
  view = [-800 .. 800, -800 .. 800, -800 .. 800],
  orientation = [125, 65],
  title = `Thoracic IDEM`,
  labels = [First, Min, Predicted],
  labelfont = ["HELVETICA", 20],
  titlefont = ["ROMAN", 30]
)

 

 

Download H_M_mmcdara_2.mw

@permanoon123 

So I answered your question in my last post, didn't I?

Here is the extended worksheet

restart

with(plottools):

with(plots):

with(CurveFitting):

with(Statistics):

Digits := 10:

NULL

L := point([146, 146, 207], color = red, symbol = cross, symbolsize = 50), point([143, 143, 205], color = red, symbol = cross, symbolsize = 50), point([55, 55, 140], color = red, symbol = cross, symbolsize = 50), point([65, 65, 148], color = red, symbol = cross, symbolsize = 50), point([733, 275, 632], color = red, symbol = cross, symbolsize = 50), point([379, 379, 379], color = red, symbol = cross, symbolsize = 50), point([186, 153, 418], color = red, symbol = cross, symbolsize = 50), point([48, 31, 88], color = red, symbol = cross, symbolsize = 50), point([753, 753, 655], color = red, symbol = cross, symbolsize = 50), point([33, 33, 124], color = red, symbol = cross, symbolsize = 50), point([90, 54, 66], color = red, symbol = cross, symbolsize = 50):

display(L, axes = boxed, view = [-800 .. 800, -800 .. 800, -800 .. 800], orientation = [125, 65], title = `Thoracic IDEM`, labels = [First, Min, Predicted], labelfont = ["HELVETICA", 20], titlefont = ["ROMAN", 30])

 

pts := `<,>`(op~(1, [L])[]);
fit := LinearFit([1, x, y], pts, [x, y]);

display(
  L,
  plot3d(fit, x=(min..max)(pts[..,1]), y=(min..max)(pts[..,2]), style=wireframe, color="Gray"),
  axes = boxed,
  view = [-800 .. 800, -800 .. 800, -800 .. 800],
  orientation = [125, 65],
  title = `Thoracic IDEM`,
  labels = [First, Min, Predicted],
  labelfont = ["HELVETICA", 20],
  titlefont = ["ROMAN", 30]
)
 

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

 

HFloat(97.30505582057918)+HFloat(0.7138648126312153)*x+HFloat(0.054368022971203536)*y

 

 

 

Download H_M_mmcdara.mw

Just a simple remark to say that t^2*(x-y)*(x+y) has an even smaller size than t^2*(x^2-y^2) 

The most simplified expression in terms of size thus should be t^2*(x-y)*(x+y) ... which is probably the expression someone would says is the simplest (visually).

@vv 

Sorry, I did'nt know.

By the way, I compared inert forms of t^2*x^2 + t^2*y^2 and t^2*x^2 - t^2*y^2 and and they are quite different in the way the seconf op (+/- t^2*y^2) is represented.
In the case t^2*y^2 the representation is 

_Inert_PROD(
    _Inert_POWER(
      _Inert_NAME("t"), 
      _Inert_INTPOS(2)
    ),
    _Inert_POWER(
      _Inert_NAME("y"), 
      _Inert_INTPOS(2)
    )
  )

while for -t^2*y^2  it becomes

 _Inert_PROD(
    _Inert_PROD(
      _Inert_POWER(
        _Inert_NAME("t"), 
        _Inert_INTPOS(2)
      ), 
      _Inert_POWER(
        _Inert_NAME("y"),
        _Inert_INTPOS(2)
      )
    ), 
    _Inert_INTNEG(1)
  )

Given that something like t^2*y^2*z^2 has this form

_Inert_PROD(
    _Inert_POWER(
      _Inert_NAME("t"), 
      _Inert_INTPOS(2)
    ),
    _Inert_POWER(
      _Inert_NAME("y"), 
      _Inert_INTPOS(2)
    ),
    _Inert_POWER(
      _Inert_NAME("z"), 
      _Inert_INTPOS(2)
    )
  )

led me to write this

simplify(t^2*x^2 + t^2*y^2*one, size):
eval(%, one=-1)
                           2 / 2    2\
                          t  \x  - y /

I guess that the way MAPLE simplifies an expression, or doesn't, is related to the structure of the syntactic graph of this expression?


So I wonder if MMA treats the term -t^2*y^2 like the product of 3 quantities or, like MAPLE does, as two embedded products ? Maybe @nm could answered that?
This could be an explanation of the way the simplifications differ for these two CAS?

For info... MAPLE 2015 was consistent in its failure to simplify

restart:
interface(version);
Standard Worksheet Interface, Maple 2015.2, Mac OS X, December 21 2015 Build ID 1097895

simplify(t^2*x^2 + t^2*y^2);
                          2  2    2  2
                         t  x  + t  y 
simplify(t^2*x^2 - t^2*y^2);
                          2  2    2  2
                         t  x  - t  y 

@acer 
Don't you think @janhardo wants something like this?

restart:
L:=[0, Pi/6, Pi/4, Pi/3, Pi/2]:
R := [p -> p, f]~(L);
eval(R, f=sin);
eval(R, f=(x->sin(x)));

Or maybe?

eval(R, f=''sin'');

@Carl Love 

You know Carl, I'm not like you: I just try to answer the question asked, knowing perfectly well that I don't have the necessary skills to provide an answer to more general, but unformulated, variations of the initial question.

For the question sked; as for any numerical evaluation of a formal expression, it seems to me that the natural approach is to first simplify the expression to be evaluated. Then it "works" or not, which is another problem.
It just so happens that it did worked. 

Other point: I don't completely agree with you when you say "Kitonum's method completely avoids the roundoff by reducing the number of floating-point computations to just one, the final division."
Kitonum's method works because hedoes the computations with rationals and take advantage of "infinite" MAPLE's precision in rational, which is very diffferent (IMO) of what you say.
Kitonum's method woud have been inefficient in other languages (MATLAB, FORTRAN, C... ) which generally use 4 or 8 bytes integers.

Last point: As the title of the question is "Divergence or convergence" and because this is a CAS forum, I even find strange that no one answered (including me) that "the proof can be done by computing the formal limit of the expression as y --> 1, and that any attempt to conclude by using floating point numbers is a nonsense".

Just a simple reply, @acer will probably give you a more substantial answer.
Meanhile you can find here mathml_overscripts.htm the basic elements of MathML language.
A list of MathML codes can be found here special_ascii_characters.

the command nprintf(`"%1.3e", p) enables a fine control of the display of the number p, but p is not displayed as a number (default Times font) but as a name (Times italic font).
nprintf(`#mn(\"%1.3e\");` , p) is the way to avoid the italic font.
Note that nprintf(`#mi(\"%1.3e\");` , p) forces the italic font and its eqivalent, in this case, to nprintf(`"%1.3e", p).

A few simple examples are given in the attached file.
mi_mn.mw

@lcz 

Without any aditional constraint MMA's answer {1, 2, 3, 4, 7, 8} is not "better" than any of the other answers Tom provided.
Things could be different if edges (or vertices) had weights and if you wanted to find, among all equivalent vertex cuts, assuming there are many, the one (the ones?) wich minimizes (minimize) some weight loss.

An illustration is provided here Vertex_Cut.mw

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