把x、y用x(1)、x(2)表示,指定初值求解即可:
>> fsolve(@(x)x(1)^2+x(2)^2,[1 1])Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems;using Levenberg-Marquardt algorithm instead. > In fsolve at 319Optimization terminated: the first-order optimality measure is less than 1e-4 times options.TolFun.ans = 1.0e-003 * 0.2447 0.2447其中,警告可以无视。
是否可以解决您的问题?
m文件修改如下:
function a=myfun(x)
k=340;
r=0.08;
t=150/365;
c=29.8299;
p=8.8335;
a=blsprice(x(1),k,r,t,x(2))-[c,p];这样从语法上来说,不存在错误了;但是运行结果似乎找不到解,这就取决于:
①这个模型是否有解,②
你给的初值是否在解的附近。
不必用符号函数, 另外写一个函数,如:
function F = myfun(x)
F = sin(x);