请问 批量求解 两变量两方程的方程组的下列代码错在哪里。

函数:
function f= BSsolve(x,y)
Price=xlsread('Option.xlsx',1,'A2:A76');
Rate=xlsread('Option.xlsx',1,'C2:C76');
Volatility=xlsread('Option.xlsx',1,'E2:E76');
Value=xlsread('Option.xlsx',1,'F2:F76');
Delta=xlsread('Option.xlsx',1,'G2:G76');
f=[blsprice(Price,x,Rate, y,Volatility)-Value;
blsdelta(Price,x,Rate, y,Volatility)-Delta];
end
命令:
>> x0=xlsread('Option.xlsx',1,'H2:H76');
>> y0=xlsread('Option.xlsx',1,'I2:I76');
>> options=optimset('display','iter','MaxFunEvals',3000);
>> [x,fval]=fsolve(@BSsolve,x0,y0,options)
结果显示出错:
Undefined function 'lt' for input arguments of type 'struct'.
Error in blscheck (line 84)
if any(Time(:) < 0)
Error in blsprice (line 96)
blscheck(S, X, r, T, sig, q);
Error in BSsolve (line 9)
f=[blsprice(Price,x,Rate, y,Volatility)-Value;
Error in fsolve (line 241)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
对于结果有些疑问,Undefined function 'lt'是说lt没定义吗?我整个过程里好像没有lt?
另外,请问整体的求解思路错在了哪里?谢谢!

 Réponse acceptée

nexipa
nexipa le 23 Nov 2022

0 votes

lt 就是运算符 < 的函数名。help lt 便清楚了
之所以出现这个错误,是因为 blscheck 函数内有一个if any(Time(:) < 0)的判断,而这里似乎 Time(:)是一个结构体,而运算符 < 不支持结构体,所以报错。可能你又要问,我的代码里没有 blscheck 怎么会报这个函数的错呢,这是因为你调用了 blsprice 函数,这个函数内部会对输入变量的合法性做check,这个check函数就是 blscheck 。而blscheck 检查到 Time 是一个结构体,而 Time 对应的是 blsprice 第4个参数,也就是你这里的 y 是一个结构体。
另外,fsolve 要求方程函数 BSsolve 只有一个自变量,如果是多个未知数,应该写成向量未知数,而你这里 BSsolve 有两个变量,这也是有问题的。前面得到的 y 是一个结构体很可能就是 fsolve(@BSsolve,x0,y0,options) 这里造成的

Plus de réponses (0)

Catégories

En savoir plus sur 数学 dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!