UPDATE
感谢发布的答案,我找到了一种更简单的方法来制定问题.原始问题可以在修订历史中看到.
我正在尝试将SQL查询转换为Django,但是我收到了一个我不理解的错误.
这是我的Django模型:
class Title(models.Model):
title_id = models.CharField(primary_key=True, max_length=12)
title = models.CharField(max_length=80)
publisher = models.CharField(max_length=100)
price = models.DecimalField(decimal_places=2, blank=True, null=True)
Run Code Online (Sandbox Code Playgroud)
我有以下数据:
publisher title_id price title
--------------------------- ---------- ------- -----------------------------------
New Age Books PS2106 7 Life Without Fear
New Age Books PS2091 10.95 Is Anger the Enemy?
New Age Books BU2075 2.99 You Can Combat Computer Stress!
New Age Books TC7777 14.99 Sushi, Anyone?
Binnet & Hardley MC3021 2.99 The Gourmet Microwave
Binnet & Hardley MC2222 19.99 Silicon Valley …Run Code Online (Sandbox Code Playgroud) 在Mathematica 8.0中,假设我有一些常量:
a:=7
b:=9
c:=13
d:=.002
e:=2
f:=1
Run Code Online (Sandbox Code Playgroud)
我想用它们来评估一些相互关联的功能
g[0,k_]:=0
g[t_,0]:=e
g[t_,k_]:=g[t-1,k]*a+h[t-1,k-1]*b
h[0,k_]:=0
h[t_,0]:=f
h[t_,k_]:=h[t-1,k]*c+g[t-1,k-1]*d
Run Code Online (Sandbox Code Playgroud)
但这真的很慢,需要动态编程,否则你会出现指数减速:
g[0, k_] := 0
g[t_, 0] := e
g[t_, k_] := g[t, k] = g[t - 1, k]*a + h[t - 1, k - 1]*b
h[0, k_] := 0
h[t_, 0] := f
h[t_, k_] := h[t, k] = h[t - 1, k]*c + g[t - 1, k - 1]*d
Run Code Online (Sandbox Code Playgroud)
现在,它的真快,但是如果我们想改变常量(比如,在操纵功能,使用此),我们必须Clear g和h每个时间.如果我们有复杂的相互依赖性,这可能是真的很烦人,以清除它们全力以赴我们希望从一个值每一次g和h.
有一种简单的方式来运行g,并h …
recursion wolfram-mathematica dynamic-programming exponential
首先是我的mathematica很差.我尝试使用php将数字设为Multiples of 7.规则如下:
$num >=0;
$num = '0'; => output '7'
$num = '1'; => output '7'
$num = '6'; => output '7'
$num = '8'; => output '14'
$num = '14'; => output '14'
$num = '16'; => output '21'
$num = '20'; => output '21'
$num = '40'; => output '42'
$num = '84'; => output '84'
...
Run Code Online (Sandbox Code Playgroud)
我花了很多倍,但我自己解决这个问题并不聪明.如
echo round(($num*7-1)/7); // not a right answer.
Run Code Online (Sandbox Code Playgroud)
有人帮我吗?谢谢.