Warning: Cannot solve symbolically
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Cole Butler
le 5 Avr 2017
Réponse apportée : Walter Roberson
le 6 Avr 2017
I'm writing up a code to calculate the angle of elevation of a cannon when given a range and an initial velocity. I will run the below function and get the correct answer, but I will also receive a warning message saying:
Warning: Cannot solve symbolically. Returning a numeric approximation instead. > In solve (line 304) In projectileaim (line 27)
How do I get rid of this pesky message once and for all?
function [ ] = projectileaim( v,range )
% Inputs: v - initial velocity (m/s)
% range - range of the target
% Outputs: plot of projectile
format long
k = 0.32;
m = 3;
c = m*k; %simplified constant to find terminal velocity
v_t = (m*9.81)/c; %terminal velocity
syms t theta
theta2 = acos((9.81*range)/(v*v_t*(1-exp(-9.81*t/v_t))));
eqn = [0 ==((v_t)/(9.81))*(v*sin(theta2) + v_t)*(1-exp(-9.81*t/v_t))-t*v_t];
vars = [t];
time = solve(eqn,vars);
eqn2 = [theta == acos((9.81*range)/(v*v_t*(1-exp(-9.81*time/v_t))))];
vars2 = [theta];
theta_final = solve(eqn2,vars2);
objfunc = acos((9.81*range)/(v*v_t*(1-exp(-9.81*time/v_t)))) - theta_final;
if isreal(time) == 0 && isreal(theta_final) == 0
error('Target is out of range!');
else
fprintf('Target acquired at %.2f meters downrange; adjust angle to %.5f radians and prepare to fire!\n',abs(range),theta_final);
end
projectiledrag(m,k,v,theta_final);
end
0 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!