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 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Robert
2016-11-18
编辑:Robert
2016-11-18
1 个评论
Karan Gill
2016-11-18
编辑:Karan Gill
2016-11-18
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.
更多回答(3 个)
Steven Lord
2016-11-17
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 个评论
Robert
2016-11-18
1 个评论
Karan Gill
2016-11-18
The warning means that the input condition could not be proved or disproved for all possible values of the inputs.
Walter Roberson
2016-11-18
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!