[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
anonymous functions with >1 arg with quad
From: |
Ben Barrowes |
Subject: |
anonymous functions with >1 arg with quad |
Date: |
Thu, 18 May 2006 16:45:21 -0400 |
User-agent: |
KMail/1.8.2 |
I think I need to understand anonymous functions better in octave.
I am trying to integrate (using quad) a function that needs some parameters
passed into it.
But I can't seem to figure out the syntax to do it correctly in octave 2.9.5.
Here are my calls to quad which all work in matlab. I want to pass the variables
"I,f,a,h,d,mu0,mu,sigma" into kernel. What is the best way to do this?
Hs=quad('kernel',1e-8,100,[],[],I,f,a,h,d,mu0,mu,sigma)
Hs=quad(@kernel,1e-8,100,[],[],I,f,a,h,d,mu0,mu,sigma)
Hs=quad(@(x) kernel(x,I,f,a,h,d,mu0,mu,sigma),1e-8,100)
and
function int=kernel(lambda,I,f,a,h,d,mu0,mu,sigma)
Nl=length(lambda);
N=length(mu);
Y=zeros(N,Nl);
Yhat=zeros(N,Nl);
for ii=N:-1:1
k=sqrt(i.*2.*pi.*f.*sigma(ii).*mu0.*mu(ii));
u=sqrt(lambda.^2+k.^2);
Yhat=u./(i.*2.*pi.*f.*mu0.*mu(ii));
if ii==N
Y(ii,:)=Yhat;
else
t=d(ii+1)-d(ii);
Y(ii,:)=Yhat.*(Y(ii+1,:)+Yhat.*tanh(u.*t))./(Yhat+Y(ii+1,:).*tanh(u.*t));
end
end % for ii=length(mu):-1:1
u0=lambda;
Y0=u0./(i.*2.*pi.*f.*mu0);
R=(Y(1,:)-Y0)./(Y(1,:)+Y0);
int=I.*a./2.*R.*lambda.*exp(-2.*lambda.*h).*besselj(1,lambda.*a);
end
octave:21> ver
----------------------------------------------------------------------
GNU Octave Version 2.9.5
GNU Octave License: GNU General Public License, Version 2
Operating System: Linux 2.6.12-12mdksmp #1 SMP Fri Sep 9 17:43:23 CEST 2005 i686
----------------------------------------------------------------------
octave-forge 20060317
octave:22>
bb
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- anonymous functions with >1 arg with quad,
Ben Barrowes <=