Clear Filters
Clear Filters

Error using arrayfun All of the input arguments must be of the same size and shape. Previous inputs had size 14 in dimension 1. Input #5 has size 1

18 views (last 30 days)
timerperpeture()
Error using arrayfun
All of the input arguments must be of the same size and shape.
Previous inputs had size 14 in dimension 1. Input #5 has size 1

Error in solution>@(tau,ztau,zpa,t)cell2mat(arrayfun(@(tau,ztau,zpa,t)iyP(tau,ztau,zpa,t),tau,ztau,zpa,t,'UniformOutput',0)) (line 33)
iyp2=@(tau,ztau,zpa,t)cell2mat(arrayfun(@(tau,ztau,zpa,t)iyP(tau,ztau,zpa,t),tau,ztau,zpa,t,'UniformOutput',0));

Error in solution>@(tau,ztau,zpa)((-1).^(t)).*real(iyp2(tau,ztau,zpa,t).*sqrt(2*alphaP).*(ztau.^(nu+1))./(sinh(zpa.*sqrt(alphaP/2)).*8*(zpath^(nu))).*exp(-(nu^2).*tau.*(sigma^2)/8-((zpath+ztau).*sqrt(2*alphaP).*coth(zpa.*sqrt(alphaP/2))))) (line 34)
H2=@(t)@(tau,ztau,zpa)((-1).^(t)).*real(iyp2(tau,ztau,zpa,t).*sqrt(2*alphaP).*(ztau.^(nu+1))./(sinh(zpa.*sqrt(alphaP/2)).*8*(zpath^(nu))).*exp(-(nu^2).*tau.*(sigma^2)/8-((zpath+ztau).*sqrt(2*alphaP).*coth(zpa.*sqrt(alphaP/2)))));

Error in solution>@(tau,ztau,zpa)la(tau,ztau,zpa)+sum(gH2(tau,ztau,zpa)) (line 36)
fgH2=@(tau,ztau,zpa)la(tau,ztau,zpa)+sum(gH2(tau,ztau,zpa));

Error in solution>@(tau,ztau,zpa)(fgH2(tau,ztau,zpa)+C(2:IP).*UMY(tau,ztau,zpa)) (line 45)
F=@(tau,ztau,zpa)(fgH2(tau,ztau,zpa)+C(2:IP).*UMY(tau,ztau,zpa));

Error in solution>@(tau,ztau,zpa)(exp(9/2)/B)*sum(F(tau,ztau,zpa))/8192*(s0*exp(vaps-r*tau)*normcdf(d1)-K*exp(-r*tau)*normcdf(d2)) (line 46)
AVGSU=@(tau,ztau,zpa)(exp(9/2)/B)*sum(F(tau,ztau,zpa))/8192*(s0*exp(vaps-r*tau)*normcdf(d1)-K*exp(-r*tau)*normcdf(d2));

Error in solution>@(tau,ztau,zpa)AVGSU(tau,ztau,zpa) (line 52)
Pfin=integral3(@(tau,ztau,zpa)AVGSU(tau,ztau,zpa),0,B,0,1,0,1,'AbsTol', 0,'RelTol',0.1) %inner expectation

Error in integral3>@(y,z)fun(x(1)*ones(size(z)),y,z) (line 129)
@(y,z)fun(x(1)*ones(size(z)),y,z), ...

Error in integral2Calc>integral2t/tensor (line 228)
Z = FUN(X,Y); NFE = NFE + 1;

Error in integral2Calc>integral2t (line 55)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);

Error in integral2Calc (line 9)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);

Error in integral3>innerintegral (line 128)
Q1 = integral2Calc( ...

Error in integral3>@(x)innerintegral(x,fun,yminx,ymaxx,zminxy,zmaxxy,integral2options) (line 111)
f = @(x)innerintegral(x, fun, yminx, ymaxx, ...

Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);

Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);

Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);

Error in integral3 (line 113)
Q = integralCalc(f,xmin,xmax,integralOptions);

Error in solution>timerperpeture (line 52)
Pfin=integral3(@(tau,ztau,zpa)AVGSU(tau,ztau,zpa),0,B,0,1,0,1,'AbsTol', 0,'RelTol',0.1) %inner expectation
function [Pfin]=timerperpeture(s0,v0,sigma,kappa,K,B) %varibles
s0=100;
v0=0.001;
K=90;
B=0.001;
r=0.01;
sigma=0.15;
kappa=0.1;
rho=0.5;
zpath=(2*sqrt(v0))/sigma;
deta=(4*kappa)/(sigma^2); % Bessel process parameter
nu=deta/2-1; % bessel model index
%syms tau ztau zpa
d=sqrt((1-rho^2)*B);
vaps=@(tau,ztau,zpa)-rho*(2*kappa/(sigma^2)-0.5).*(zpa)+(r*tau)-(B/2)+rho.*(ztau-zpath);
d1=@(tau,ztau,zpa)((log(s0/K)+vaps(tau,ztau,zpa)+(1-rho^2)*B))/d;
d2=@(tau,ztau,zpa)d1-d;
%% laplace inverse
alpha=(9)/(2*B); % laplace parameter,10
f1=@(tau,ztau,zpa,u)((2*sqrt(2*alpha*zpath.*ztau)./(sinh(tau.*sqrt(alpha./2))))./sqrt((pi^3).*zpa).*exp(-(2*sqrt(2*alpha*zpath.*ztau)./(sinh(tau.*sqrt(alpha./2)))).*cosh(u)-(pi^2)./(4.*zpa)-(u.^2)./(4.*zpa)).*sinh(u).*sin(pi.*u./(2.*zpa)));
iy1=@(tau,ztau,zpa)integral(@(u)f1(tau,ztau,zpa,u),0,200*pi,'ArrayValued',1);
iy2=@(tau,ztau,zpa)cell2mat(arrayfun(@(tau,ztau,zpa)iy1(tau,ztau,zpa),tau,ztau,zpa,'UniformOutput',0));
la=@(tau,ztau,zpa)0.5*real(iy2(tau,ztau,zpa).*sqrt(2*alpha).*(ztau.^(nu+1))./(sinh(tau.*sqrt(alpha./2)).*8*(zpath^(nu))).*exp(-(nu^2).*tau.*(sigma^2)/8-((zpath+ztau).*sqrt(2*alpha).*coth(zpa.*sqrt(alpha/2)))));
%la=0.5*real(iy2.*sqrt(2*alpha).*(ztau.^(nu+1))./(sh.*8*(zpath^(nu))).*exp(-(nu^2).*tau.*(sigma^2)/8-((zpath+ztau).*sqrt(2*alpha).*coth(zpa.*sqrt(alpha/2)))));
%% circle
NTR=5;
alphaP=@(t)complex(alpha,(t*pi)/B);
iyfP=@(tau,ztau,zpa,t,u)(2*sqrt(2*alphaP*zpath.*ztau)./sinh(zpa.*sqrt(alphaP/2)))./sqrt(pi^3.*tau).*exp(-(2*sqrt(2*alphaP*zpath.*ztau)./sinh(zpa.*sqrt(alphaP/2))).*cosh(u)-(pi^2-u.^2)./(4.*tau)).*sinh(u).*sin(pi.*u./2.*tau);
iyP=@(tau,ztau,zpa,t)integral(@(u)iyfP(tau,ztau,zpa,t,u),0,200*pi,'ArrayValued',1);
iyp2=@(tau,ztau,zpa,t)cell2mat(arrayfun(@(tau,ztau,zpa,t)iyP(tau,ztau,zpa,t),tau,ztau,zpa,t,'UniformOutput',0));
H2=@(t)@(tau,ztau,zpa)((-1).^(t)).*real(iyp2(tau,ztau,zpa,t).*sqrt(2*alphaP).*(ztau.^(nu+1))./(sinh(zpa.*sqrt(alphaP/2)).*8*(zpath^(nu))).*exp(-(nu^2).*tau.*(sigma^2)/8-((zpath+ztau).*sqrt(2*alphaP).*coth(zpa.*sqrt(alphaP/2)))));
gH2=H2(2:NTR);
fgH2=@(tau,ztau,zpa)la(tau,ztau,zpa)+sum(gH2(tau,ztau,zpa));
IP=14;
alpha2=@(N)complex(alpha,((NTR+N)*pi)/B);
sh2=@(N)sinh(zpa.*sqrt(alpha2/2));
gP2=@(N)2*sqrt(2*alpha2*zpath.*ztau)./sh2;
iyP2=@(N)@(tau,ztau,zpa)integral(@(u)gP2./sqrt(pi^3.*tau).*exp(-gP.*cosh(u)-(pi^2-u.^2)./(4.*tau)).*sinh(u).*sin(pi.*u./2.*tau),0,200*pi,'ArrayValued',1);
MY=@(N)@(tau,ztau,zpa)(-1)^(NTR+N).*real(iyP2.*sqrt(2*alpha2).*(ztau.^(nu+1))./(sh2.*8*(zpath^(nu))).*exp(-(nu^2).*tau.*(sigma^2)/8-((zpath+ztau).*sqrt(2*alpha2).*coth(zpa.*sqrt(alpha2/2)))));
UMY=MY(1:IP);
C=[1,14,91,364,1001,1848,3003,3432,3003,1848,1001,364,91,14,1];
F=@(tau,ztau,zpa)(fgH2(tau,ztau,zpa)+C(2:IP).*UMY(tau,ztau,zpa));
AVGSU=@(tau,ztau,zpa)(exp(9/2)/B)*sum(F(tau,ztau,zpa))/8192*(s0*exp(vaps-r*tau)*normcdf(d1)-K*exp(-r*tau)*normcdf(d2));
% dx=find(isnan(AVGSU)~=0);
% AVGSU(dx)=0;
% dy=find(isnan(AVGSU1)~=0);
% AVGSU1(dy)=0;
%disthree=@(tau,ztau,zpa,u)(U.*AVGSU)./8192;
Pfin=integral3(@(tau,ztau,zpa)AVGSU(tau,ztau,zpa),0,B,0,1,0,1,'AbsTol', 0,'RelTol',0.1) %inner expectation
end

Answers (1)

Walter Roberson
Walter Roberson on 20 Jun 2023
iyp2=@(tau,ztau,zpa,t)cell2mat(arrayfun(@(tau,ztau,zpa,t)iyP(tau,ztau,zpa,t),tau,ztau,zpa,t,'UniformOutput',0));
1 2 3 4 1 2 3 4 5
You are passing arrayfun an anonymous funciton that expects four parameters. You are passing that function 5 parameters -- the iyP expression first, then tau, ztau, zpa, and t .

Categories

Find more on Special Functions in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!