I copied the solutions into mathematica and went through all the terms (which is a lot easier since you can display the equations in a "pretty-format" easier to visualize than the one in MATLAB), and then I finally saw that there's a sign difference before a square-root, so they are not the same. However, the square root cannot really be distinguished in the output I got from using the pretty-function in MATLAB...so for future reference I'll keep in mind that it's better to use mathematica to evaluate (or at least visualize) long symbolic expressions than MATLAB.
Inconsistent solution from a symbolic equation?
1 view (last 30 days)
Show older comments
Hi,
I'm solving a system of some rather lengthy equations using the solve function after setting up the equations using symbols. Solving one of the equations gives me two solutions, let's denote it like this:
aa=solve(eq3_2==0,N3);
Now if I look at the two solution in "aa", they look the same apart from an overall negative sign..however, since they are very long I wanted to make sure if one was just the negative of the other, so I wrote:
aa(1)+aa(2)
and was expecting to get 0, which I didn't get. To try to spot what made them different i used the pretty-function like:
pretty(solve(eq3_2==0,N3))
which gave me the following output:
[[(#58 + #28 + #55 + #54 + #53 - #52 + #11 - #10 + #9 - #8 + #7 + #6 + #5 + #4 - #3 - #2
+ #24 + #57 - #56 + #33 - #32 - #31 + #30 - #29 + #27 + #26 - #25 + #23 + #22 - #21
- #20 - #19 - #18 + #17 + #16 + #15 - #14 - #13 - #12 - #37 - #36 + #35 - #34 + #51
+ #50 - #49 - #48 - #47 - #46 - #45 + #44 + #43 + #42 + #41 - #40 - #39 - #38)/#1],
[-(#58 - #28 - #55 - #54 - #53 + #52 - #11 + #10 - #9 + #8 - #7 - #6 - #5 - #4 + #3 + #2
- #24 - #57 + #56 - #33 + #32 + #31 - #30 + #29 - #27 - #26 + #25 - #23 - #22 + #21
+ #20 + #19 + #18 - #17 - #16 - #15 + #14 + #13 + #12 + #37 + #36 - #35 + #34 - #51
- #50 + #49 + #48 + #47 + #46 + #45 - #44 - #43 - #42 - #41 + #40 + #39 + #38)/#1]]
and a list with the expression for each number. Just comparing what I got from this, they do seem to be the same apart from an overall negative sign. So my question is if I'm missing something or if this might be a bug caused by too lengthy symbolic expressions or something like that?
Thanks in advance
Robert
0 Comments
Accepted Answer
Robert
on 18 Nov 2016
Edited: Robert
on 18 Nov 2016
1 Comment
Karan Gill
on 18 Nov 2016
Edited: Karan Gill
on 18 Nov 2016
For the record, you get "pretty format" using the Live Editor in MATLAB now: https://www.mathworks.com/products/matlab/live-editor/ . Oh, if you need to follow up to your question, you can also edit your question or comment on it instead of adding answer.
More Answers (3)
Steven Lord
on 17 Nov 2016
What does:
isAlways(aa(1) == -aa(2))
return? The isAlways function tells you "whether equation or inequality holds for all values of its variables".
0 Comments
Robert
on 18 Nov 2016
1 Comment
Karan Gill
on 18 Nov 2016
The warning means that the input condition could not be proved or disproved for all possible values of the inputs.
Walter Roberson
on 18 Nov 2016
One approach you might take in future, which applies for sums and products:
aa1ch = children(aa(1));
aa2ch = children(-aa(2));
tf = ismember(aa1ch, aa2ch);
non_matching_aa1 = aa1ch(~tf);
then non_matching_aa1 are the terms in aa(1) that do not have a match in -aa(2)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!