Error in ode45 (line 115) odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
18 views (last 30 days)
Show older comments
federico midei
on 29 Jul 2020
Commented: Walter Roberson
on 5 Aug 2020
I'm new to matlab and to coding in general...
I don't get the errors, I have them both in 'odefun' and in 'ode45'
how should I solve them?
function:
%odefun
function dudz = odefun(z, u)
%constants
P=1000;% carico agente
R=20;%raggio medio
L=1000;%lunghezza tubo
s=0.5;%spessore di parete
ni=0.3;%coeff poisson
E=250000;%modulo young
w=3; %pressione interna/esterna
E1=E/(1-ni^2);%modulo young dilataz laterale impedita
I=2*pi*R*s^3/(12);%momento di inerzia cilindro
k=2*pi*(E*s/R);%rigidezza molla fondazione
%linear sistem for diff eq 4th order
dudz(1) = u(2);
dudz(2) = u(3);
dudz(3) = u(4);
dudz(4)=(-1/(E1*I))*((P*u(3))+(k*u(1)));
end
error:
odefun
Not enough input arguments.
Error in odefun (line 13)
dudz(1) = u(2);
ODE :
%range:
zRange = [0,1000];
%INItIAL conditions:
u0=[0,0,0,0];
%ODE:
[zsol,usol] = ode45(@odefun,zRange,u0)
errors:
Error using odearguments (line 93)
ODEFUN must return a column vector.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in ODE_buckling_cilindro (line 17)
[zsol,usol] = ode45(@odefun,zRange,u0)
0 Comments
Accepted Answer
Walter Roberson
on 29 Jul 2020
Edited: Walter Roberson
on 29 Jul 2020
odefun
Not enough input arguments.
Error in odefun (line 13)
dudz(1) = u(2);
When you invoke odefun by itself instead of by calling one of the ode*() routines such as ode45(), then you need to manually pass in valid parameters to the function -- a value for z, and a vector of values for u.
It is valid to call odefun by itself, and it can be useful to do so for debugging purposes, to make sure that your function returns the values you expect and the correct datatype and size of output.
However, you would not invoke your odefun directly in order to run the ode integration: instead you would invoke the name of the file that you wrote that starts with your line
%range:
For example if you named that file run_z_ode.m then you would invoke
run_z_ode
and that would proceed to set up the initial conditions and invoke ode45() for your odefun .
Error using odearguments (line 93)
ODEFUN must return a column vector.
Your odefun has
dudz(1) = u(2);
dudz(2) = u(3);
where you did not initialize dudz before that.
When MATLAB was being designed, they had to make a design decision: if the user has a variable that is a scalar, and the user asks to assign to the second element of the variable using a single index only, then should MATLAB extend the variable into being a row vector or a column vector ? For example if you do
A(1) = 10;
A(2) = 20;
then "should" you end up with [10 20] (row vector) or "should" you end up with [10; 20] (column vector) ?
MATLAB had to choose one of those (or else had to make it an error to extend an array using a single subscript.) MATLAB choose to make it a row vector, [10 20]. So after your lines
dudz(1) = u(2);
dudz(2) = u(3);
dudz(3) = u(4);
dudz(4)=(-1/(E1*I))*((P*u(3))+(k*u(1)));
you will have a row vector dudz that is 1 x 4, as if you had typed
dudz = [u(2), u(3), u(4), (-1/(E1*I))*((P*u(3))+(k*u(1)))];
However, ode45(), and the other ode*() functions, specifically require that you return a column vector, as-if you had typed
dudz = [u(2); u(3); u(4); (-1/(E1*I))*((P*u(3))+(k*u(1)))];
You have a series of options: you can do any of the following:
%A:
dudz = zeros(4,1);
dudz(1) = u(2);
dudz(2) = u(3);
dudz(3) = u(4);
dudz(4)=(-1/(E1*I))*((P*u(3))+(k*u(1)));
%or B:
dudz(1) = u(2);
dudz(2) = u(3);
dudz(3) = u(4);
dudz(4)=(-1/(E1*I))*((P*u(3))+(k*u(1)));
dudz = dudz.';
%or C:
dudz(1) = u(2);
dudz(2) = u(3);
dudz(3) = u(4);
dudz(4)=(-1/(E1*I))*((P*u(3))+(k*u(1)));
dudz = dudz(:);
%or D:
dudz(1,1) = u(2);
dudz(2,1) = u(3);
dudz(3,1) = u(4);
dudz(4,1)=(-1/(E1*I))*((P*u(3))+(k*u(1)));
%or E:
dudz = [u(2); u(3); u(4); (-1/(E1*I))*((P*u(3))+(k*u(1)))];
10 Comments
Walter Roberson
on 5 Aug 2020
%variabili
syms P;% carico agente
syms R;%raggio medio
syms s;%spessore di parete
syms ni;%coeff poisson
syms E;%modulo young
syms w; %pressione interna/esterna
L = 1000;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
E1=E/(1-(ni^2));%modulo young dilataz laterale impedita
I=(2*pi*R*(s^3))/12;%momento di inerzia cilindro
k=2*pi*((E*s)/R);%rigidezza molla fondazione
Pcr=sqrt(4*k*E1*I);%carico agente critico(sol periodica cost)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%soluzione eq diff con w=0, Pcr
syms u(z);
du = diff(u,z);
d2u = diff(du,z);
u0=(0);
cond = [d2u(0) == 0, d2u(L) == 0];
ode = diff(u,z,4)+(Pcr/(E1*I))*diff(u,z,2)+(Pcr/(E1*I))*u == 0;
usol1(z) = dsolve(ode, cond);
pretty(usol1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%soluzione eq diff con w>0, Pcr
syms u(z);
ode1 = diff(u,z,4)+(Pcr/(E1*I))*diff(u,z,2)+(Pcr/(E1*I))*u+(w/(E1*I));
usol2(z) = dsolve(ode1, cond);
pretty(usol2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%soluzione eq diff con W<0, Pcr
syms u(z);
ode2 = diff(u,z,4)+(Pcr/(E1*I))*diff(u,z,2)+(Pcr/(E1*I))*u-(w/(E1*I));
usol3(z) = dsolve(ode2, cond);
pretty(usol3)
These will still have two boundary conditions unresolved; if you know more information then you can put the restrictions into cond
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!