ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 01 Sep 2012 10:30:27 -0500Solving a system of coupled iterative equations containing lots of heavy integrals and derivativeshttp://ask.sagemath.org/question/9285/solving-a-system-of-coupled-iterative-equations-containing-lots-of-heavy-integrals-and-derivatives/Hello all,
I am trying to solve a system of coupled iterative equations, each of which containing lots of integrations and derivatives.
First I used Sage to solve it analytically, but the solution was too dependent on the initial guesses for my unknown functions in the iterative loops, constant values for initial guesses yielded in Sage answering back almost immediately whereas symbolic functions when were used as initial guesses caused the system to go deep into calculations, sometimes seemingly into never ending ones.
However, what I tried with Sage was actually a simplified version of my original equations so I thought it might be the case that I have no other choice rather than to treat the integrations and derivatives numerically, however, I had some not ignorable problems:
1. integrations were only allowed to have numerical limits and variables were not allowed as e.g. their upper limits (I thought maybe a numerical method algorithm is faster than the analytic one even-though I leave a variable or parameter in its calculations, but it just didn't work so).
2. integrands couldn't also admit extra variables and parameters w.r.t. which not being integrated.
3. the derivative function was itself a big obstacle, as I wasn't able to compute partial derivatives or to use a derivative in the integrand of an integral.
To get rid of all the problems with numerical derivative I substitute it by the symbolic diff() function and the speed improvement was still hopeful but the problems with numerical integration persist.
Now I have three questions:
a- Is it right to conclude there is no other way for me rather than to discretize the equations and do a complete numerical treatment instead of a mixed one?
b- If so then is there any way to do this automatically? My equations are not DE ones to use ODEint or else, they are iterative equations, I have integrations and derivatives only to update my unknowns at each step to their newer values.
c- If my calculations are so huge in size is there any suggestion on switching from python to fortran or things like that as well?
Best RegardsowariSat, 01 Sep 2012 10:30:27 -0500http://ask.sagemath.org/question/9285/problem with numerical integration and differentiation with scipyhttp://ask.sagemath.org/question/9272/problem-with-numerical-integration-and-differentiation-with-scipy/Hi,
I was trying to learn Scipy, using it for integration and differentiation, but at the very initial step I encontered the following problems.
First, the following integration has a complex value as its numerical result when is solved analytically, but the numerical solution only gives its real part without any note for caution:
reset()
forget()
import scipy as sp
from scipy import integrate
var('y')
f=lambda x: 10^10*sin(x)
g=lambda x,y: f(x+y^2)
I=integrate.dblquad(g(x,y), 0, pi, lambda y:0,lambda y:1)[0]; show(I)
show( integral(integral(g(x,y),x,0,1),y,0,pi) )
show( integral(integral(g(x,y),x,0,1),y,0,pi).n() )
is this natural or I am doing something wrong that may cause my even **Real calculations** erratic?
Next, about numerical differentiation, it seems that the only function that works for callable functions is scipy.derivative() if I'm right!? However, I couldn't work with it:
**1st)** when I am not going to specify the point at which the differentiation is to be taken, e.g. when the differentiation is under an integral so that it is the integral that should assign the numerical values to its integrand's variable, not me. As a simple example I tried this code:
import scipy as sp
from scipy import integrate, derivative
I2=integrate.quad( sp.derivative(f(y),y, dx=0.00001, n=1, order=7) , 0, pi,)[0]; show(I2)
show( integral(diff(f(y),y),y,0,1).n() )
also it gives the warning that "Warning: The ocurrence of roundoff error is detected, which prevents the requested tolerance from being achieved. The error may be underestimated."
**2nd)** when I want to find the derivative of a multivariable function like g(x,y) in the above example, and something like sp.derivative(g(x,y),(x,0.5), dx=0.01, n=1, order=3) gives error as was easily expected.
Looking forward to hearing from you if that integration result is natural and how to resolve the above cited problems with numerical differentiation.
Best RegardsowariTue, 28 Aug 2012 05:15:47 -0500http://ask.sagemath.org/question/9272/