MATLAB: Solve returns useless values

MATLABsolve

Following is my code
phi = linspace(0,60,100);
beta = linspace(0,30,100);
alpha = ones(1,100)*2.5;
theta_ = zeros(1,100);
for i=1:100
i
syms theta
%assume(theta > 0)
eqn = -cosd(phi(i))*sind(theta)*cosd(alpha(i))*cosd(beta(i))-sind(phi(i))*cosd(alpha(i))*sind(beta(i))...
+cosd(phi(i))*cosd(theta)*sind(alpha(i))*sind(beta(i)) == 0;
a = solve(eqn,theta)%,'Real',true)
theta_(i) = a;
end
plot(phi,theta_)
values of a are useless, how can I make them useful?

Best Answer

Try this code. The values are not useless. MATLAB displays the symbolic form of the solution. If you want to get a numeric form, then you can use vpa(). Also, you get two solutions ay each iteration, so you need to save both. See the code below
phi = linspace(0,60,100);
beta = linspace(0,30,100);
alpha = ones(1,100)*2.5;
theta_ = sym(zeros(2,100));
for i=1:100
fprintf('Iteration: %d\n', i);
syms theta
%assume(theta > 0)
eqn = -cosd(phi(i))*sind(theta)*cosd(alpha(i))*cosd(beta(i))-sind(phi(i))*cosd(alpha(i))*sind(beta(i))...
+cosd(phi(i))*cosd(theta)*sind(alpha(i))*sind(beta(i)) == 0;
a = vpa(real(solve(eqn,theta)))%,'Real',true)
theta_(:,i) = a;
end
plot(phi,theta_)
I used real() in this code because the solve() produced small imaginary numbers due to some numerical errors. They can be ignored.