0
$\begingroup$

I have no trouble finding stationary points using diff and solve in the following way:

f:= somefunction;  dx:=diff(f,x);  evalf(solve(dx=0)); 

which gives me an approximation for the stationary points; however, if I wanted the stationary points between 1..4, for example, how do I specify that? I tried evalf(solve(dx=0, 1..4)); but I get an error saying "too many and/or wrong type of arguments...". Also, if I wanted to include a range too, so I was looking for stationary points within a square field, how do I accomplish that?

1 Answers 1

2

You can try including inequalities in the solve command. This should work if your $f$ is a rational function. For example:

solve({x^3 - 3*x + 2 = 0, x >= 0, x <= 3});

$\{x = 1\}$

It's rather iffy for transcendental functions, especially since they might not have closed-form solutions.

On the other hand, you can use fsolve to get a numerical approximation to a solution. For example:

fsolve(x^3 - 4*sin(x) + 2 = 0, x = 0 .. 2);

$1.200054459$

For a system of equations (I suspect that's what you mean by "stationary points within a square field") you can also use fsolve, e.g.

fsolve({ 3*x + 4*y = 8, sin(x) + sin(y) = 1}, {x,y}, x=0 .. 3, y=0 .. 3);

$\{x = 2.312379302, y = .2657155233\}$

This will only give you one solution. On the other hand, for a polynomial system you can try RootFinding[Isolate] which will give you all solutions in a given rectangle. For example:

RootFinding[Isolate]({ 3*x + 4*y - 8, (x-2)^2 + (y-2)^2 - 2}, [x,y],x=0 .. 3, y=0 .. 3);

$[[x = 1.878665182, y = .5910011136], [x = .6813348181, y = 1.488998886]]$