使用Newton Raphson方法创建表示滑块曲柄机构位置分析的代码。

时间:2014-10-30 20:22:44

标签: jquery matlab computer-science

我正在尝试在MATLAB中创建滑块曲柄机构的位置分析代码。

我一直在代码中遇到以下错误,我无法理解如何修复它。有人可以给我一些指导。

  
    

未定义函数'solve'表示'char'类型的输入参数。

  
     

SliderCrank中的错误(第20行)solC = solve(eqnC,'xCsol');

代码在

之下
    % Position analysis
% R-RRT
clear % clears all variables from the workspace
clc % clears the command window and homes the cursor
close all % closes all the open figure windows
% Input data
AB=0.5;
BC=1;
phi = pi/4;
% Position of joint A (origin)
xA = 0; yA = 0;
% Position of joint B - position of the driver link
xB = AB*cos(phi);
yB = AB*sin(phi);
% Position of joint C
yC = 0;
% Distance formula: BC=constant
eqnC = '( xB - xCsol )ˆ2 + ( yB - yC )ˆ2 = BCˆ2';
% Solve the above equation
solC = solve(eqnC, 'xCsol' );
% solve symbolic solution of algebraic equations
% Two solutions for xC - vector form

% first component of the vector solC
xC1=eval(solC(1));
% second component of the vector solC
xC2=eval(solC(2));
% eval executes string as an expression or statement
% Select the correct position for C
% for the given input angle
if xC1 > xB
   xC = xC1; 
else xC = xC2; 
end
% if conditionally executes statements
% Angle of the link 2 with the horizontal
phi2 = atan((yB-yC)/(xB-xC));
fprintf('Results \n\n')
% Print the coordinates of B
fprintf('xB = %g (m)\n', xB)
fprintf('yB = %g (m)\n', yB)
% Print the coordinates of C
fprintf('xC = %g (m)\n', xC)
fprintf('yC = %g (m)\n', yC)
% Print the angle phi2
fprintf('phi2 = %g (degrees) \n', phi2*180/pi)

% Graphic of the mechanism
plot([xA,xB],[yA,yB],'r-o',... 
[xB,xC],[yB,yC],'b-o'),...
xlabel('x (m)'),...
ylabel('y (m)'),...
title('positions for \phi = 45 (deg)'),...
text(xA,yA,' A'),...
text(xB,yB,' B'),...
text(xC,yC,' C'),...
axis([-0.2 1.4 -0.2 1.4]),...
grid
% the commas and ellipses (...) after the commands
% were used to execute the commands together
% end of program

1 个答案:

答案 0 :(得分:0)

solve documentation page上显示的第一件事是:

  

solve不接受包含多个输入的字符串输入   参数。在将来的版本中,将不推荐使用字符串输入。在   字符串输入的位置,首先使用syms和。声明变量   将它们作为逗号分隔的列表或向量传递。

所以你需要:

syms xCsol
eqnC = ( xB - xCsol )ˆ2 + ( yB - yC )ˆ2 == BCˆ2; % no single quotes, so not a string, need ==
% Solve the above equation
solC = solve(eqnC, xCsol ); % no single quotes here either