How can I use assumptions with FindRoot[] in Mathematica? - wolfram-mathematica

In Mathematica I have something like
FindRoot[f[x], {x, a}]
Now I want FindRoot to constrain the solutions to 0 < x < 1.
How can I obtain this?
Thanks

There is a four-parameter option for this function: FindRoot[f[x],{x,xstart,xmin,xmax}] which stops the search if the search ventures outside of the interval [xmin,xmax].

Related

Using Unit Triangle to make a triangle with and an area of 1

I want to create a function that returns a triangle with an area of 1 when plotted. I'd like to use the "UnitTriangle" function to do so.
I've tried multiplying "UnitTriangle" by 2(1/x), multiplying it by 2(1/(Max[x]-Min[x]), and multiplying by Total[x] but none return what I'm looking for.
Triangle[x_] := (2*(1/x))*UnitTriangle[x];
Plot[Triangle[x], {x, -2, 2} , PlotRange -> All]
I understand why this isn't working as I'd like (it's evaluating for each x input), but I don't know how to find the base of the triangle from the input list I provide when I plot it.
Any thoughts?
Thanks for your help in advance!!
Try this
unitAreaTriangle[w_]:=(
triangle[x_]:=Piecewise[{
{ 4/w^2*x+2/w,-w/2<=x<0},
{-4/w^2*x+2/w, 0<=x<=w/2},
{0,True}}];
Plot[triangle[x],{x,-w,w},PlotRange->All]);
unitAreaTriangle[2]
or
plotUnitAreaTriangle[w_]:=Plot[
Piecewise[{
{ 4/w^2*x+2/w,-w/2<=x<0},
{-4/w^2*x+2/w, 0<=x<=w/2},
{0,True}}],
{x,-w,w},PlotRange->All];
plotUnitAreaTriangle[2]

Why is an empty list returned when solving for this linear system in Maxima?

I'm trying to solve a simple linear system in Maxima using solve like so:
/*Standard form*/
eq1 : x1 + 3*x2 + s1 = 6;
eq2 : 3*x1 + 2*x2 + s2 = 6;
base1 : solve([eq1,eq2],[s1,s2]);
This however returns an empty list and I don't know why. Any ideas? I'm pretty sure the system has a solution, so that shouldn't be the issue.
EDIT:
I attempted to insert the equations explicitly into solve in place of eq1 and eq2, and now it works. Now the question is, why do I need to explicitly insert the equations to be solved for into the first argument of solve. An in-depth answer about how Maxima works in this case would be welcome.
This happened to me when one of the variables in the equation was previously defined.
E.g., if z was previously defined:
Then simply changing z to, e.g., p returns the solutions:

Define a pdf with a unique non-null value in mathematica

I'd like to define a pdf such as:
g(x):P(x=0)=1. and P(x!=0)=0.
i.e. a pdf where the only non-zero probability occurs when x=0. Any ideas? Thanks
Piecewise is a useful tool for these cases:
g[x_] := Piecewise[{{1, x == 0}}, 0]
The above should do the job for you.
Note:
DiracDelta[0]=infinity ; which is obviously not equal to 1.

matrix manipulation SciLab

I heard there was some way to change matrix values without using the FOR loop. For example:
A = [1 2; 3 4]
There is suppose to be a way I can make all the values for example less than 4 and changed them to some other value, let's say zero. Something like this:
A(...<4...)=0
And the answer should be:
ans =
0. 0.
0. 4.
Anyone know the syntax for this?
You don't really need to use find for this; you can simply use indexing instead :
A(A>=4) = 0;
you can do:
A(find(A<4))=0;

Assist "Solve[]" by Providing Variable Ranges

I am trying to solve a system of equations (5 unknown variables, 5 equations) but the Solve[] function just hangs and I have to abort the evaluation. I can understand as some of the equations are quite messy-- in my opinion at least (I'm not a mathematician).
I checked the equations used in Solve[] by substituting in "known/true" simulation values and they all work out.
So, my question is this: Is it possible to "help" Solve[] by saying, for example...
Solve[{eq1, eq2, eq3, eq4, eq5},{var1, var2, var3, var4, var5}, (*code here along the lines of { 0 < var1 < 10, var2 < 25, ...}*)]
I can provide more information if it would be of assistance.
Thanks!
The program Mathematica provides actually very simple solution inside the function Solve[].
You can add all kind of desired conditions as inequalities ConditionOnVar1, ConditionOnVar1:
Solve[{Eq1, Eq2, ConditionOnVar1, ConditionOnVar2},{Var1, Var2}]
Trivial 1D Example
Solve[Cos[theta]==1 && theta >= 0 && theta < 2\[Pi], theta]

Resources