I have a set of geometric relationships where the independent variable is the angle theta and the dependent variable s2 is given by the following code. I am attempting to use code to write my anonymous function for fzero but I get an error message "Undefined function or method 'eq' for input arguments of type 'function_handle'" Any suggestions? Thank you, Scott
function s2_function(theta)% =========================================================================
% system constants & initial values
P0 = [0,0]; p1 = [6,2]; P4 = [18,15]; r1 = 4; r2 = 4; r4 = 10; s1 = sqrt((P0(1)-p1(1))^2 + (P0(2)-p1(2))^2); s4 = sqrt((P4(1)-p1(1))^2 + (P4(2)-p1(2))^2); bd = 19.65585; Lb = bd*pi; beta = 0.2662517; theta = theta*pi/180; %%=========================================================================
% variables solved directly
P1 = P0 + [s1*cos(theta), s1*sin(theta)];alpha1 = theta-beta; alpha2 = asin((P4(2)-P1(2))/s4)-alpha1; gamma2 = asin((r1+r4)/s4); T3 = P1 + [r1*sin(gamma2-alpha2-alpha1),r1*cos(gamma2-alpha2-alpha1)]; T4 = P4 - [r4*sin(gamma2-alpha2-alpha1),r4*cos(gamma2-alpha2-alpha1)];%%=========================================================================% variables solved indirectly
syms s2 P2 = P1 + [s2*cos(alpha1),s2*sin(alpha1)]; gamma1 = asin((r1-r2)/s2); x1 = gamma1 + alpha1; T1 = P1 + [r1*sin(x1), -r1*cos(x1)]; T2 = P2 + [r2*sin(x1), -r2*cos(x1)]; [M] = CircleIntersect(P4,r4,P2,r2); T5 = M(1,:); T6 = M(2,:); l1 = sqrt((T1(1)-T2(1))^2 + (T1(2)-T2(2))^2); l2 = r1*((2*pi)- acos(1-(((T1(1)-T3(1))^2 + (T1(2)-T3(2))^2)/(2*r1^2)))); l3 = sqrt((T3(1)-T4(1))^2 + (T3(2)-T4(2))^2); l4 = ArcLength(T4,T5,r4); l5 = ArcLength(T5,T6,r2); l6 = ArcLength(T6,T2,r2);%%=========================================================================% Solve the system of equations
fs2 = Lb-l1-l2-l3-l4-l5-l6; ss2 = char(fs2); fhs2 = strcat('@(s2)',ss2); S2 = fzero(fhs2,16); sprintf('s2 equals: %d',S2) endfunction [M]=CircleIntersect(P1,r1,P2,r2) dx = P2(1)-P1(1); dy = P2(2)-P1(2); alpha = atan(dy/dx); s = sqrt((P1(1)-P2(1))^2 + (P1(2)-P2(2))^2); x = (s^2-r1^2-r2^2)/(2*r1*r2); y = r2/r1;alpha2 = atan((1-x^2)^(1/2)/(x+y));alpha1 = asin(y*sin(alpha2));gamma1 = alpha - alpha1;gamma2 = alpha + alpha1;% =========================================================================% Define intersecting points (T1 & T2)
T1 = P1 + [r1*cos(gamma1), r1*sin(gamma1)]; T2 = P1 + [r1*cos(gamma2), r1*sin(gamma2)]; M = [T1;T2];function [len] = ArcLength(P1,P2,r)========================================================================= c = sqrt((P1(1)-P2(1))^2 + (P1(2)-P2(2))^2);theta = acos(1-c.^2./(2.*r.^2)); len = r.*theta;
Best Answer