Warning: Cannot solve symbolically

조회 수: 2 (최근 30일)
Cole Butler
Cole Butler 2017년 4월 5일
답변: Walter Roberson 2017년 4월 6일
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

채택된 답변

Walter Roberson
Walter Roberson 2017년 4월 6일
Use vpasolve instead of solve

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by