## 15 Reputation

6 years, 246 days

## Pick the "positive" solution of a quadra...

Maple 2016

Quadratic equation ax^2 + bx + c = 0. Coeff's long and ugly expressions in their own right, but I know that a is nonzero, that there is at least one real solution, and that I want the largest.

So, question: How do I get Maple to return the -b/2a PLUS sqrt((b/2a)^2-c/a) solution?

## How do I collect & match polynomial coef...

Maple 2016

I have several functional equations in equally many unknown functions of at least two variables, plus parameters.  ("collect" works just for single equations, right?)

I know that for certain parameter ranges, all the functions involved will be quadratic, and I know some coefficients are zero.  That gives me some  coefficients to determine.  I want to

1. specify the functional equations [done in a very primitive low-tech way in the attachment, using atomic variables rather than indices ... have I done correctly?!?]
2. get Maple to collect coefficients (the K's and the L's in the attachment; the variables are (y,z))
3. get Maple to state an equation system these coefficients have to satisfy (these will unfortunately be coupled quadratics)
4. get Maple to solve that equation system if possible, and if not: to tell me when (= for what parameter values, parameters being the "remaining letters" in the attachment) I have specified enough coefficients
5. in case of a solution, get Maple to tell me which coefficients are real and positive (for those that are solution of quadratic eq's: whether a positive solution exists)

Phew. I am still a complete newbie. Edit: Attachment link: STcoeff2match.mw where the equations themselves are EQ0, EQ1 and EQ2 at the bottom. Copying and pasting them, they look like this (download STcoeff2pastedEQs.mw)

 >

 >

## How to formulate this eq. (system) with ...

Apologies for possible double post, it seemingly locked up upon trying to post the first time.

So before I get as far as to ask for how to get a certain PDE system solved and plotted, I tried to fiddle a little bit around with linear algebra.

• First, the file SystemGoesWrong.mw . I have issues with declaring (same result if I remove the with(VectorCalculus)); as far as I can see, EQ0 and EQ00 should be the same, except that I have summed the vector in one of them. And the first that "works", is wrong: it returns a scaling of a vector. How come?
• But then I copy everything from the heading and down into a worksheet where I was already fighting some linear algebra things (can someone please explain?): SystemDeclaresBut.mw
Then EQ0 and EQ00 declare just fine! What is the issue?
• How do I get Maple to list the equations in "compact" form with vector-valued functions so that I can read and debug?  The actual PDE system I want to solve (numerically, of course), looks as follows: DE4Maple.pdf
That was also the reason why I tried to declare procedures (coordinate-wise maximum ...), but I guess that questions on how to extract a solution and plot it in a particular way will be its own posting after I have learned how to declare it.

The contents of the first file:

 >

# Since I do not have any idea of how to get vectors nicely, ...

... I replace U0, U1, U2 by u,v,w and use difftables U,V,W.  And y1, y2 replaced by y,z.

 >
 >
 (1)
 >
 >
 (2)
 >
 (3)

# The system

 >
 (4)
 >
 >
 >

... and of the second:

 >

Over to some linear algebra.

 >
 >
 >
 (1)
 >
 (2)
 >
 (3)
 >
 (4)
 >
 >
 >
 normsqbyDot := proc() local theArgs, arg, look, me, cf, term;    1   me := eval(procname,1);    2   theArgs := args;    3   look := tablelook(('procname')(theArgs),'[`/POS`(1,normsqbyDot,1), `/BIND`(1,1,`/y1`::VectorCalculus:-Vector), `/PATTERN`(`/y1`^2)]');    4   if look <> FAIL then    5     eval(look,`/FUNCNAME` = procname)        else    6     ('procname')(theArgs)        end if end proc
 >
 >
 normsqbyMatrixProduct := proc() local theArgs, arg, look, me, cf, term;    1   me := eval(procname,1);    2   theArgs := args;    3   look := tablelook(('procname')(theArgs),'[`/POS`(1,normsqbyMatrixProduct,1), `/BIND`(1,1,`/y1`::Matrix), `/PATTERN`(`/y1`^2)]');    4   if look <> FAIL then    5     eval(look,`/FUNCNAME` = procname)        else    6     ('procname')(theArgs)        end if end proc
 >
 >
 (5)
 >
 (6)
 >

# Since I do not have any idea of how to get vectors nicely, ...

... I replace U0, U1, U2 by u,v,w and use difftables U,V,W.  And y1, y2 replaced by y,z.

 >
 (7)
 >
 (8)
 >
 >
 (9)
 >
 (10)

# The system

 >
 (11)
 >
 (12)
 >

## How to force simplification of this ODE ...

Maple

So I encountered a Chini differential equation which is solvable in terms of an implicit function

```restart; assume(nu > 2, beta > 0, lambda > 0, delta > 0, y >= 0);
simplify(dsolve(beta+y+(D(h))(y) = nu*((lambda+beta+y)^2-delta*h(y))^(1/2)));
```

The answer is really too ugly to be pasted here, but I do get a
RootOf [ linear + log(linear) + delta* some integral + 2 * the very same integral]

It took me a quarter of an hour to deciphre that the integrals are the same and that I could get it all down to (delta+2)*integral. Because Maple did not simplify it.

But if I copy what is inside the RootOf(), and paste it into a simplify() - then it does! So how to force it into doing that in the first place?

Still novice, yes ...

## Newbie that can't even maximize a quadra...

Maple 2016

So I needed a CAS, and I spent a couple of months trying to get a basic understanding of SymPy and various applications starting with "M". We have Maple version 2016.

My "prototype problem" can be solved by hand, and is a system of quadratic Bellman equations, for i=1,2.  I'll return to it below, as I am obviously too clumsy to get even the second-to-simplest max/min working.  Oh, and I can't even insert Maple Math here in the forum, it does not like maximize or minimize.

Let's start easy. I enter
maximize((b-x)x,x)
which works as I expect. Then already at
maximize((abs(b)-x)x,x>=0)
I am stuck. Please, sweet Maple, you know that the answer is the same as before, don't you? (In the meantime I have tried to feed it maximize((b-x)x,x=0..1)... )

I was hoping my "proper" problem should be doable. What I really need is a sequence of quadratic optimization problems, where I have a vector x maximizing b'x-x'Ax subject to linear constraints, so it should not be too hard.  The "prototype problem" I needed for starters, is a system where for i=1,2 I have

v_i(0,y)=0 and inductively v_i(t+1,y)=max{x_i*(b_i-x_1-x_2)+ r_i v_i(t,y-x)}

where b_i and r_i are constants, x=(x_1,x_2), y=(y_1,y_2), and everything is nonnegative - including, the choice variables x_i must be between 0 and min{y_i, b_i-x_1-x_2}. And I want to plot both functions and the x with time as a slider, but ... I don't think I'll ever get that far?

Sorry for whining. (I know why I dropped out of computer science.)

 Page 1 of 1
﻿