ODE45 issues (odearguements error)

14 Ansichten (letzte 30 Tage)
Tristen Hernandez
Tristen Hernandez am 27 Feb. 2020
Beantwortet: darova am 27 Feb. 2020
Hi recently I've started having to use the ode45 function for various classes I have taken, I think I understand how to format the inputs to the solver, or atleast I thought I did.
Error using odearguments (line 93)
@(T,Y)VELOCITY(T,Y,A,P_0,Y_0,GAMMA,M) must return a column
vector.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0,
options, varargin);
Error in currentproblem (line 20)
[t,y] = ode45(@(t,y)velocity(t,y,A,P_0,y_0,gamma,m), timespan,
IC);
This error is occuring from what I have here:
%Constants (Initial conditions)
% A = area (m^2)
% P_0 = original pressure (Pa)
% x_0 = original distance from left edge of the gun. (m)
% x = distance after block is released (m)
% m = mass of block (kg)
% gamma = air constant (unitless)
% t = time (s)
m = 0.1; %kg
y_0 = 1; %m
P_0 = 5000;%Pa
A = 0.1; %m^2
gamma = 1.4; %air constant
IC = [m y_0 P_0 A gamma];
timespan = 0:0.0001:0.2;
[t,y] = ode45(@(t,y)velocity(t,y,A,P_0,y_0,gamma,m), timespan, IC);
The function it's calling is this:
function v = velocity(t,y,A,P_0,y_0,gamma,m)
%Velocity of a block within enclosed space given various parameters
v= sqrt((2*A*P_0*(y_0^gamma).*y)/((y.^gamma).*m*(1-gamma)));
end
Now one thing I can spot off the bat is that I have the function calling for 't' (time) with no 't' variable, but the documentation I was reading said this would be alright and that the ode45 calls the first 2 variables (i.e t and y in this case). I've tried various things such as have y be defined in terms of givens etc and I just can't seem to get the solution through the ode45 command and I was just wondering if another set of eyes could point me in the right direction.
As always I appreciate any all help!

Akzeptierte Antwort

darova
darova am 27 Feb. 2020
Mistake

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by