I am developing quite an involved bit of code (for me) that is not finding solutions with Solve when it should. The relevant part of the code is
ky = 0.6;
width = 10.1;
(*...monolith of code that generates s1, s2 and s3...*)
c1 = (s1 == s2) /. x -> 0;
c2 = D[s1 == s2, x] /. x -> 0;
c3 = (s2 == s3) /. x -> width;
c4 = D[s2 == s3, x] /. x -> width;
Solve[c1 && c2 && c3 && c4]
(*{}*)
where s1
, s2
and s3
are lists with length 2 generated in the rest of the code (omitted here for simplicity/compactness), an example of which will be provided below. I expect solutions to exist for ky
between -1 and 1 but the code failed to find solutions for some values such as ky=0.6
.
I therefore attempted to split the Solve process up into a couple of steps and changed the last line in the code to:
{c3, c4} = {c3, c4} /. Solve[c1 && c2] // Flatten;
Solve[c3 && c4]
(*{{r1 -> -0.504095 - 0.823378 I,....and other solutions...}}*)
Hurrah it works. However this code still fails for other values such as ky=0.7
when there should be solutions. How can I improve this code so it always finds solutions when it should? For testing I provide the output from the rest of the code for ky=0.7
(sorry it's messy)
{s1, s2, s3}=
{{(-0.299481 + 0.640556 I) E^(
I (1.1 x + 0.7 y)) - (0.299481 + 0.640556 I) E^(
I (-1.1 x + 0.7 y)) r1 +
0.941558 E^(I ((0. - 1.47986 I) x + 0.7 y))
rIm1, (0.707107 + 0. I) E^(
I (1.1 x + 0.7 y)) + (0.707107 + 0. I) E^(I (-1.1 x + 0.7 y))
r1 + 0.33685 E^(I ((0. - 1.47986 I) x + 0.7 y))
rIm1}, {(0.497117 + 0.502866 I) b1 E^(I (-1.67631 x + 0.7 y)) -
0.904655 b4 E^(I ((0. - 1.94679 I) x + 0.7 y)) -
0.426145 b3 E^(
I ((0. + 1.94679 I) x + 0.7 y)) + (0.497117 - 0.502866 I) b2 E^(
I (1.67631 x + 0.7 y)), (0.707107 + 0. I) b1 E^(
I (-1.67631 x + 0.7 y)) +
0.426145 b4 E^(I ((0. - 1.94679 I) x + 0.7 y)) +
0.904655 b3 E^(
I ((0. + 1.94679 I) x + 0.7 y)) + (0.707107 + 0. I) b2 E^(
I (1.67631 x + 0.7 y))}, {(-0.299481 + 0.640556 I) E^(
I (1.1 x + 0.7 y)) t1 +
0.33685 E^(I ((0. + 1.47986 I) x + 0.7 y))
tIm1, (0.707107 + 0. I) E^(I (1.1 x + 0.7 y)) t1 +
0.941558 E^(I ((0. + 1.47986 I) x + 0.7 y)) tIm1}}
I hope this is an acceptable question, I post with caution (see here).
ky=0.70001
. $\endgroup$ – Sumit Jun 27 '16 at 13:43{s1,s2,s3}
$\endgroup$ – Feyre Jun 27 '16 at 13:52[c1&&c2&&c3&&c4]
and[c3&&c4]
respectively{{b1 -> 0.551683 - 0.197769 I, b2 -> 0.163159 - 0.453896 I, b3 -> 0.29314 - 0.549955 I, b4 -> -1.81831*10^-10 + 9.53055*10^-10 I, r1 -> -0.336636 - 0.847225 I, rIm1 -> 0.895327 - 1.06646 I, t1 -> -0.245692 + 0.329425 I, tIm1 -> -1.91242*10^6 + 1.17446*10^6 I}}
{{b1 -> 0.551683 - 0.197769 I, b2 -> 0.163159 - 0.453897 I, t1 -> -0.245692 + 0.329425 I, tIm1 -> -1.91242*10^6 + 1.17446*10^6 I}}
$\endgroup$ – Feyre Jun 27 '16 at 14:01