你能告诉我在哪里我必须把我的起始值放在下面提到的代码中假设我想解决它的初始值-2p为theta和phi
function myFcn
X = fsolve(@F, 2*pi*rand(2,1))
end
function val = F(X)
th = X(1);
ph = X(2);
val = [
cos(2*th) + sin(2*th)
cos(ph).^2.*cos(th).^2 + cos(ph).^2.*cos(2*th).*sin(2*th) + cos(ph).^2.*cos(2*th) + sin(2*ph).*cos(2*ph).*cos(2*th).*sin(2*th) + sin(2*ph).*cos(2*ph).*sin(th).^2 + sin(2*ph).*cos(2*ph).*sin(2*th) + 0.4837
cos(2*ph).*cos(th).^2.*sin(2*ph) + cos(2*th).*sin(ph).^2.*sin(2*th) + cos(2*ph).*cos(2*th).*sin(2*ph).*sin(2*th) + cos(2*ph).*cos(2*th).*sin(2*ph) + sin(ph).^2.*sin(2*th) - 1
cos(th).^2.*sin(2*ph) - cos(2*ph).*sin(th).^2 - cos(2*ph).*sin(2*th) + cos(2*th).*sin(2*ph) - cos(2*ph).*cos(2*th).*sin(2*th) + cos(2*th).*sin(2*ph).*sin(2*th)
];
end
thankx
答案 0 :(得分:0)
fsolve
的第二个参数是X的初始值。你的意思是-2 * pi作为theta和phi的初始值吗?如果是这样,您将执行以下操作:
function myFcn
X = fsolve(@F, [-2*pi, -2*pi])
end
您可以创建myFcn,以便在函数调用中指定起始值,如下所示:
function myFcn(initial_theta, initial_phi)
X = fsolve(@F, [initial_theta, initial_phi])
end
然后当你调用这个函数时,你可以调用
myFcn(-2*pi, -2*pi)
,
或者如果你以后决定要尝试theta = pi和phi = 0的初步猜测,你可以打电话
myFcn(pi, 0)