6
$\begingroup$

I am trying to calculate the mutual impedance of two antennas which is just a big integral. I defined my function in terms of my variable, but when I execute it, Mathematica runs for a while and then just gives back my original equation, just a little bit expanded. It does not show any errors, just runs for a while and spits out my unintegrated equation. My exact code is below:

(* this part is just setting up the equations I will be using in my integral *)
Sza[s_, θ_]            := s*Cos[θ]
Sya[s_, θ_, φ_]        := s*Sin[θ]*Sin[φ]
Sxa[s_, θ_, φ_]        := s*Sin[θ]*Cos[φ]
ρa[Sx_, y0_, Sy_]      := Sqrt[Sx^2 + (y0 + Sy)^2]
ra[ρ_, z0_, Sz_]       := Sqrt[ρ^2 + (z0 + Sz)^2]
r1a[ρ_, z0_, Sz_, L1_] := Sqrt[ρ^2 + (z0 + Sz + L1/2)^2]
r2a[ρ_, z0_, Sz_, L1_] := Sqrt[ρ^2 + (z0 + Sz - L1/2)^2]

(* Defining the integral equation *)
R21[ρ_, r1_, Sz_, z0_, L1_, r2_, r_, Sx_, y0_, Sy_, L2_] := -30*
Integrate[
    (((1/ρ^2)*(Sin[2*Pi*r1]*((Sz + z0 + L1/2)/r1) + 
        Sin[2*Pi*r2]*((Sz + z0 - L1/2)/r2) - 
        2*Cos[Pi*L1]*Sin[2*Pi*r]*((Sz + z0)/r))*(Sx^2 + y0*Sy + 
        Sy^2)) + ((2*Sin[2*Pi*r]*Cos[Pi*L1]/r - Sin[2*Pi*r1]/r1 - 
        Sin[2*Pi*r2]/r2)*Sz))*(Sin[2*Pi*(L2/2 - Abs[s])]/s),
    {s, -L2/2, L2/2}]

(*Calculating constants *)
Sz = Sza[s, 1/4*Pi]
Sy = Sya[s, 1/4*Pi, 1/4*Pi]
Sx = Sxa[s, 1/4*Pi, 1/4*Pi]
ρ  = ρa[Sx, .6175, Sy]
r  = ra[ρ, .103, Sz]
r1 = r1a[ρ, .103, Sz, .395]
r2 = r2a[ρ, .103, Sz, .395]

(*Executing the integration equation, with constants plugged in *)
R21[ρ, r1, Sz, .103, .395, r2, r, Sx, .6175, Sy, 1.63]

After that, it ran for about 2 hours, and then just spit out R21 in its integration form.

What I am doing wrong?

$\endgroup$
6
$\begingroup$

Use NIntegrate to perform numerical integration (simply replace Integrate with NIntegrate in the definition of R21). On my laptop, it spits out the numerical value of the result in 0.3 s (and the result is 9.46643, by the way).

$\endgroup$
  • $\begingroup$ Wow, that was easy. Thank you very much!!! $\endgroup$ – Dmitry Apr 2 '12 at 22:37
  • $\begingroup$ So did you use Timing or AbsoluteTiming to figure out how long it took for the code to run? $\endgroup$ – dearN Apr 2 '12 at 22:52
  • $\begingroup$ I did not but all I cared about is that it gave me an answer in less than a second. This is weird about integrate though, I always used Integrate for numerical computations and had no problems. Guess it uses a different method. $\endgroup$ – Dmitry Apr 2 '12 at 22:59
  • $\begingroup$ @DNA AbsoluteTiming, why? $\endgroup$ – F'x Apr 3 '12 at 7:01
  • $\begingroup$ @F'x Oh, just curious! $\endgroup$ – dearN Apr 3 '12 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.