700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > matlab计算方程fsolve matlab中关于fsolve解非线性方程组的问题

matlab计算方程fsolve matlab中关于fsolve解非线性方程组的问题

时间:2024-03-12 08:53:56

相关推荐

matlab计算方程fsolve matlab中关于fsolve解非线性方程组的问题

求E1_mean的程序没问题,function定义也没问题,问题出在fsolve。fsolve是为了求每个E1_mean元素对应的x(1),x(2),也就是V和sigmaV,E1_mean包含10000个数据,怎样才能一次性求出对应的10000对V和sigmaV? matlab为Rb。程序如下:

globalE1_mean

beta01=zeros(1,10000);beta01(1,: )=0.00000901;beta1=0.93095390;beta2=0.06165110;r=zeros(1,10000);r(1,: )=0.00196230; theta=zeros(1,10000);theta(1,: )=-0.00032120 ;path1=zeros(245,10000); path1(1,: )=0.001218392 ^2;R1=zeros(245,10000);

for i=2:245

path1(i,: )=beta01+beta1*path1(i-1,: )+beta2*path1(i-1,: ).*(randn(1,10000)-theta).^2 ;

R1(i,: )=r+(path1(i,: ).^0.5).*randn(1,10000);

end

R1_cumsum=cumsum(R1,1);

E1=zeros(244,10000);

for i=1:244

E1(i,: )=180970333.4*exp(R1_cumsum(i+1,: ));

end

E1_mean=mean(E1,1);

function F = blsprice(x)

globalE1_mean j

% x(1) : V; 银行总资产

% x(2) : sigmav; 资产波动率

rf = 3.6/100; %无风险利率

B = 2055510000000.00 /(10^12) ; %股权的执行价格 B/(10^12)

sigmaE = 0.545240875;

T = 1; % 时间周期

t = 0; % 时间

forj=1:10000

d1 = (log(x(1)/(0.97*B))+rf*(T-t)+x(2)^2*(T-t)/2) / (x(2)*sqrt(T-t));

d2 = d1-x(2)*sqrt(T-t);

F(1) = x(1)* normcdf(d1) - 0.97*B* normcdf(d2) -(E1_mean(1,j))/10^12;

F(2) = x(1)*normcdf(d1)*x(2) - sigmaE*(E1_mean(1,j))/10^12;

end

globalj

V1=zeros(1,10000);

sigmaV1=zeros(1,10000);

forj=1:10000

x0 = [1.2;1];

options=optimset('Display','off','MaxFunEvals',10000,'MaxIter',10000);

[x,fval] = fsolve(@blsprice,x0,options);

V1(1,j)=x(1);

sigmaV1(1,j)=x(2);

end

程序运行后显示Error using erfc

Input must be real and full.

Error in normcdf>localnormcdf (line 124)

p(todo) = 0.5 * erfc(-z ./ sqrt(2));

Error in normcdf (line 46)

[varargout{1:max(1,nargout)}] =localnormcdf(uflag,x,varargin{:});

Error in blsprice (line 20)

F(1) = x(1)* normcdf(d1) - 0.97*B*normcdf(d2) -(E1_mean(1,j))/10^12;

Error in trustnleqn (line 200)

F= feval(funfcn{3},reshape(xTrial,sizes.xRows,sizes.xCols),varargin{:});

Error in fsolve (line 366)

[x,FVAL,JACOB,EXITFLAG,OUTPUT,msgData]=...

Error in solve_blsprice (line 9)

[x,fval] = fsolve(@blsprice,x0,options);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。