Ask Your Question
0

Solving systems of equations always returns [ ]

asked 10 years ago

Evidlo gravatar image

updated 10 years ago

FrédéricC gravatar image

Suppose I have the set of equations and I'm trying to solve for f1, f2 and f3:

formula

I've tried solving it in the following way

eq1 = f1 == a + b + f2
eq2 = 2*f2 == c + d + f1
eq3 = f3 == f1 + f2
solve([eq1,eq2,eq3],f1,f2,f3)
[]

This is easy to solve using matrices, and I have double-checked that the answer is fully constrained, so why does sage always return [ ]? I would have expected answers for f1, f2 and f3 in terms of a, b , c and d. Is there another argument to solve() that tells Sage what I want my answer in terms of?

I would prefer to use solve() instead of matrices both for the sake of convenience and if I have a nonlinear system later on.

Preview: (hide)

Comments

That's odd. I used your code and got:

[[f1 == 2*a + 2*b + c + d, f2 == a + b + c + d, f3 == 3*a + 3*b + 2*c + 2*d]]
calc314 gravatar imagecalc314 ( 10 years ago )

2 Answers

Sort by » oldest newest most voted
0

answered 7 years ago

It seems defining the variables as variables would solve the problem.

f1,f2,f3,a,b,c,d = var('f1,f2,f3,a,b,c,d');
eq1 = f1 == a + b + f2;
eq2 = 2*f2 == c + d + f1;
eq3 = f3 == f1 + f2;
solve([eq1,eq2,eq3],f1,f2,f3);

This would give the answer @cacl314 mentioned

Preview: (hide)
link
0

answered 10 years ago

Evidlo gravatar image

updated 10 years ago

I realize now that when I was testing this, I was only doing

solve([eq1,eq2,eq3],f1)
[]

because I was only interested in the solution to f1. However this leaves f2 and f3 as free variables and so there are multiple ways to express your answer.

This makes me wonder if I can directly tell Sage to solve for f1 in terms of a, b ,c ,d.
For example, this seems like a more natural expression.

solve([eq1,eq2,eq3],f1,in_terms_of=[a,b,c,d])
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 10 years ago

Seen: 486 times

Last updated: Dec 04 '14