ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 18 Jan 2021 17:13:33 +0100Please tell me how to write a loophttps://ask.sagemath.org/question/55339/please-tell-me-how-to-write-a-loop/
x=3
for i in range(x):
[if(arr[i]==1)]:
arr[i]=2^(x-i-1)
Hello there please tell me how to set that arr[i] within the for loop, that is going outside of the loop
If array value at a index is 1 I have set it to the power of 2
IDK about this I'm trying for so long. Please help me with this.
Thanks againRamaMon, 18 Jan 2021 17:13:33 +0100https://ask.sagemath.org/question/55339/Recurrence, for-loop and zero.https://ask.sagemath.org/question/37380/recurrence-for-loop-and-zero/Hello guys! Hope you guys are having a nice day.
I have some problem as follows: I setup some recurrence as follows
def f(j,k):
if k==0:
m=j
elif j==0:
m=k
else:
m=j/k*(f(j-1,k)+1/k*(f(j-1,k)))+k/j*(f(j,k-1)+1/j*(f(j,k-1)))
return m
And if we calculate
`f(1,1),
f(2,1),
f(1,2),
f(2,2)`
in sage, then what we get are
4,
35/2,
35/2,
105/2.
However, if we do the for loop as in the below, I found the above results to be zero!!:
for k in range(3):
for j in range(3):
(j,k), expVal(j,k)
And the calculation result from the sage is:
((0, 0), 0)
((1, 0), 1)
((2, 0), 2)
((0, 1), 1)
**((1, 1), 0)**
**((2, 1), 0)**
((0, 2), 2)
**((1, 2), 0)**
**((2, 2), 0)**
And observe the bolded result above... it is weird that the result is zero... Can anyone help me fix this please...
Thank you for any help! Hope you have a nice rest of the day!
sssageeeeMon, 24 Apr 2017 00:09:35 +0200https://ask.sagemath.org/question/37380/write output of for loop in pari to filehttps://ask.sagemath.org/question/32491/write-output-of-for-loop-in-pari-to-file/Hi all,
I would like to write the output of a for loop in Pari to a file named 'foo', However the output of a for loop has no numbering contrast with other output. If I look at the numbers labeling the outputs before and after the for loop and use that number in the following command
\w n foo
Then what I get in foo is 0. What happened and how can this be fixed?
Dianbin BaoMon, 08 Feb 2016 03:36:16 +0100https://ask.sagemath.org/question/32491/