Usage of SUBS for the calculation of the intersection of a circle and an ellipse
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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)
0 Comments
More Answers (2)
Verena
on 2 Oct 2012
3 Comments
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)
See Also
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!