[Date Index]
[Thread Index]
[Author Index]
Re: Simple, syntactical question
*To*: mathgroup at smc.vnet.net
*Subject*: [mg48171] Re: [mg48152] Simple, syntactical question
*From*: Andrzej Kozlowski <akoz at mimuw.edu.pl>
*Date*: Sat, 15 May 2004 03:56:30 -0400 (EDT)
*References*: <200405150059.UAA21815@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
On 15 May 2004, at 09:59, Olaf Skjaraasen wrote:
> Hi all,
>
> my problem is a simple one, but please bear with me: Assume a function
> f(x) whose x-dependence is different for different parts of the x-axis;
> e.g.,
> f[x_] := If[x<0,x^2, x^2 + Cos[x]];
>
> I would like Mathematica to do the following: Given values y0,
> x0, find x such that f[x]=y0, subject to the condition x>x0.
>
> What is the syntax to be used to tell Mathematica to restrict itself to
> x>x0 when solving the equation, whether with Solve, NSolve, FindRoot or
> DSolve?
>
> Cheers,
> Olaf
>
>
>
Probably the best way is to use NMinimize. Since you do not provide
any numerical data I have to make up my own. Suppose x0=-1 and y0 = 0.1
So we define:
f[x_]:=If[x<0,x^2,x^2+Cos[x]];
x0=-1;
y0=0.1;
Now we minimise and use Chop to get rid of tiny numerical quantities:
NMinimize[{Abs[f[x]-y0],x>x0},x]//Chop
Out[4]=
{0,{x->-0.316228}}
We check the answer:
f[x]/.%[[2]]
0.1
So we have a solution.
Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/
Prev by Date:
**Re: Mean**
Next by Date:
**Re: Mean**
Previous by thread:
**Simple, syntactical question**
Next by thread:
**setdirectory doesn't work.anymore**
| |