空间换速度
sqrt[m_] := sqrt[m] = N@Sqrt[m]
bsqrt[b_, m_] := bsqrt[b, m] = b sqrt[m]
nbsqrt[n_, b_, m_] := nbsqrt[n, b, m] = (-1)^n bsqrt[b, m]
sqrtanbsqrt[a_, n_, b_, m_] :=
sqrtanbsqrt[a, n, b, m] = Sqrt[a + nbsqrt[n, b, m]]
Do[If[Abs[sqrtanbsqrt[a, n1, b, m] + sqrtanbsqrt[d, n2, e, m] - 9] <
4*^-6, Print[{n1, n2, a, b, d, e, m}]], {n1, 0, 1}, {n2, 0,
1}, {a, -10, 10}, {b, -10, 10}, {d, -10, 30}, {e, -10, 10}, {m, 2,
8}]
2018年10月11日 06点10分
9
真是太感谢,我测算了一下,速度超快!确实牛!!!谢谢老师啦!
2018年10月11日 11点10分
我是初学者,当中有些看不懂的
![[狂汗]](/static/emoticons/u72c2u6c57.png)
,我去琢磨琢磨,实在搞不懂再来求教
2018年10月11日 12点10分
老师,你好!这种算法语言我使用了万能度娘也没查明白,比如:sqrt是平方根,Abs是绝对值这我能懂,但 N@Sqrt[m],sqrt[m_]我就看不懂了,真是羞愧。能否请老师在百忙之中抽出宝贵的时间指点学生,逐句帮我讲解一下,你是如何用空间换速度的,用mathematica常用的语言应该怎么写?拜托老师了!
2018年10月13日 11点10分
我看明白的原理是:尽可能使用机器精度的小数( N@Sqrt[m]),而不是我们常用的精确形式,我搞不懂这种语言命令,跟书上讲的不一样,帮助上也没说明。
2018年10月13日 17点10分