MATLAB: Usage of SUBS for the calculation of the intersection of a circle and an ellipse

subs

Dear MATLAB-community,
I'm trying to solve the problem to find the intersection of a circle (param. repr. x=C+R*(1-T^2)/(1+T^2); y=D+R*(2*T)/(1+T^2)) and a ellipse ((x-E)^2/A^2 + (y-F)^2/B^2 = 1), where the center points (C,D) and (E,F) as well as the radii may alter during the program.
Since MATLAB wont supply a general solution in terms of 't' for the symbolic elliptic equation, when the parameter representation of the circle is plugged in, I tried to substitute the symbols when known (given: a b c d e f r), like in the following code (extract of function circell):
  • syms A B C D E F R T
  • Expr = '(C+R*(1-(T*T))/(1+(T*T)) – E)*(C+R*(1-(T*T))/(1+(T*T)) – E)/(A*A) + (D+R*2*T/(1+(T*T)) – F)*(D+R*2*T/(1+(T*T)) – F)/(B*B) = 1';
  • Expr = subs(Expr,A,a);
  • Expr = subs(Expr,B,b);
  • Expr = subs(Expr,C,c);
  • Expr = subs(Expr,D,d);
  • Expr = subs(Expr,E,e);
  • Expr = subs(Expr,F,f);
  • Expr = subs(Expr,R,r);
  • solve(Expr,'t');
In case of (a=0.9,b=0.9,c=0,d=1,e=0,f=0,r=0.34), when substituting 'D' by 'd' it results in the following error:
  • ??? Error using ==> mupadfeval at 28Error: Illegal operand [subs];during evaluation of 'mlsubs'
  • Error in ==> sym.subs>oneSubs at 263 G = sym(mupadfeval('mlsubs', charcmd(G), [x '=' charcmd(y)]));
  • Error in ==> sym.subs>mupadsubs at 162 G = oneSubs(G,X{k},Y{k},yscalar(k));
  • Error in ==> sym.subs at 124G = mupadsubs(F,X,Y);
  • Error in ==> sym.subs at 128 G = subs(F,Y,X,0);
  • Error in ==> circell at 25Expr = subs(Expr,E,e);
  • Error in ==> CCT_BP at 154 [insect,T] = circell(x(1),x(2),rad, E(k).x,E(k).y,E(k).a,E(k).b);
What can do to get this relatively simple problem solved?
I greatly appreciate any help and advice.
Best regards,
Verena

Best Answer

first, your equation involves CAPITALIZED T while you are trying to solve it for little t. You need to stay consistent.
second, use
Expr = (C+R*(1-(T*T))/(1+(T*T)) - E)*(C+R*(1-(T*T))/(1+(T*T)) - E)/(A*A) + (D+R*2*T/(1+(T*T)) - F)*(D+R*2*T/(1+(T*T)) - F)/(B*B) = 1
instead of
Expr = '(C+R*(1-(T*T))/(1+(T*T)) - E)*(C+R*(1-(T*T))/(1+(T*T)) - E)/(A*A) + (D+R*2*T/(1+(T*T)) - F)*(D+R*2*T/(1+(T*T)) - F)/(B*B) = 1'
(without quotes I mean)