for-loop not computing the values
Hi. I am quite new to using phyton is SAGE, but what I did here is that I have tried my best to come up with the code based on reading multiple notes on SAGE.
The values of alpha, n, eta, lambda, h, T, t, kappa, k(x-s) and gamma values are given.
I have tried to do the coding from scratch and this is what I have obtained:
from __future__ import print_function
alpha = 1.2
n = 2
eta = 1.3
lamda = 1
h = 1
T = 1
t = 0.1
h, t, x, s = var('h t x s')
U[t] = 1/3*t^3+1
P[t] = 2*t-lamda*(-t^4/24+t^5/15-t^7/126+t^8/72)
b[k] = 1
def X(m):
if m <= 1:
return 0
else:
return 1
k[x,s]=s-x
gamma[z]=integrate(x^(z-1)*e^(-x),x, 0, infinity)
u[0]=1
for m in range(1,4):
u[m] = sum(b[k]/factorial(k)*t^k,k,0,n-1) + X[m]*u[m-1]-X[m]*sum(๐๐๐๐๐๐๐๐๐๐(u[m-1][0],t,k)/factorial(k)*t^k,k,0,n-1)+h/gamma[eta-alpha]*integrate((t-tau)^(eta-alpha-1)*u[m-1].subs(t=tau)*P[t].subs(t=tau),tau, 0, t); print(u[m].full_simplify())
UU=u[1]+u[2]+u[3]+u[4]:
What I am trying to achieve here is the values of u_1, u_2, u_3, u_4
. Then calculate UU = u_1 + u_2 + u_3 + u_4
.
At the moment, I am not getting the answer. Not sure what is causing the error. It took me so much time and effort to come up with this from scratch, hope someone can help me indicate what's wrong with this coding. Thank you in advance.
Hello, @Sha! I have corrected some errors in your code. However, there seems to be a couple of problems in Sage. On one side, the last integral in the definition of
u[m]
can't be computed directly, so I had to use a couple of auxiliary variables. This helped, but the loop only computes one iteration, and then freezes until Sage gives up.I suppose there are some optimizations that can be carried out in the loop. Let me try for a couple of days and I'll let you know. Do you have a deadline for this?
My code is here
U
andP
look like functions, so you should use parentheses when you define them.b
andu
look like lists or dictionaries or vectors, and you need to define them as such before setting entries in them.u[0]=1
will give an error, for example, unless you have first done something likeu={}
. Also, note thatfor m in range(1,4):
will loop over valuesm=1
,m=2
, andm=3
, but notm=4
.@dsejas Hi diego. thank you for your reply. I am actually trying to figure out the formula too.. just to check if there's anything wrong with it. I don't have a deadline with this. Thank you for your help. Let me too re check the calculation manually.
@johnpalmieri thank you for the feedback John. I really appreciate it.