Double integral with complex numbers in a loop
古いコメントを表示
Hi everyone, I'm trying to run this code (probably there are better ways to write it, but I'm not a pro at Matlab yet).
params is a vector of 4 parameters, Nstep =365*25, and p_sims is a matrix with Nstep+1 columns and as many raws as the number of simulations (1000 in my case).
I need to integrate a function in two variables, u and s and then use the result to create another matrix.
The problem is that I need to insert in the integrand a vector (the jjj column of p_sims), but this gives me an error (Inner matrix dimensions must agree), whether I use .* to multiply by something containing p_sims, or * How can I solve this?
(I tried with a loop to compute the jjj column of CPrice, but it took ages to run the code, so I was wondering if there was a more efficient way)
for jjj=Nstep+1:-1:1
CFun = @(s,u) exp(-r*(s-jjj)).*p_sims(:,jjj).^gamma.*floor^(1-gamma)/pi.* ...
exp(-1i*u.*log(p_sims(:,jjj)/floor)).*exp(1i*params(2).*s.*(-u-1i*gamma));
CPrice(:,jjj) = X.*real(integral2(CFun,jjj,Nstep+1,0,inf));
phi(:,jjj) = p_sims(:,jjj).*(exp((params(2)-r)*(Nstep+1-jjj))*(1-(params(4)+1/2*params(3)^2)/params(1))^ ...
(-params(1)*(Nstep+1-jjj))-1) + CPrice(:,jjj);
end
3 件のコメント
Walter Roberson
2017 年 5 月 2 日
"inner dimensions must agree" can only occur for * or / and not for .* or ./
Maria445
2017 年 5 月 2 日
Maria445
2017 年 5 月 2 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!