Double integral of a function (Beginners Question)
Subject: Double integral of a function (Beginners Question)
From: Leo Butler
Date: Mon, 7 Jun 2010 12:26:16 +0100 (BST)
On Mon, 7 Jun 2010, Doktor Bernd wrote:
< Hi,
<
< I just started using Maxima as I wanted to check some of my calculations which I am doing in C.
< I searched a lot on the web and read several tutorials, but I think this confused me more than it helped.
<
< I tried to bring my code from C to Maxima, which leads to the following code (I simplified some parts, that's why there is e.g the Cn2(l) function)
<
< Lambda : 0 $
< Theta : 1 $
< Theta_inv : 1-Theta $
< W_0 : 0.0254 $
< L : 50000 $
< Cn2 : 1e-17 $
< li : 0.005 $
< lo : 5.0 $
< k : 7.139983303613165e+006 $
< r : 0 $
< Cn2(l) := block([l:l], 1e-17) $
< rho_0(k,L,Cn2) := block([k:k,L:L,Cn2:Cn2],(1.46*k^2*integrate(Cn2(l),l,0,L))^(-3/5)) $
< ka2x(k,l,Cn2) := block([k:k,l:l,Cn2:Cn2],(0.38/k + 0.35*(l/(k*rho_0(k,l,Cn2)))^2)^-1) $
< ka2y(k,l,Cn2) := block([k:k,l:l,Cn2:Cn2],3*k/l + 1.7/rho_0(k,l,Cn2)) $
< f(kappa,li):= block([kappa:kappa,li:li],exp(-kappa^2/(3.3/li)^2)*(1+1.803*(kappa/(3.3/li))-0.254*(kappa/(3.3/li))^(7/6))) $
< g(kappa,lo):= block([kappa:kappa,lo:lo],(1-exp(-kappa^2/(8*%pi/lo)^2))) $
< spec(Cn2,kappa,ka2x,ka2y,li,lo):= block([Cn2:Cn2,kappa:kappa,ka2x:ka2x,ka2y:ka2y,li:li,lo:lo],0.033*Cn2*kappa^(-11/3)* f(kappa,li) * g(kappa,lo) *exp(-(kappa^2)/(ka2x))+(kappa^(11/3))/(kappa^2+ka2y^2)^(11/6)) $
< integrand(kappa,Cn2,l,L,Lambda,Theta_inv,xi,k,r):= block([kappa:kappa,Cn2:Cn2,l:l,L:L,Lambda:Lambda,Theta_inv:Theta_inv,xi:xi,k:k,r:r],kappa*spec(Cn2,kappa,ka2x(k,l,Cn2),ka2y(k,l,Cn2),li,lo)*exp(-(Lambda*L*kappa^2*xi^2)/(k)) *
< (bessel_i(0,2*Lambda*r*kappa*xi)-cos((L*kappa^2)/k)*xi*(1-Theta_inv*xi))) $
< float(integrate('(integrate('(integrand(kappa,Cn2,(1-xi)/L,L,Lambda,Theta_inv,xi,k,r)),'kappa,0,inf)),xi,0,1));
<
< My questions are:
<
< Do I have to use the blocks?
No. You are using block inappropriately. The function arguments are
copies which you can overwrite inside the rhs of the function definition
without effect on the value passed.
e.g. try
f(x) := (x:2*x,x);
If you wish to see how f is defined in the underlying lisp, try
:lisp (mget '$f 'mexpr)
< I read at some places that I have to and at others that all passed variables are treated as local ones.
<
< Why do I not get a result from the last statement?
< I guess I am using ' in a wrong way.
Yes, ' suppresses evaluation. Compare
'integrate(1/x,x);
and
integrate(1/x,x);
Welcome to Maxima. I hope it helps in your work.
Leo
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.