Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #12210 > unrolled thread
| Started by | Neal Becker <ndbecker2@gmail.com> |
|---|---|
| First post | 2012-11-01 07:19 +0000 |
| Last post | 2012-11-02 05:11 +0000 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
[newb] simple equation substitutions Neal Becker <ndbecker2@gmail.com> - 2012-11-01 07:19 +0000
Re: [newb] simple equation substitutions "Nasser M. Abbasi" <nma@12000.org> - 2012-11-02 04:45 +0000
Re: [newb] simple equation substitutions Peter Breitfeld <phbrf@t-online.de> - 2012-11-02 05:11 +0000
Re: [newb] simple equation substitutions p-crossbow <goramedforsiktigt@gmail.com> - 2012-11-02 05:11 +0000
| From | Neal Becker <ndbecker2@gmail.com> |
|---|---|
| Date | 2012-11-01 07:19 +0000 |
| Subject | [newb] simple equation substitutions |
| Message-ID | <k6t7qk$1mi$1@smc.vnet.net> |
{y == x + 2, x == 7}
Solve[%, y]
-> {}
What I expected to happen is have x->7 applied to y == x+2.
My real plan is to develop a list of (a lot more complicated) expressions that will have repeated substitutions applied.
Why didn't the above work and/or what should I do instead?
[toc] | [next] | [standalone]
| From | "Nasser M. Abbasi" <nma@12000.org> |
|---|---|
| Date | 2012-11-02 04:45 +0000 |
| Message-ID | <k6vj4k$6ad$1@smc.vnet.net> |
| In reply to | #12210 |
On 11/1/2012 2:19 AM, Neal Becker wrote:
> {y == x + 2, x == 7}
>
> Solve[%, y]
>
> -> {}
>
> What I expected to happen is have x->7 applied to y == x+2.
>
> My real plan is to develop a list of (a lot more complicated)
>expressions that will have repeated substitutions applied.
>
> Why didn't the above work and/or what should I do instead?
>
Solve wants you to list _all_ the variables.
-----------------------
In[4]:= {y==x+2,x==7};
Solve[%,{y,x}]
Out[5]= {{y->9,x->7}}
------------------------
--Nasser
[toc] | [prev] | [next] | [standalone]
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Date | 2012-11-02 05:11 +0000 |
| Message-ID | <k6vklj$6ie$1@smc.vnet.net> |
| In reply to | #12210 |
There are several possibilities:
expr = {y == x + 2, x == 7};
Solve[expr, {x, y}]
Reduce[expr]
Eliminate[expr, x]
giving:
{{x -> 7, y -> 9}}
y == 9 && x == 7
y == 9
--
_________________________________________________________________
Peter Breitfeld | Bad Saulgau, Germany | http://www.pBreitfeld.de
[toc] | [prev] | [next] | [standalone]
| From | p-crossbow <goramedforsiktigt@gmail.com> |
|---|---|
| Date | 2012-11-02 05:11 +0000 |
| Message-ID | <k6vkm7$6il$1@smc.vnet.net> |
| In reply to | #12210 |
You would have to use Solve[%,{x,y}] to get the answer you're looking for. My best understanding of this is that Mathematica sees a system of equations with two unknowns - x & y despite the fact that the solution for x is trivial. As such, Solve[] requires both unknowns specified as solve variables in order to return a result that isn't full dimensional.
When you know the value for a variable, as in the case above, it is simpler if you perform a substitution rather than creating another equation for Solve[] to wrestle with.
{y==x+2}/.{x->7}
Solve[%, y]
If you would rather post-process your equations to perform this substitution, one way to do this could be:
eqns={y==x+2,x==7};
eqns/.(Cases[eqns,_Symbol==_Integer]/.{(u_Symbol==v_Integer)->(u->v})
I've assumed above that the RHS is always an integer in my pattern, but this can be adjusted "to taste". I'm sure there are more elegant ways of doing this, and perhaps some of the fine people here can help there.
Le jeudi 1 novembre 2012 00:21:48 UTC-7, Neal Becker a =E9crit :
> {y == x + 2, x == 7}
>
>
>
> Solve[%, y]
>
>
>
> -> {}
>
>
>
> What I expected to happen is have x->7 applied to y == x+2.
>
>
>
> My real plan is to develop a list of (a lot more complicated) expressions that will have repeated substitutions applied.
>
>
>
> Why didn't the above work and/or what should I do instead?
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web