Re: My problem when solving a system of equations

• To: mathgroup at smc.vnet.net
• Subject: [mg78061] Re: My problem when solving a system of equations
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Fri, 22 Jun 2007 06:35:42 -0400 (EDT)
• Organization: The Open University, Milton Keynes, UK
• References: <f5dkv7\$13j\$1@smc.vnet.net>

```loveinla at gmail.com wrote:
> Hi, guys,
>
> I was trying to solve a system of nonlinear equations. However,
> whenever I run it, Mathematica always returns:
> " ReplaceAll::reps: {-0.04\(-24 + 5\pA)\((25 - 4\p1)\(-2 + p1) - (24 -
> \
> 5\pA)\(-3 + pA) + (-3 - disA + pA)\(24 - 5\(-disA + pA))) + 0.4\(\
> \[LeftSkeleton]1\[RightSkeleton])\(\[LeftSkeleton]1\[RightSkeleton])
> == 0, \
> \[LeftSkeleton]3\[RightSkeleton]} is neither a list of replacement
> rules nor \
> a valid dispatch table, and so cannot be used for replacing. "
>
> I don't know what this means and how to deal with it.
>
> Below is my code for your reference:
>
> a = 24;
> b = 5;
> c = 25;
> d = 4;
> cA = 3;
> cB = 2;
> t = 5;
> alpha = 0;
> bta = 0.6;
> NB = NSolve[{-d(p - cB) + c - d*p == (p - cB)(c - d*p)^2/t}, {p}];
> SNB = DeleteCases[NB, {p -> _Complex}]
> B = NSolve[{(alpha + (1 - alpha - bta)*(0.5 - ((d/
>           2)*(p1^2 - p2^2) - c*(p1 - p2))/(2t) - ((b/2)*((
>       pA - disA)^2 - pA^2) + a*disA)/(2t)))*(a - b*pA - b*(pA -
>     cA)) - (1 - alpha - bta)*((p1 - cB)*(c - d*
>     p1) + (pA - disA - cA)*(a - b*(pA -
>                    disA)) - (pA - cA)*(a - b*pA))*(-(
>                     a - b*pA)/(
>                         2t)) == 0, (1 - alpha - bta)*((a - b*(pA -
> disA) -
>                                b(pA - disA - cA))*(0.5 + ((d/2)*(
>                         p1^2 - p2^2) - c*(
>                                 p1 - p2))/(2t) + ((b/2)*((pA -
>                                     disA)^2 - pA^2) + a*disA)/(2t)) +
> ((
>                           p1 - cB)*(c -
>               d*p1) + (pA - disA - cA)(a - b*(pA - disA)) - (pA -
>             cA)(a - b*pA))*(-(a - b*(pA - disA))/(
>               2t))) == 0, (1 - alpha)*((c - d*p1 - d*(p1 -
>                   cB))*(0.5 + ((d/2)*(p1^2 - p2^2) - c*(p1 -
>                         p2))/(2t)) + (p1 - cB)*(c - d*p1)*(-
>                   c + d*p1)/(2t)) + (1 -
>                      alpha - bta)*(((pA - disA - cA)*(a -
>
>                   b*(pA - disA)) - (pA - cA)*(a - b*
>         pA))*(-c + d*p1)/(2t) + (c - d*p1 - d(
>             p1 - cB))*((
>                       b/2)((pA - disA)^2 - pA^2) + a*disA)/(2t)) ==
>                           0, (1 - alpha)*((c - d*p2 - d(p2 - cB))*(
>         0.5 - ((d/
>                   2)*(p1^2 - p2^2) - c*(p1 - p2))/(2t)) + (
>                         p2 - cB)*(c - d*p2)*(-c + d*p2)/(
>                         2t)) - (1 - alpha - bta)*(c - d*p2 - d(p2 -
> cB))*((
>                               b/2)*((pA - disA)^2 - pA^2) + a*disA)/(
>                   2t) == 0}, {pA, p1, p2, disA}];
> BR = DeleteCases[B, {pA -> _Complex, p1 -> _Complex,
>              p2 -> _Complex, disA -> _Complex}];
> SB = Select[BR, And @@ (({pA > 0, p1 > 0, p2 >
>                0, disA > 0, pA - disA > 0} /. #)) &]
>
>

You should try the above code with a fresh session of Mathematica (it
works fine on my system; see below); however since all your variables,
parameters, constants, etx are define globaly, I am rather condident
that some of the name clashed after few attempts. You should have a
look, and use, constructs such as *With* and *Module*.

In[1]:= a = 24;
b = 5;
c = 25;
d = 4;
cA = 3;
cB = 2;
t = 5;
alpha = 0;
bta = 0.6;
NB = NSolve[{(-d)*(p - cB) + c - d*p == (p - cB)*((c - d*p)^2/t)},
{p}];
SNB = DeleteCases[NB, {p -> _Complex}]
{{p -> 2.292510833366451}}
B = NSolve[
{(alpha + (1 - alpha - bta)*(0.5 - ((d/2)*(p1^2 - p2^2) -
c*(p1 - p2))/(2*
t) - ((b/2)*((pA - disA)^2 - pA^2) +
a*disA)/(2*t)))*(a - b*pA -
b*(pA - cA)) -
(1 - alpha -
bta)*((p1 - cB)*(c - d*p1) + (pA - disA - cA)*
(a - b*(pA - disA)) - (pA - cA)*(a - b*pA))*
(-(a - b*pA)/(2*t)) == 0,
(1 - alpha - bta)*((a - b*(pA - disA) - b*(pA - disA - cA))*
(0.5 + ((d/2)*(p1^2 - p2^2) - c*(p1 - p2))/(2*t) +
((b/2)*((pA - disA)^2 - pA^2) + a*disA)/(2*
t)) +
((p1 - cB)*(c - d*p1) + (pA - disA - cA)*(a -
b*(pA - disA)) -
(pA - cA)*(a - b*pA))*(-(a - b*(pA - disA))/(2*
t))) == 0,
(1 - alpha)*((c - d*p1 - d*(p1 - cB))*
(0.5 + ((d/2)*(p1^2 - p2^2) - c*(p1 - p2))/(2*
t)) +
(p1 - cB)*(c - d*p1)*((-c + d*p1)/(2*t))) +
(1 - alpha -
bta)*(((pA - disA - cA)*(a - b*(pA - disA)) -
(pA - cA)*(a - b*pA))*((-c + d*p1)/(2*t)) +
(c - d*p1 -
d*(p1 - cB))*(((b/2)*((pA - disA)^2 - pA^2) +
a*disA)/(2*t))) == 0,
(1 - alpha)*((c - d*p2 - d*(p2 - cB))*
(0.5 - ((d/2)*(p1^2 - p2^2) - c*(p1 - p2))/(2*
t)) +
(p2 - cB)*(c - d*p2)*((-c + d*p2)/(2*t))) -
(1 - alpha - bta)*(c - d*p2 - d*(p2 - cB))*
(((b/2)*((pA - disA)^2 - pA^2) + a*disA)/(2*t)) ==
0},
{pA, p1, p2, disA}];
BR = DeleteCases[B, {pA -> _Complex, p1 -> _Complex, p2 -> _Complex,
disA -> _Complex}];
SB = Select[BR, And @@ ({pA > 0, p1 > 0, p2 > 0, disA > 0,
pA - disA > 0} /. #1) & ]

Out[11]= {{p -> 2.292510833366451}}

Out[12]= {{p -> 2.292510833366451}}

Out[15]= {{pA -> 4.445374169873915, p1 -> 2.319154459353897,
p2 -> 2.253920244654226, disA -> 0.9966066375970366},
{pA -> 3.9732432024842192, p1 -> 4.958302022957722,
p2 -> 2.9492043120806235, disA -> 1.7317345079613626}}

Regards,
Jean-Marc

```

• Prev by Date: Re: is there a better way to iterate this?
• Next by Date: Re: Re: Integrate modified in version 6?
• Previous by thread: Re: My problem when solving a system of equations
• Next by thread: Re: My problem when solving a system of equations