matlab计算方程fsolve,matlab中关于fsolve解非线性方程组的问题
求E1_mean的程序沒問題,function定義也沒問題,問題出在fsolve。fsolve是為了求每個E1_mean元素對應的x(1),x(2),也就是V和sigmaV,E1_mean包含10000個數據,怎樣才能一次性求出對應的10000對V和sigmaV?? ?matlab為R2013b。程序如下:
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);
總結
以上是生活随笔為你收集整理的matlab计算方程fsolve,matlab中关于fsolve解非线性方程组的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php ftp 大文件,php – 将文
- 下一篇: php禁止国外访问,wordpress