Use vpasolve for vectors of two inputs.
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.
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!