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

2 views (last 30 days)
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

Accepted Answer

Babak
Babak on 26 Sep 2012
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)

More Answers (2)

Verena
Verena on 27 Sep 2012
Dear Babak,
thank you very much for your prompt answer. According to your annotation I changed the MATLAB-code as follows:
  • 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);
  • Expr = subs(Expr,{A,B,C,D,E,F,R},{a,b,c,d,e,f,r});
The substitution works fine now. But, without the use of the quotation marks, I am not allowed to express the assignment '... = 1'. So, how can I go on, solving...
  • solve(Expr == 1,'t') (NOT POSSIBLE)?
Do you have an idea to proceed?
Thanks in advance,
Verena
  1 Comment
Babak
Babak on 27 Sep 2012
You don't need the quotations for t either so say
solve(Expr == 1,t) % instead of solve(Expr == 1,'t')
Here's an example
solve(x + 1 == 2, x)
and the link to MATLAB documentation on this:

Sign in to comment.


Verena
Verena on 2 Oct 2012
Hello again:
Babak, what about the error message: "Conversion to char from logical is not possible."
Here my code once more:
  • 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);
  • Expr = subs(Expr,{A,B,C,D,E,F,R},{a,b,c,d,e,f,r});
  • Expr = simplify(Expr);
  • solve(Expr == 1,t)
Do you know what to do next? Thank you very much for your attention,
Verena
  3 Comments
Verena
Verena on 2 Oct 2012
Hi there,
I get the error in the line with the solve-call;
and further:
  • Error in ==> solve>getEqns at 160 vc = char(v);
  • Error in ==> solve at 84[eqns,vars] = getEqns(varargin{:});
  • Error in ==> circell at 27solve(Expr == 1,t)
Babak
Babak on 3 Oct 2012
Can you get the result of
Expr = simplify(Expr)
in the command window and see if it is right (in ok shape) and try to apply
solve(Expr == 1,t)
on the expression yourself in the command window?
You could also do check in the MATLAB command window on simple expression like this one
syms A B C D E F R t
Expr = (A+B+C+D+E+F+R+t);
a=0.9,b=0.9,c=0,d=1,e=0,f=0,r=0.34
Expr = subs(Expr,{A,B,C,D,E,F,R},{a,b,c,d,e,f,r});
Expr = simplify(Expr);
solve(Expr == 1,t)
I suspect the result of Expr is not good for solve. You may want to try
Expr_vpa = vpa(Expr)
solve(Expr_vpa == 1,t)

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!