ode45 doesn't run?
이전 댓글 표시
I am doing a system of equations that are being solved by ode45. I have six state variables but whenever I try to run the ode45, I get an answer where my x array only contains the initial conditions!! I need to know why doesn't ode45 do over the equations by adding the regular time steps.
Here is the whole code and I apologize for putting it in its entirety:
%Pneumatic Launcher Molecules
if true
% code
end
clear; clc; close all
%Constants
global Gg T K Z Cv B Vo D L_tot m A gama_max l h d Patm Ptank Q Pt Pb
Gg = 1; %Specific gravity of air
T = 293; %Temperature, k
K = 1.380e-23; %Boltzmann Constant, J/K
Z = 1; %Compressiblity Factor
Cv = 1.93; %Flow Coefficient
B = 3.11e19; %Engineering Flow Constant converts quantity into units of molecules per time, sqrt(k)/(Pa*s)
Vo = 0.004196; %Tank volume, m^3
D = 0.01913; %Barrel Diameter, m
m = 0.0194; %Mass of the payload, kg
A = pi*D^2/4; %Barrel cross sectional area, m^2
gama_max = 0.8; %Flow Ratio (For chocked vs unchocked)
L_tot = 0.916; %total length, m
h = 0.04802; %Slug Length, m
l = 0.8825; %initial length through the barrel, m
d = L_tot - l; %Initial distance from the valve to the slug, m
Patm = 101300; %Initial barrel pressure, atmospheric, Pa
Ptank = 300000; %Ininitial Tank Pressure, Pa
%Initial Conditions
x_ini = 0; %initial distance
xdot_ini = 0; %initial velocity
Pb_ini = Patm; %initial barrel pressure
Pt_ini = Ptank; %initial tank pressure
N_ini = Ptank*Vo/(K*T); %initial number of molecules in the tank
Nb_ini = Patm*A*d/(K*T); %initial number of molecules in the barrel
ini = [x_ini; xdot_ini; N_ini; Nb_ini; Pt_ini; Pb_ini]; %Initial Conditions vector
%The modeling equation
Tspan = 0:0.01:0.5;
options=odeset('event',@stopsim);
[t,x] = ode45(@Plauncher, Tspan, ini, options);
function [dx] = Plauncher(t,x)
global Gg T K Z Cv B Vo D L_tot m A gama_max l h d Patm Ptank Q Pt Pb
%This function takes the state variables and outputs the required
%parameters
ssure, Pa
%STATE VARIABLES
dx =zeros(6,1);
X =x(1); %Position
xdot=x(2); %Velocity
N =x(3); %Number of Molecules in the tank
Nb =x(4); %Number of Molecules in the barrel
Pt =x(5); %Tank Pressure
Pb =x(6); %Barrel Pressure
gama1 = (Pt-Pb)/Pt;
if gama1 >= gama_max
gama1 = gama_max;
else
gama1 = (Pt-Pb)/Pt;
end
if Pt < Pb/(1-gama_max)
Q = B*Pt*Cv*(1-gama1/(3*gama_max))*sqrt(gama1/(Gg*K*T));
else
Q = (2/3)*B*Pt*Cv*sqrt(gama_max/(Gg*K*T));
end
dx(1) = xdot; % Velocity
dx(2) = (A*Pb - A*Patm)/m; % Acceleration
dx(3) = -Q; %Tank Molecules number Differential
dx(4) = Q; %Barrel Molecules Number Differential
dx(5) = -Q*K*T/Vo; % Tank Pressure Differential
dx(6) = Q*K*T/(A*(d+X+xdot)); %Barrel Pressure Differential
end
function [ Val, Ister, Dir ] = stopsim( t,x )
%STOPSIM Summary of this function goes here
% Detailed explanation goes here
global l Pt Pb
Val(1)=x(1)-l; %Stops whenever the slug is at the exit of the barrel
Val(1)=Pt-Pb; %Stops whenever the tank pressure is less than barrel pressure
Ister(1)=1;
Dir(1)=1;
end
finally, here is what I get at the end:
Warning: Failure at t=3.789533e-13. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (8.077936e-28) at time t. > In ode45 (line 308) In pneumatics_molecules (line 42)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!