這類事情變得非常複雜。雖然可以用一個內聯方程來完成,但我建議您將其分解爲多個嵌套函數(如果僅用於可讀性)。
爲什麼可讀性很重要的最佳示例:您在發佈的公式中存在包圍問題;沒有足夠的右括號,所以我不能完全肯定式的樣子在數學符號:)
總之,這裏的同版本做這件事我--think--你的意思是:
function test
% some random values for testing
Y0 = rand;
b = rand;
a = rand;
k0 = rand;
alpha = rand;
epsilon_t = rand;
% D is your B
D = -0.015;
% define SIMPLE anonymous function
Bb = @(ep) F(ep).*main_integral(ep) - D;
% aaaand...solve it!
sol = fsolve(Bb, 1)
% The anonymous function above is only simple, because of these:
% the main integral
function val = main_integral(epsilon)
% we need for loop through epsilon, due to how quad(gk) solves things
val = zeros(size(epsilon));
for ii = 1:numel(epsilon)
ep = epsilon(ii);
% NOTE how the sinint's all have a different function as argument:
val(ii) = quadgk(@(th)...
2*sinint(A(ep,th)) - sinint(B(ep,th)) - sinint(C(ep,th)), ...
0, pi);
end
end
% factor in front of integral
function f = F(epsilon)
f = alpha*Y0*sqrt(epsilon)./(pi*log(b/a)*sqrt(epsilon_t)); end
% first sinint argument
function val = A(epsilon, theta)
val = k0*sqrt(epsilon*(a^2+b^2-2*a*b*cos(theta))); end
% second sinint argument
function val = B(epsilon, theta)
val = 2*k0*sqrt(epsilon)*a*sin(theta/2); end
% third sinint argument
function val = C(epsilon, theta)
val = 2*k0*sqrt(epsilon)*b*sin(theta/2); end
end
上述解決方案仍然很慢,但我認爲這是非常正常的積分這很複雜。
我不認爲實現自己的sinint
會有很大的幫助,因爲大部分速度損失是由於非內建函數的for循環引起的......如果速度要求,我會去MEX用自己的Gauss-Kronrod自適應正交例程實現。
http://www.mathworks.com/matlabcentral/fileexchange/34241-integral-equation-solver – 0x90
上面定義了所有其他的常量嗎? (即α,Y0等) – nicktruesdale
這些常數只是用於計算目的的任意常數,只有epsilon是未知的。 theta只是整合變量(如dx,dy,dz等) – user1880273