matlab求助!!!! 5
functiont=fengposition(R,th1,L1,L2,L4)t=[L1*cos(th1)+L2*cos(R(1));L1*sin(th1)+L2*sin(...
function t =fengposition(R,th1,L1,L2,L4)t = [L1*cos(th1) + L2*cos(R(1));L1*sin(th1) + L2*sin(R(1)) - R(4);... 64 + R(5)*sin(R(3)) - L1*sin(th1) - L4*sin(R(2));... 24 + R(5)*cos(R(3)) - L1*cos(th1) - L4*cos(R(2));... R(1) - R(2) - 112*pi/180];% 解方程L1 = 32;L2 = 100;L4 = 28; th1 = 0:1/36:2*pi; options = optimset('display','off'); for i = 1:length(th1) Res(i,:) = fsolve(@fengposition,[1 1 1 1 5],options,th1(i),L1,L2,L4);end %求解速度方程w1 = 5;for j = 1:length(th1) A = [-L2*sin(Res(j,1)) 0 0 0 0;L2*cos(Res(j,1)) 0 0 1 0;... 0 -L4*cos(Res(j,2)) Res(j,5)*cos(Res(j,3)) 0 sin(Res(j,3));... 0 L4*sin(Res(j,2)) -Res(5)*sin(Res(j,3)) 0 cos(Res(j,3));1 -1 0 0 0]; B = [w1*L1*sin(th1(j));-w1*L1*cos(th1(j));w1*L1*cos(th1(j));-w1*L1*sin(th1(j));0]; w = A\B; w2(j) = w(1); w4(j) = w(2); w5(j) = w(3); v3(j) = w(4); v5(j) = w(5); end %求解加速度方程for j = 1:length(th1) C = [-L2*sin(Res(j,1)) 0 0 0 0;L2*cos(Res(j,1)) 0 0 1 0;... 0 -L4*cos(Res(j,2)) Res(j,5)*cos(Res(j,3)) 0 sin(Res(j,3));... 0 L4*sin(Res(j,2)) -Res(j,5)*sin(Res(j,3)) 0 cos(Res(j,3));... 1 -1 0 0 0]; D = [-w2(j)^2*L2*cos(Res(j,1)) + w1^2*L1*cos(th1(j));... w2(j)^2*L2*sin(Res(j,1)) + w1^2*L1*sin(th1(j));... w4(j)^2*L4*sin(Res(j,2)) + w5(j)^2*(Res(j,5)*cos(Res(j,3)) -... Res(j,5)*sin(Res(j,3))) + w5(j)*v5(j)*cos(Res(j,3)) -... w1^2*L1*sin(th1(j));w4(j)^2*L4*cos(Res(j,2)) - ... w5(j)^2*(Res(j,5)*cos(Res(j,3))+Res(j,5)*sin(Res(j,3))) - ... w5(j)*v5(j)*sin(Res(j,3)) - w1^2*L1*cos(th1(j));0]; a = C\D; a = C\D; a3(j) = a(4);endt = th1/5; %绘图plot(t,Res(:,4))gridxlim([0 1.25])title('针头位移曲线图')xlabel('时间(s)')ylabel('针头位移') plot(t,v3)gridxlim([0 1.25])title('针头速度曲线图')xlabel('时间(s)')ylabel('针头速度') plot(t,a3)gridxlim([0 1.25])title('针头加速度曲线图')xlabel('时间(s)')ylabel('针头加速度')
展开
追问
是直接运行的吗= =
我还是出现
>> fengposition(R, th1, L1, L2, L4)
未定义函数或变量 'R'。
追答
这是两个M文件,一个是函数,另一个是程序,你能明白吗?
我发给你吧
这个是函数
function t =fengposition(R,th1,L1,L2,L4)
t = [L1*cos(th1) + L2*cos(R(1)); L1*sin(th1) + L2*sin(R(1)) - R(4);...
64 + R(5)*sin(R(3)) - L1*sin(th1) - L4*sin(R(2));...
24 + R(5)*cos(R(3)) - L1*cos(th1) - L4*cos(R(2));...
R(1) - R(2) - 112*pi/180];
这个是程序,你用我的,要不你的有问题
clc;
clear;
close all;
% 解方程
L1 = 32;
L2 = 100;
L4 = 28;
th1 = 0:1/36:2*pi;
options = optimset('display','off');
for i = 1:length(th1)
Res(i,:) = fsolve(@fengposition,[1 1 1 1 5],options,th1(i),L1,L2,L4);
end
%求解速度方程
w1 = 5;
for j = 1:length(th1)
A = [-L2*sin(Res(j,1)) 0 0 0 0;L2*cos(Res(j,1)) 0 0 1 0;...
0 -L4*cos(Res(j,2)) Res(j,5)*cos(Res(j,3)) 0 sin(Res(j,3));...
0 L4*sin(Res(j,2)) -Res(5)*sin(Res(j,3)) 0 cos(Res(j,3));1 -1 0 0 0];
B = [w1*L1*sin(th1(j));-w1*L1*cos(th1(j));
w1*L1*cos(th1(j));-w1*L1*sin(th1(j));0];
w = A\B;
w2(j) = w(1);
w4(j) = w(2);
w5(j) = w(3);
v3(j) = w(4);
v5(j) = w(5);
end
%求解加速度方程
for j = 1:length(th1)
C = [-L2*sin(Res(j,1)) 0 0 0 0;L2*cos(Res(j,1)) 0 0 1 0;...
0 -L4*cos(Res(j,2)) Res(j,5)*cos(Res(j,3)) 0 sin(Res(j,3));...
0 L4*sin(Res(j,2)) -Res(j,5)*sin(Res(j,3)) 0 cos(Res(j,3));...
1 -1 0 0 0];
D = [-w2(j)^2*L2*cos(Res(j,1)) + w1^2*L1*cos(th1(j));...
w2(j)^2*L2*sin(Res(j,1)) + w1^2*L1*sin(th1(j));...
w4(j)^2*L4*sin(Res(j,2)) + w5(j)^2*(Res(j,5)*cos(Res(j,3))-Res(j,5)*sin(Res(j,3)))+w5(j)*v5(j)*cos(Res(j,3))-w1^2*L1*sin(th1(j));...
w4(j)^2*L4*cos(Res(j,2)) - w5(j)^2*(Res(j,5)*cos(Res(j,3))+Res(j,5)*sin(Res(j,3)))-w5(j)*v5(j)*sin(Res(j,3))-w1^2*L1*cos(th1(j));...
0];
a = C\D;
a = C\D;
a3(j) = a(4);
end
t = th1/5;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询