matlab编程出错,S0=50;K=5;r=0.2;sigma=0.3;T=0.5;a=428.5912b=246.7252c=-801.6449for i=1:10; for j=1:100; A(i,j)=S0*exp((r-sigma^2/2)*T+sigma*random_A(i,j)*sqrt(T)); if A(i,j)>K; and b*A(i,j)+c *(A(i,j)^2)-A(i,j)>-K-a; B(i,j)=0; else B(i,j)=a +b*A(i
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/26 07:03:49
matlab编程出错,S0=50;K=5;r=0.2;sigma=0.3;T=0.5;a=428.5912b=246.7252c=-801.6449for i=1:10; for j=1:100; A(i,j)=S0*exp((r-sigma^2/2)*T+sigma*random_A(i,j)*sqrt(T)); if A(i,j)>K; and b*A(i,j)+c *(A(i,j)^2)-A(i,j)>-K-a; B(i,j)=0; else B(i,j)=a +b*A(i
matlab编程出错,
S0=50;
K=5;
r=0.2;
sigma=0.3;
T=0.5;
a=428.5912
b=246.7252
c=-801.6449
for i=1:10;
for j=1:100;
A(i,j)=S0*exp((r-sigma^2/2)*T+sigma*random_A(i,j)*sqrt(T));
if A(i,j)>K;
and b*A(i,j)+c *(A(i,j)^2)-A(i,j)>-K-a;
B(i,j)=0;
else B(i,j)=a +b*A(i,j)+c*(A(i,j) ^2);
end
end
end
A
B
Error using &
Inputs must have the same size.
matlab编程出错,S0=50;K=5;r=0.2;sigma=0.3;T=0.5;a=428.5912b=246.7252c=-801.6449for i=1:10; for j=1:100; A(i,j)=S0*exp((r-sigma^2/2)*T+sigma*random_A(i,j)*sqrt(T)); if A(i,j)>K; and b*A(i,j)+c *(A(i,j)^2)-A(i,j)>-K-a; B(i,j)=0; else B(i,j)=a +b*A(i
错误在于逻辑与&的使用,正确的代码如下,纠正错误的地方已用%注释说明
S0=50;
K=5;
r=0.2;
sigma=0.3;
T=0.5;
a=428.5912
b=246.7252
c=-801.6449
random_A=ones(10,100);%从你的错误提示,看出,你的程序之前已经给random_A赋值了
for i=1:10;
for j=1:100;
A(i,j)=S0*exp((r-sigma^2/2)*T+sigma*random_A(i,j)*sqrt(T));
if A(i,j)>K && b*A(i,j)+c *(A(i,j)^2)-A(i,j)>-K-a; %这是你出错的地方
B(i,j)=0;
else B(i,j)=a +b*A(i,j)+c*(A(i,j) ^2);
end
end
end
A
B
希望对你有帮助,欢迎交流!