I have a probleb solving this ode ODE it gives me the following errors
or too many inputs in the ode45
or Inputs must be floats, namely single or double.
burn_time=100;
Nt=1000;
m_ox=0.7;
t=linspace(0,burn_time,Nt);
m_ox=m_ox.*ones(1,Nt);
Dp_in=0.0005;
rho_fuel=1.9;
L_grain=0.5;
%% Definizione regression rate
a=0.007;
b=0.67;
r_dot=a.*m_ox.^b;% in futuro r_dot sara gia fornito da dati sperimentali
C=((m_dot_fuel+m_ox-m_dot_pr)./(v_cham)) ;
A=((4.*r_dot)./Dp_t);
dt=t(2)-t(1);
t_span=(0:dt:burn_time);
y_0=zeros(1,Nt);
y_0=y_0(:);
[T,Y ]=ode45(@(t,y) vdp1(C,y,A),t_span,y_0);
function dydt = vdp1(C,y,A)
dydt =C+A*y;
dydt=dydt(:);
end

 Accepted Answer

Star Strider
Star Strider on 6 Jan 2021
The problem here:
[T,Y ]=ode45(@(t,y) vdp1(C,y,A),t_span,y_0);
is that one of the input arguments to ‘vdp1’ needs to be ‘t’.
There are too many missing constants for me to run your code, however this:
[T,Y ]=ode45(@(t,y) vdp1(t,C,y,A),t_span,y_0);
should work, if there are no other problems.

6 Comments

clc;
close all;
clear all;
%% Parametrizzazione DEL FLUSSO DI OSSIDANTE
%In futuro questa parte di codice verrà sostiutita dal grafico excel, che
%ci indichera si ala discretizzazione temporale che i valori della funzione
%m_ox
burn_time=100;
Nt=1000;
m_ox=0.7;
t=linspace(0,burn_time,Nt);
m_ox=m_ox.*ones(1,Nt);
Dp_in=0.0005;
rho_fuel=1.9;
L_grain=0.5;
%% Definizione regression rate
a=0.007;
b=0.67;
r_dot=a.*m_ox.^b;% in futuro r_dot sara gia fornito da dati sperimentali
%% variabili ugello divergente
At =1.45*10^(-4);%Area della gola del' ugello
P_e=1*10^6;% Pressione in uscita
P_cham=45*10^6;
gamma=1.2;
T_cham=3000;
R=0.344;
%% Ugello isoentropico
T_e=T_cham*(P_e/P_cham)^((gamma-1)/gamma);
sound_v=(gamma*R*T_e)^0.5;
T_t=(2*R*gamma*T_cham)/(gamma-1);
v_e=(T_t*(1-((P_e/P_cham)^((gamma-1)/gamma))))^0.5;
M_e=v_e/sound_v;
%Pt=P_e*(1+((gamma-1)/2)*M_e^2)^((gamma)/(gamma-1));
Pt=P_cham*(T_cham./T_t)^(gamma/(gamma-1));
%Pt=((2/(gamma+1))^(gamma/(gamma-1)))*2.068;
m_dot_pr=(At*Pt)/(((T_t)^0.5))*((gamma/R)^0.5)*((gamma+1)/2);
%% Calcolo il variare del DIameter port
syms Dp(T) T
ode=diff(Dp,T)==2.*r_dot;
cond=Dp(0)==Dp_in;
Dp=dsolve(ode,cond);
Dp_t=subs(Dp,T,t);
%% Calcolo la variazione di volume della C.C e dell' afflusso di carburante nel tempo
m_dot_fuel=r_dot.*rho_fuel*L_grain.*Dp_t;
v_cham=((Dp_t./2).^2).*L_grain;
plot(t,m_dot_fuel);
figure(2)
plot(t,v_cham);
%% Calcolo la variazione di densita risolvendo il sistema lineare
C=((m_dot_fuel+m_ox-m_dot_pr)./(v_cham)) ;
A=((4.*r_dot)./Dp_t);
dt=t(2)-t(1);
t_span=(0:dt:burn_time);
y_0=zeros(1,Nt);
y_0=y_0(:);
Thank yo a lot for the answer
this is all the code that there is before and I tried like you have said but it gives the error
Inputs must be floats, namely single or double.
This is the part where I have problem, and is the continuation of the code from y=y(:)
[T,Y ]=ode45(@(t,y) vdp1(t,C,y,A),t_span,y_0);
function dydt = vdp1(t,C,y,A)
dydt =C+A*y;
dydt=dydt(:);
end
even putting t in vdp1 it gives error
kind regards
One change:
%% Calcolo il variare del DIameter port
syms Dp(T) T
ode=diff(Dp,T)==2.*r_dot;
cond=Dp(0)==Dp_in;
Dp=dsolve(ode,cond);
Dp_t=subs(Dp,T,t);
Dp_t = double(Dp_t); % <— ADD THIS LINE TO CONVERT THE SYMBOLIC VECTOR TO A DOUBLE VECTOR
is necessary, then your code runs without error. The added assignment converts the symbolic vector to a double vector.
thanks a lot you solved it, it runs ....
As always, my pleasure!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!