mkonto

25 Reputation

5 Badges

8 years, 319 days

MaplePrimes Activity


These are questions asked by mkonto

I am using solve() to give me a two variable solutions (e.g. a = 3, b = 5). Very often, I have 2 solutions, so the output will be something like {a = .8025072621, b = -.8025072621}, {a = 1.326426441, b = 1.326426441}. I store this output in a matrix called Answers, so that looks like:

Answers:= solve(equation that needs solving). 

Later when I want to access these answers, I'll do Answers[1][1] to get the first a, and Answers[1][2] to get the first b. Overwhelmingly this all works fine, but occassionaly Answers only has one set of solutions, so Answers[1][1] becomes meaningless, for example, if solve() returned {a = 3, b = 4}, then Answers[1] just returns a, and Answers[2] returns b, but Answers[1][1] gives an error. As I cannot predict when solve() will give me one solutions as opposed to 2, how can I write code to reliably access the first solution for use later?

1 2 Page 2 of 2