MatLab wont let me use Ax as a variable?
3 views (last 30 days)
Show older comments
Kristian Thompson
on 15 Dec 2017
Commented: Kristian Thompson
on 15 Dec 2017
Hi,
Im currently doing a university assignment about a packaged falling from a helicopter with drag force.
The problem I have is that matlab wont let me use the variable Ax, it lets me use A, AX, x, Axx, but when I use Ax i get an error message in my dsolve line. Whats going on??
%MOTION OF PACKAGE.
%Constant boundary conditions
syms Vx
m=265; %Mass of package [kg]
g=9.81; %Acceleration due to gravity [ms^-2]
p=1.225; %Air density at sea level [kgm^-3].
%Boundary conditions parachute closed (0-3 seconds).
Axx=1; %Area facing horizontal air flow.
Cdx=1.3; %Horizontal drag coefficient.
%Create time row vectors for when parachure is open and closed.
t1=linspace(0,3,31); %Time 0-3 seconds (0.1 second steps).
%Equations to define motion of package (F=ma ODE).
eqn1 = '(0.5*p*Axx*Cdx)*Vx^2=m*DVx'; %x-axis velocity
%Solution for x-axis velocity when parachute is closed.
inits1 = 'Vx(0)=14.3053'; %Boundary condition, when t=0 seconds, Vx=32mph.
Vx1=dsolve(eqn1,inits1,'t1'); %Solve ODE using boundry conditions so that Vx1 is a function of t1.
Vx1=eval(vectorize(Vx1)); %Evaluate solution Vx1 for all values of t1, create row vector of results.
2 Comments
Star Strider
on 15 Dec 2017
Where are you using ‘Ax’ it in your code? I don’t see it in what you posted.
What is the complete error message (all the red text in your Command Window)?
Accepted Answer
Walter Roberson
on 15 Dec 2017
syms Vx(t)
m = 265; %Mass of package [kg]
g = 9.81; %Acceleration due to gravity [ms^-2]
p = 1.225; %Air density at sea level [kgm^-3].
%Boundary conditions parachute closed (0-3 seconds).
Axx = 1; %Area facing horizontal air flow.
Cdx = 1.3; %Horizontal drag coefficient.
%Create time row vectors for when parachute is open and closed.
t1 = linspace(0,3,31); %Time 0-3 seconds (0.1 second steps).
DVx = diff(Vx);
%Equations to define motion of package (F=ma ODE).
eqn1 = (0.5*p*Axx*Cdx)*Vx^2==m*DVx; %x-axis velocity
%Solution for x-axis velocity when parachute is closed.
inits1 = Vx(0)==14.3053; %Boundary condition, when t=0 seconds, Vx=32mph.
Vx1sol = dsolve(eqn1, inits1); %Solve ODE using boundry conditions so that Vx1 is a function of t
Vx1 = double(subs(Vx1sol, t, t1));
plot(t1, Vx1)
3 Comments
Walter Roberson
on 15 Dec 2017
In your code you are attempting to pass a string to dsolve() to operate on. When you pass a string to the symbolic routines (other than str2sym()) then the code in the string is expected to be in MuPAD programming language, not in MATLAB programming language. It just happens to be the case that in MuPAD programming langue, Ax is expected to be followed by :: and then the name of a category. So, you just cannot do what you want to do.
The fix is to either use a different variable name (like you found), or else do not pass strings to the symbolic routines (like my solution.)
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!