How to Solve Multiple Groups of Ternary Linear Equations using for loop?
1 view (last 30 days)
Show older comments
There is a three-variable linear equation system below, and its parameters have xt and yt. I want to substitute the first xt and all yt into this equation to get 501 sets of three-variable linear equations, and then find 501 solutions of A1, then Repeat this operation for other xt to get 501*501 A1 in total. What should I do?
format compact
warning off
x1=600;y1=0;z1=1200;
x2=800;y2=0;z2=-1200;
syms A1 E1 A2 E2 out
yt=500;zt=500;
fprintf('A1');
i=0;
yt=-1000:2:0;
for xt=-5000:10:0
i=i+1;
yt=-1000:2:0;
eq1=(x1-xt).*(tan(A1)-tan(A2))+((x1-x2).*tan(A2)-(z1-z2));
eq2=(y1-yt).*(tan(A1)-tan(A2))+((x1-x2).*tan(A2)-(z1-z2)).*(tan(E1).*sec(A1));
eq3=(z1-zt).*(tan((A1))-tan((A2)))+((x1-x2).*tan(A2)-(z1-z2)).*tan((A1));
A1s=solve([eq1,eq2,eq3],[A1,A2,E1]);
fprintf('the %dth A1 when x is %d\n',i);
A1s.A1
double(A1s.A1)
end
2 Comments
John D'Errico
on 19 Apr 2022
Um, they are NOT linear equations!!!!!
The unknowns in your solve are A1, A2, E1. You have products of variables. Only in your dreams are these linear equations.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!