Double integral with complex numbers in a loop
Mostra commenti meno recenti
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 Commenti
Walter Roberson
il 2 Mag 2017
"inner dimensions must agree" can only occur for * or / and not for .* or ./
Maria445
il 2 Mag 2017
Maria445
il 2 Mag 2017
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Numerical Integration and Differentiation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!