Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare a variable to be a positive real number in maxima?

Tags:

maxima

I have the following maxima code:

declare(p, real)$
declare(q, real)$
declare(m, real)$
is(-(4*p^2*q^2)/m^2-(4*p^4)/m^2  < 0);

This evaluates to unknown. Can I declare that p,q and m are positive real numbers?

like image 978
Kasper Avatar asked Oct 23 '17 08:10

Kasper


People also ask

How do we declare a function in Maxima?

To define a function in Maxima you use the := operator. E.g. would return a list with 1 added to each term. f(x) := (expr1, expr2, ...., exprn);

How do you define a constant in Maxima?

An expression is considered a constant expression if its arguments are numbers (including rational numbers, as displayed with /R/ ), symbolic constants such as %pi , %e , and %i , variables bound to a constant or declared constant by declare , or functions whose arguments are constant.

How do you write pi in Maxima?

If you want to refer to the immediately preceding result computed by Maxima, you can either use its o label, or you can use the special symbol percent (%). The standard quantities e (natural log base), i (square root of −1) and π (3.14159…) are respectively referred to as %e, %i, and %pi.


Video Answer


1 Answers

Short answer to the question

Putting @Michael O.'s comment into the form of an answer:

The assume function can be used to set predicates on variables, in particular to tell maxima that a number is positive (this is also useful for calculating some integrals with integrate)

assume(p>0,q>0,m>0);
is(-(4*p^2*q^2)/m^2-(4*p^4)/m^2  < 0);

Some more functions for managing predicates

The list of predicates can be displayed using the facts function and removed using the forget function

kill(all); /*Clears many things, including facts*/
assume(a>0,b>0,c>0)$ /*Learn facts*/
facts();
forget(b>0)$ /*Forget one fact*/
facts();
forget(facts())$ /*Forget all known facts*/
facts();

Example of usage of assume with integrate function

Some mathematical results depends on e.g. the sign of some parameters. In particular, it is the case of some integrals.

(%i0) print("Without predicates: Maxima prompts the user")$
      kill(all)$
      L : sqrt(1 - 1/(R^2))$
      facts();
      integrate(x,x,0,L);

      print("With predicates: Maxima does not need to prompt the user because it already knows the answer")$
      kill(all)$
      assume(R>0)$
      L : sqrt(1 - 1/(R^2))$
      facts();
      integrate(x,x,0,L);

Without predicates: Maxima prompts the user
(%o0) []
Is "R" positive or negative? positive;
(%o1) (R^2-1)/(2*R^2)
With predicates: Maxima does not need to prompt the user because it already knows the answer
(%o2) [R>0]
(%o3) (R^2-1)/(2*R^2)
like image 100
Gael Lorieul Avatar answered Sep 27 '22 18:09

Gael Lorieul