function [t,y]=ASModel(tspan,y0,theta,kx,ky,r0,s0,a,zeta,lambda,l,w) % This function solves the dynamical system for modelling the paddling of % two flagella on the same cell, the model is the anisotropic spring model. % % y = [phi_1,phi_2,r1,r2] = solution % tspan = the time interval to be solved % y0=[phi_1;phi_2;r1;r2] = initial condition at t0 % theta = the angle between the motor in the cell and the flagella bead % kx = spring constant along x direction % ky = spring constant along y direction % r0 = equilibrium radius for radial spring r % s0 = equilibrium radius for radial spring s % a = radius of the flagella bead % lambda = [r-spring const, s-spring const, eta-spring const] % l = distance between effective center of flagella % w = [w1, w2]=intrinsic angular frequency % Parameter switch_s is used to include or exclude the s spring %========================================================================== switch_s=0; % 1 if spring s exists, 0 if s is rigid Atol=1e-13;Rtol=1e-11; % absolute and relative tolerance for solver kr=lambda(1); ks=lambda(2); eta=lambda(3); w1=w(1); w2=w(2); options=odeset('AbsTol',Atol,'RelTol',Rtol); [t,y]=ode45(@derivative,tspan,y0,options); switch switch_s case 0 s1_=ones(length(t),1)*s0; s2_=s1_; case 1 Q_=@(a,b)(kx-ky)/2*cos(a+b+2*theta)+(kx+ky)/2*cos(a-b); U12_=-Q_(y(:,1),y(:,2)-2*theta)./(ks+eta+Q_(y(:,1),y(:,1))); U21_=-Q_(y(:,2)-2*theta,y(:,1))./(ks+eta+Q_(y(:,2)-2*theta,y(:,2)-2*theta)); E12_=s0*(ks+eta)./(ks+eta+Q_(y(:,1),y(:,1)))-eta*(y(:,3)-r0)./(ks+eta+Q_(y(:,1),y(:,1))); E21_=s0*(ks+eta)./(ks+eta+Q_(y(:,2)-2*theta,y(:,2)-2*theta))-eta*(y(:,4)-r0)./(ks+eta+Q_(y(:,2)-2*theta,y(:,2)-2*theta)); s1_=-(E12_ - E21_.*U12_)./(U12_.*U21_ - 1); s2_=-(E21_ - E12_.*U21_)./(U12_.*U21_ - 1); end y=[y s1_ s2_]; function dydt=derivative(t,y) % solve for explicit expression for each derivative symbolically % A=[ r1 X12 0 Y12; % X21 r2 Y21 0; % 0 L12 1 T12; % L21 0 T21 1;]; % b=[ I12; % I21; % O12; % O21]; % x=A\b; %================================================================== % Define functions: sin, cos, N, M, A, B, G, Q used in Equations c=@(a,b) cos(y(a)-y(b)); s=@(a,b) sin(y(a)-y(b)); m=@(a,b,n) (-1)^(n-1)*l*sin(y(a))+y(2+b)*sin(y(a)-y(b)); n=@(a,b,n) (-1)^n*l*cos(y(a))+y(2+a)-y(2+b)*cos(y(a)-y(b)); A=@(a,b,n) (-1)^(n-1)*l*y(2+b)*sin(y(b))+y(2+a)*y(2+b)*sin(y(a)-y(b)); B=@(a,b,n) (-1)^n*l*cos(y(b))+y(2+a)*cos(y(a)-y(b))-y(2+b); G=@(a,b)(ky-kx)/2*sin(a+b+2*theta)-(ky+kx)/2*sin(a-b); Q=@(a,b)(kx-ky)/2*cos(a+b+2*theta)+(kx+ky)/2*cos(a-b); %================================================================== % Put in labels for 1 and 2 K=3/4*a; r1=y(3); r2=y(4); c12=c(1,2); c21=c(2,1); s12=s(1,2); s21=s(2,1); g12=G(y(1),y(2)-2*theta); g21=G(y(2)-2*theta,y(1)); g11=G(y(1),y(1)); g22=G(y(2)-2*theta,y(2)-2*theta); r12=sqrt(l^2-2*l*(r1*cos(y(1))-r2*cos(y(2)))+r1^2+r2^2-2*r1*r2*c12); m121=m(1,2,1); % M_{12}^+ m212=m(2,1,2); % M_{21}^- n121=n(1,2,1); n212=n(2,1,2); a121=A(1,2,1); a212=A(2,1,2); b121=B(1,2,1); b212=B(2,1,2); %================================================================== switch switch_s case 0 s1=s0; s2=s0; case 1 % Solve expression for s1,s2 explicitly % A=[ 1 U12; % U21 1]; % b=[ E12; % E21]; % x=A\b; U12=-Q(y(1),y(2)-2*theta)/(ks+eta+Q(y(1),y(1))); U21=-Q(y(2)-2*theta,y(1))/(ks+eta+Q(y(2)-2*theta,y(2)-2*theta)); E12=s0*(ks+eta)/(ks+eta+Q(y(1),y(1)))-eta*(r1-r0)/(ks+eta+Q(y(1),y(1))); E21=s0*(ks+eta)/(ks+eta+Q(y(2)-2*theta,y(2)-2*theta))-eta*(r2-r0)/(ks+eta+Q(y(2)-2*theta,y(2)-2*theta)); s1=-(E12 - E21*U12)/(U12*U21 - 1); s2=-(E21 - E12*U21)/(U12*U21 - 1); end % Define elements for matrix using coefficients from equations X12=-K/r12*(m121*a121/r12^2+r2*c12); Y12=-K/r12*(m121*b121/r12^2+s21); X21=-K/r12*(m212*a212/r12^2+r1*c21); Y21=-K/r12*(m212*b212/r12^2+s12); L12=-K/r12*(n121*a121/r12^2+r2*s12); T12=-K/r12*(n121*b121/r12^2+c12); L21=-K/r12*(n212*a212/r12^2+r1*s21); T21=-K/r12*(n212*b212/r12^2+c21); I12=r0*w1+s1*s2/(zeta*r1)*g12-s1^2/(zeta*r1)*g11; I21=r0*w2+s1*s2/(zeta*r2)*g21-s2^2/(zeta*r2)*g22; O12=-(kr+eta)/zeta*(r1-r0)-eta/zeta*(s1-s0); O21=-(kr+eta)/zeta*(r2-r0)-eta/zeta*(s2-s0); dydt =[ (I21*X12 - I12*r2 + I12*L12*Y21 - O12*X12*Y21 + O21*Y12*r2 + I21*L12*T21*Y12 - I21*T12*T21*X12 - L12*O21*Y12*Y21 + O21*T12*X12*Y21 + I12*T12*T21*r2 - O12*T21*Y12*r2)/(X12*X21 - r1*r2 + L12*Y21*r1 + L21*Y12*r2 - L12*L21*Y12*Y21 + L12*T21*X21*Y12 + L21*T12*X12*Y21 - T12*T21*X12*X21 + T12*T21*r1*r2) (I12*X21 - I21*r1 + I21*L21*Y12 - O21*X21*Y12 + O12*Y21*r1 + I12*L21*T12*Y21 - I12*T12*T21*X21 - L21*O12*Y12*Y21 + O12*T21*X21*Y12 + I21*T12*T21*r1 - O21*T12*Y21*r1)/(X12*X21 - r1*r2 + L12*Y21*r1 + L21*Y12*r2 - L12*L21*Y12*Y21 + L12*T21*X21*Y12 + L21*T12*X12*Y21 - T12*T21*X12*X21 + T12*T21*r1*r2) (O12*X12*X21 - I12*L12*X21 + I21*L12*r1 - O12*r1*r2 - I21*L12*L21*Y12 + I21*L21*T12*X12 + L12*O21*X21*Y12 - O21*T12*X12*X21 - I12*L21*T12*r2 + L21*O12*Y12*r2 + O21*T12*r1*r2)/(X12*X21 - r1*r2 + L12*Y21*r1 + L21*Y12*r2 - L12*L21*Y12*Y21 + L12*T21*X21*Y12 + L21*T12*X12*Y21 - T12*T21*X12*X21 + T12*T21*r1*r2) (O21*X12*X21 - I21*L21*X12 + I12*L21*r2 - O21*r1*r2 - I12*L12*L21*Y21 + I12*L12*T21*X21 + L21*O12*X12*Y21 - O12*T21*X12*X21 - I21*L12*T21*r1 + L12*O21*Y21*r1 + O12*T21*r1*r2)/(X12*X21 - r1*r2 + L12*Y21*r1 + L21*Y12*r2 - L12*L21*Y12*Y21 + L12*T21*X21*Y12 + L21*T12*X12*Y21 - T12*T21*X12*X21 + T12*T21*r1*r2)]; end end