# use solution of solve (symbolic)

5 messages
Open this post in threaded view
|

## use solution of solve (symbolic)

 Hello, I must me missing something obvious, but can't find a simple solution: I have two symbolic variables (a,b) and two other variables depending on them (dbl_a, dbl_b). I solve two equations, which I can solve for a and b. How do I "substitute" those solutions into the depending variables, so I can see what their values are? pkg load symbolic syms a b dbl_a=2*a dbl_b=2*b eq1=dbl_a==9 eq2=dbl_b==10 solution=solve([eq1 eq2],[a b]) a=solution.a b=solution.b vpa(dbl_a) vpa(dbl_b) When I run this, I get: a = (sym) 9/2 b = (sym) 5 ans = (sym) 2.0*a ans = (sym) 2.0*b But I need the last two lines to return "9" and "10", to inspect the values. I allready tried to use "subs", without succes.... Of course, I can change the last two lines to "vpa(dbl_a=2*a)" and "vpa(dbl_b=2*b)", but actually my calculations and equations are a lot more complex, this is a MWE Many thanks for any help, Stef -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html
Open this post in threaded view
|

## Re: use solution of solve (symbolic)

 On Wed, Mar 27, 2019 at 4:58 PM Stef Pillaert <[hidden email]> wrote:Hello, I must me missing something obvious, but can't find a simple solution: I have two symbolic variables (a,b) and two other variables depending on them (dbl_a, dbl_b). I solve two equations, which I can solve for a and b. How do I "substitute" those solutions into the depending variables, so I can see what their values are? pkg load symbolic syms a b dbl_a=2*a dbl_b=2*b eq1=dbl_a==9 eq2=dbl_b==10 solution=solve([eq1 eq2],[a b]) a=solution.a b=solution.b vpa(dbl_a) vpa(dbl_b) here is one waysolution=solve([eq1 eq2],[a b])a1=solution.ab1=solution.bdouble(subs(dbl_a,a,a1))double(subs(dbl_b,b,b1))  When I run this, I get: a = (sym) 9/2 b = (sym) 5 ans = (sym) 2.0*a ans = (sym) 2.0*b But I need the last two lines to return "9" and "10", to inspect the values. I allready tried to use "subs", without succes.... Of course, I can change the last two lines to "vpa(dbl_a=2*a)" and "vpa(dbl_b=2*b)", but actually my calculations and equations are a lot more complex, this is a MWE Many thanks for any help, Stef -- Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html -- DAS
Open this post in threaded view
|

## Re: use solution of solve (symbolic)

 On 2019-03-27 6:21 p.m., Doug Stewart wrote: > here is one way > > solution=solve([eq1 eq2],[a b]) > a1=solution.a > b1=solution.b > double(subs(dbl_a,a,a1)) > double(subs(dbl_b,b,b1)) I agree with Doug. In the *next* version of Symbolic (2.8.0, not out yet) you will also be able to use subs and/or eval to shortcut this a little bit: syms a b dbl_a=2*a dbl_b=2*b eq1=dbl_a==9 eq2=dbl_b==10 solution=solve([eq1 eq2],[a b]) a = solution.a b = solution.b eval(dbl_a) eval(dbl_b) The eval command will search your workspace for variables whose names match the symbols a and b. Note: IMHO, this sort of thing might be nice for interactive command-line usage, but Doug's approach is better for code. Colin