関数ハンドルのハンドルの渡し方について
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
kazuma kaneda
el 19 de Nov. de 2021
Respondida: Atsushi Ueno
el 22 de Nov. de 2021
下のように、ωについての積分をするコードを書きました。
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/806139/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/806144/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/806149/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/806154/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/806159/image.png)
以下がコードです。
A=1;m=1;s=1;wA=1;const=10^-10; %定数を決定
%2の計算 まず、eで積分
J=ffun(@(e)A.*exp(-(e-m).^2./(2*pi.*s.^2))./(w-e),-inf,w-const,w+const,inf)-@(w)1i*pi*A.*exp(-(w-m).^2./(2*pi.*s.^2));
%1の計算 次に、wで積分
K=@(t)gfun(@(w)exp(-1i*w.*t)./(w-wA-J),-inf,inf);
function f=ffun(fun,a,b,c,d)
f=integral(fun,a,b)+integral(fun,c,d);
end
function g=gfun(fun,a,b)
g=integral(fun,a,b);
end
こなままだと、まずωが変数として認識されません。また、ハンドルの渡し方についても違うと思うのですがわかる方がいましたらご教授お願いします。
2 comentarios
Atsushi Ueno
el 21 de Nov. de 2021
2行目の”@(w)”を先頭に移動すれば、ωに関するエラー無く動く事は間違いないです。
ただ、続くKの演算におけるgfunの中身(積分する式)が「ωを含む数式-(ωを引数とする関数ハンドル)」と、数式の内部で関数ハンドルを演算しており、この形が成立するのかどうかが疑問です
Atsushi Ueno
el 22 de Nov. de 2021
すなわち「無名関数の入れ子」の考え方が必要ですね
Respuesta aceptada
Atsushi Ueno
el 22 de Nov. de 2021
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/809089/image.png)
ηによる積分範囲を分割して下記のようにした理由が良く分かりませんが、とにかくそのように致します。
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/809094/image.png)
JとKを離せない問題があって長く見難いですが、これで引数t,ω,ηが入れ子になった無名関数として成立します。
A=1;m=1;s=1;wA=1;const=10^-10; %定数を決定
K=@(t)gfun(@(w)exp(-1i*w.*t)./(w-wA-ffun(@(e)A.*exp(-(e-m).^2./(2*pi.*s.^2))./(w-e),-inf,w-const,w+const,inf)-1i*pi*A.*exp(-(w-m).^2./(2*pi.*s.^2))),-inf,inf)
function f=ffun(fun,a,b,c,d)
f=integral(fun,a,b)+integral(fun,c,d);
end
function g=gfun(fun,a,b)
g=integral(fun,a,b);
end
0 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!