如何用mathematica得到方程组的实数根?
方程如下:NSolve[{x^2 + y^3 == 1, x^4 + y^4 == 2}, {x, y}]
得到的结果如下
{{x -> -0.428653 + 1.42567 I,
y -> -0.552329 - 1.34942 I}, {x -> -0.428653 - 1.42567 I,
y -> -0.552329 + 1.34942 I}, {x -> 1.15363,
y -> -0.691637}, {x -> -1.20097 + 0.0500217 I,
y -> 0.324147 - 0.698088 I}, {x -> -1.20097 - 0.0500217 I,
y -> 0.324147 + 0.698088 I}, {x -> 0. + 0.71621 I,
y -> 1.148}, {x -> 0. - 0.71621 I,
y -> 1.148}, {x -> 1.20097 - 0.0500217 I,
y -> 0.324147 - 0.698088 I}, {x -> 1.20097 + 0.0500217 I,
y -> 0.324147 + 0.698088 I}, {x -> 0.428653 + 1.42567 I,
y -> -0.552329 + 1.34942 I}, {x -> 0.428653 - 1.42567 I,
y -> -0.552329 - 1.34942 I}, {x -> -1.15363, y -> -0.691637}}
但是对我来说有用的就是x和y都是实数的解,其余的复数解都没有用,
怎么办呢? Clear["Global`*"];(*清除所有变量*)
eq1 = NSolve[{x^2 + y^3 == 1, x^4 + y^4 == 2}, {x, y}] (*求解方程*)
eq2={x,y}/.eq1 (*只保留数据,去掉变量符号*)
eq3 = Im (*取得虚部*)
Pick (*只提取虚部等于零的数据*)Clear["Global`*"];(*清除所有变量*)
eq1 = NSolve[{x^2 + y^3 == 1, x^4 + y^4 == 2}, {x, y}] (*求解方程*)
eq2={x,y}/.eq1 (*只保留数据,去掉变量符号*)
eq3 = Im (*取得虚部*)
Pick (*只提取虚部等于零的数据*)
但是我得到的结果是
{{}, {}, {1.15363, -0.691637}, {}, {}, {1.148}, {1.148}, {}, {}, {}, \
{}, {-1.15363, -0.691637}}
这个结果总是与我想得到的要差那么些 晕,我自己得到结果了,虽然是费了点小脑筋!
Select == {0, 0} &] Clear["Global`*"];(*清除所有变量*)
eq1=NSolve[{x^2+y^3==1,x^4+y^4==2},{x,y},10];(*求解方程,并得到10位数字*)
eq2={x,y}/.eq1;(*只保留数据,去掉变量符号*)
answer=Select=={0,0}&](*根据虚部都等于零提取得到最后的结果*)
这下算是完美了,不过总有些自问自答的味道! 再给一个复杂的
Clear["Global`*"];(*清除所有变量*)
eq1=NSolve[{x^2+c^2==4^2,y^2+c^2==5^2,
2/x==b/c,2/y==a/c,
a+b==c},{a,b,c,x,y},10] (*求解方程,并得到10位有效数字*)
eq2={a,b,c,x,y}/.eq1 (*只保留数据,去掉变量符号*)
eq3=Select=={0,0,0,0,0}&](*根根据虚部都等于零的结果*)
(*提取结果都大于零的结果*)
eq4=Select]>0&&#[]>0&&#[]>0&&#[]>0&&#[]>0&&#[]>0)&]Clear["Global`*"];(*清除所有变量*)
eq1=NSolve[{x^2+c^2==4^2,y^2+c^2==5^2,
2/x==b/c,2/y==a/c,
a+b==c},{a,b,c,x,y},10] (*求解方程,并得到10位有效数字*)
eq2={a,b,c,x,y}/.eq1 (*只保留数据,去掉变量符号*)
eq3=Select=={0,0,0,0,0}&](*根根据虚部都等于零的结果*)
(*提取结果都大于零的结果*)
eq4=Select]>0&&#[]>0&&#[]>0&&#[]>0&&#[]>0&&#[]>0)&]
不知道谁能把eq3和eq4简化一下! 其实五楼的方程组是根据几何关系得到的,不知道谁能看出来?
我当年就参加数学建模,看到了一本教材,就是因为这个感受到了mathematica的强大! 代码总是解析会出问题,老是要把代码解析成公式,郁闷! 五楼的保留20位的求解结果!
{{0.8190941687975817515, 1.0758780371486812001, 1.8949722059462629516,
3.5226524578350266188, 4.6269947415888808194}} 对了,谁能够把五楼的方程组的符号解求解出来,我说的是符号解,不是数值解,并且提取出都大于零的解! 好庞大的求解结果!看来只有mathematica能办到这事情了!
{{1/72 (36 \(33/2 -
1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 \(182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)])) +
256 \((33/2 -
1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 \(182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]))/(91 +
1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3))) -
4 \((91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)) (33/2 -
1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 \(182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]))) -
4 \((182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]) (33/2 -
1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 \(182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]))) +
1/2 \((91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)) (182 -
1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]) (33/2 -
1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 \(182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)])))),
1/72 (36 \(33/2 -
1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 \(182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)])) -
256 \((33/2 -
1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 \(182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]))/(91 +
1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3))) +
4 \((91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)) (33/2 -
1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 \(182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]))) +
4 \((182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]) (33/2 -
1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 \(182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]))) -
1/2 \((91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)) (182 -
1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]) (33/2 -
1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 \(182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)])))), \(33/
2 - 1/2 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/2 Sqrt[
182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]]),
1/144 (144 + 2176/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
145/8 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] +
1/8 (8789553 - 1119744 Sqrt)^(1/3) Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] +
9/8 (3 (4019 + 512 Sqrt))^(1/3) Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/8 (91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3))^(3/2) +
16 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]] -
1/8 (8789553 - 1119744 Sqrt)^(1/3) Sqrt[
182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]] -
9/8 (3 (4019 + 512 Sqrt))^(1/3) Sqrt[
182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]] -
1/8 (182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)])^(3/2) +
17/4 \((91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)) (182 -
1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]))),
1/144 (144 + 128/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] +
145/8 Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
1/8 (8789553 - 1119744 Sqrt)^(1/3) Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] -
9/8 (3 (4019 + 512 Sqrt))^(1/3) Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)] +
1/8 (91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3))^(3/2) -
16 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]] +
1/8 (8789553 - 1119744 Sqrt)^(1/3) Sqrt[
182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]] +
9/8 (3 (4019 + 512 Sqrt))^(1/3) Sqrt[
182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)]] +
1/8 (182 - 1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)])^(3/2) +
1/4 \((91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)) (182 -
1/3 (8789553 - 1119744 Sqrt)^(1/3) -
3 (3 (4019 + 512 Sqrt))^(1/3) + 1024/Sqrt[
91 + 1/3 (8789553 - 1119744 Sqrt)^(1/3) +
3 (3 (4019 + 512 Sqrt))^(1/3)])))}}
页:
[1]
2