想问一下,为什么fsolve函数的使用出错了
function t=cc(th,th2)
t=@(th)[L2*cos(th2)+L3*cos(th(1))-L4*cos(th(2))-L1; L2*sin(th2)+L3*sin(th(1))-L4*sin(th(2))];
L1=input('输入机架长度 L1=');
L2=input('输入曲柄长度(主动件) L2=');
L3=input('输入连杆长度 L3=');
L4=input('输入输入从动杆长度 L4=');
w2=input('输入主动件角速度 w2=');
th2=[0:1/6:2]*pi; %曲柄输入角度从0至360度,步长为pi/6
th34=zeros(length(th2),2); %建立一个N行2列的零矩阵,第一列存放θ3,第二列存放θ4
options=optimset('display','iter');
for m=1:length(th2) %建立for循环,求解θ3,θ4
th34(m,:)=fsolve(@cc,[1 1],options,th2(m),L2,L3,L4,L1);
end
命令行显示的错误:
出错 fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});
出错 cc (line 18)
th34(m,:)=fsolve(@cc,[1;1],options,th2(m),L2,L3,L4,L1);
原因:
Failure in initial objective function evaluation. FSOLVE cannot
continue.
function t=cc(th,th2)
t=@(th)[L2*cos(th2)+L3*cos(th(1))-L4*cos(th(2))-L1; L2*sin(th2)+L3*sin(th(1))-L4*sin(th(2))];
L1=input('输入机架长度 L1=');
L2=input('输入曲柄长度(主动件) L2=');
L3=input('输入连杆长度 L3=');
L4=input('输入输入从动杆长度 L4=');
w2=input('输入主动件角速度 w2=');
th2=[0:1/6:2]*pi; %曲柄输入角度从0至360度,步长为pi/6
th34=zeros(length(th2),2); %建立一个N行2列的零矩阵,第一列存放θ3,第二列存放θ4
options=optimset('display','iter');
for m=1:length(th2) %建立for循环,求解θ3,θ4
th34(m,:)=fsolve(@cc,[1 1],options,th2(m),L2,L3,L4,L1);
end
命令行显示的错误:
出错 fsolve (line 242)
fuser = feval(funfcn{3},x,varargin{:});
出错 cc (line 18)
th34(m,:)=fsolve(@cc,[1;1],options,th2(m),L2,L3,L4,L1);
原因:
Failure in initial objective function evaluation. FSOLVE cannot
continue.