Use vpasolve for vectors of two inputs.
14 views (last 30 days)
Show older comments
Hello,
I have the inputs A and B as vectors. Moreover I got the constants c and d. My equotations look like (c-d-x)^2+y^2=d^2 and x^2+(c-d-y)^2=d^2. Those should give for each row of the input vector two pairs of solutions (x(1),y(1) and x(2),y(2)).
I found a solution with a for loop, but vpasolve has to run a lot of times, which consumes a lot of time:
A=[1,2,3,4];
B=[5,6,7,8];
c=9;
d=10;
%those numbers are just for the example and do not lead to real solution
for i=1:length(A)
clear x
clear y
syms x y
S = vpasolve([(c-A(i)-x)^2+y^2==d^2, x^2+(c-B(i)-y)^2==d^2],[x,y]);
L(1,:,i)=[double(S.x(1));double(S.y(1))];
L(2,:,i)=[double(S.x(2));double(S.y(2))];
end
This however takes some time for a long input vector, so I do wonder if it is possible to speed this up (maybe get rid of the for-loop)?
Thank you in advance.
0 Comments
Accepted Answer
Walter Roberson
on 26 Jun 2015
A = [1, 2, 3, 4];
B = [5, 6, 7, 8];
c=9;
d=10;
syms As Bs x y
sol = solve((c-As-x)^2+y^2==d^2, x^2+(c-Bs-y)^2==d^2,x,y);
Rx = double(subs(sol.x, {As, Bs}, {A, B}));
Ry = double(subs(sol.y, {As, Bs}, {A, B}));
I am not sure what the output dimensions of Rx and Ry would be.
More Answers (0)
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!