How EXACTLY doe the solve function work?
조회 수: 3 (최근 30일)
이전 댓글 표시
I'm trying to solve a simple projectile motion problem using the solve command, but it does not recognize already-assigned variables, and outputs an answer that is a function of itself. Am I misunderstanding how solve works? Apologizing in advanced for the bad formatting; I can't figure out how to work it.
if true
% code
vel=100;
theta=50;
height=150;
v_vert=vel*sind(theta); %Y-velocity (m/s)
g=9.81; %gravity constant (m/s^2)
y_f=-height;
t=0
time=solve('y_f=v_vert*t-g/2*t^2',t)
end
% code
end
and it returns this:
t =
0
time =
t*v_vert - (g*t^2)/2 %code
댓글 수: 0
답변 (1개)
Walter Roberson
2013년 9월 17일
When you pass a quoted string to solve(), existing variables are not used (not unless they were defined within the MuPAD environment, which is not the case for your code).
You should pass in symbolic expressions instead.
syms t
vel=100;
theta=50;
height=150;
v_vert=vel*sind(theta); %Y-velocity (m/s)
g=9.81; %gravity constant (m/s^2)
y_f=-height;
time = solve(y_f == v_vert*t-g/2*t^2, t)
Note: if you are using a version of MATLAB that is a couple of years older, it might complain about the == being unable to compare symbolic objects. If that happens, then use the usual trick:
solve( A == B )
is the same as
solve( (A) - (B) )
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!