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

采纳的回答

Robert
Robert 2016-11-18
编辑:Robert 2016-11-18
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.
  1 个评论
Karan Gill
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
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".

Robert
Robert 2016-11-18
Hi Steven,
Thank you for the reply. I suppose that this function essentially does the same as checking whether aa(1)+aa(2)=0 holds or not? The reason that I tried the "aa(1)+aa(2)"-command was because I could verify that I indeed got zero from another equation which was giving me one root being equal to the negative of the other, the only difference is that the equation that I mentioned above is that it has much longer symbolic expressions for the solutions. However, if I run the command that you mentioned I get the following warning: "Warning: symbolic:sym:isAlways:TruthUnknown"
followed by 0. Given the warning I suppose that it isn't conclusive that it isn't true and that the roots might be the same apart from an overall minus sign?
  1 个评论
Karan Gill
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
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)
  1 个评论
Robert
Robert 2016-11-19
Hi Walter,
Thank you for sharing, I'll keep this in mind if I run in to a similar situation in the future :)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by