How can I change variables in for loop in order to use the variables in subs?

1 次查看(过去 30 天)
I would like to find out intersection (coordinate) between circle and line.
One thing remarked is that
I want to change the slope of the line by change 'th' in for loop as shown below code, so that I will have matrix of intersection coordinates.
The problem is that when function 'subs' replace the 'th' in eq. as looping over, it does not evaluate 'xc' and 'yc'.
I want to have exact numeric result such as
xc = 365
yc = -235
but the result returns like
xc = -((350*tan(th)*(tan(th)^2 - 3)^(1/2) + 700)/(tan(th)^2 + 1) - 700)/tan(th) ((350*tan(th)*(tan(th)^2 - 3)^(1/2) - 700)/(tan(th)^2 + 1) + 700)/tan(th)
Anything I am missing?
Thanks in advance.
if true
% code
end
syms x y a thr;
eq1='x^2+y^2=a^2'
eq2='y=tan(th)*x-2*a'
[xc,yc]=solve(eq1,eq2,x,y)
k=1;
for th=0:90 %count the number of th
k=k+1;
end
k=k-1;
th=0:90; %th matrix
for s=1:k
th(s)=th(s)*pi/180;
subs(xc,{a,th},{350,th(s)})
subs(xc,{a,th},{350,th(s)})
end

采纳的回答

David Sanchez
David Sanchez 2013-11-29
Look at the code below and see the differences with yours. The one below returns what you want.
syms x y a thr;
eq1='x^2+y^2=a^2';
eq2='y=tan(thr)*x-2*a';
[xc,yc]=solve(eq1,eq2,x,y);
th=0:90; %th matrix
k = length(th);
for s=1:k
th(s)=th(s)*pi/180;
subs(xc,{a,thr},{350,th(s)})
subs(xc,{a,thr},{350,th(s)})
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by