%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 정해져서 아는 벡터길이
r1=input('r1값입력')
r2=input('r2값입력')
r4=input('r4값입력')
r5=input('r5값입력')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Guess
theta2=210;
r3=22.5;
theta5=0;
r6=40;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 정해져서 아는 벡터의 각각도값
theta1=90 ;
theta6=180;
n=1;
t=1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% input
for theta4= 0: 10 : 360
theta3=theta4;
while t~=0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Scalar equations
f_freudenstein=[r1*cosd(theta1)+r2*cosd(theta2)+r3*cosd(theta3) ;
r4*cosd(theta4)+r5*cosd(theta5)+r6*cosd(theta6) ;
r1*sind(theta1)+r2*sind(theta2)+r3*sind(theta3) ;
r4*sind(theta4)+r5*sind(theta5)+r6*sind(theta6)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Jacobian matrix
f_jacobian=[-r2*sind(theta2) cosd(theta3) 0 0 ;
0 0 -r5*sind(theta5) cosd(theta6) ;
r2*cosd(theta2) sind(theta3) 0 0 ;
0 0 r5*cosd(theta5) sind(theta6) ] ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Newton-Rapshon's Method - error
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 초기값을 주고 오차가 가장 적도록 하게 하는 방법
f_newton_rapshon_error=(-1)*inv(f_jacobian)*(f_freudenstein);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Newton-Rapshon's Method - root
theta2new=theta2+(f_newton_rapshon_error(1));
r3new=r3+f_newton_rapshon_error(2);
theta5new=theta5+(f_newton_rapshon_error(3));
r6new=r6+f_newton_rapshon_error(4);
theta2=theta2new;
r3=r3new;
theta5=theta5new;
r6=r6new;
theta2new=0;
r3new=0;
theta5new=0;
r6new=0;
%%%%%%%%%%%%%%%%%%%set error range
if ((f_newton_rapshon_error(1,1)<10^(-5) & f_newton_rapshon_error(1,1)>-10^(-5))...
& (f_newton_rapshon_error(2,1)<10^(-5) & f_newton_rapshon_error(2,1)>-10^(-5))...
& (f_newton_rapshon_error(3,1)<10^(-5) & f_newton_rapshon_error(3,1)>-10^(-5))...
& (f_newton_rapshon_error(4,1)<10^(-5) & f_newton_rapshon_error(4,1)>-10^(-5)));
t=0 ;
else
t=1 ;
end
end
theta3=theta4;
t=1;
n=n+1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Drawing graph
ox=0; oy=0;
Ax=0; Ay=13 ;
Bx=Ax+r2*cosd(theta2); By=Ay+r2*sind(theta2) ;
Cx=Bx+r3*cosd(theta3); Cy=By+r3*sind(theta3) ;
Dx=Cx+r4*cosd(theta4); Dy=Cy+r4*sind(theta4) ;
Ex=Dx+r5*cosd(theta5); Ey=Dy+r5*sind(theta5) ;
Fx=Ex+r6*cosd(theta6); Fy=0 ;
L1x=[ox Ax] ; L1y=[oy Ay] ;
L2x=[Ax Bx] ; L2y=[Ay By] ;
L3x=[Bx Cx] ; L3y=[By Cy] ;
L4x=[Cx Dx] ; L4y=[Cy Dy] ;
L5x=[Dx Ex] ; L5y=[Dy Ey] ;
L6x=[Ex Fx] ; L6y=[Ey Fy] ;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
set(gca , 'visible' , 'on');
plot(L1x, L1y, L2x, L2y, L3x, L3y, L4x, L4y, L5x, L5y, L6x, L6y);
hold on
grid on
drawnow;
end
Table1=[Ax Ay;
Bx By;
Cx Cy;
Dx Dy;
Ex Ey;
Fx Fy];
Table2=[L1x L1y;
L2x L2y;
L3x L3y;
L4x L4y;
L5x L5y;
L6x L6y];
fid1=fopen('T_1.txt','w')
fid2=fopen('T_2.txt','w')
fprintf(fid1,'Ax,y Bx,y Cx,y Dx,y Ex,y Fx,y \n \n');
fprintf(fid1,'%8.2f %8.2f\n','Table1');
fprintf(fid2,'L1xy, L2xy, L3xy, L4xy, L5xy, L6xy \n \n');
fprintf(fid2,'%8.2f %8.2f\n','Table2');
fclose(fid1);
fclose(fid2);
여기서 제가 스크립트 파일로 만들었는데 이걸 function 함수파일? 써서 바꾸라든데 제가 그걸모르네여
혹시 function 넣어서 교정좀 가능하십니까 ㅜㅜㅜ
살려주십셔 ㅜㅜ