Solving a system of differential equation using BVP4C but getting error - "The derivative function ODEFUN should return a column vector of length 4."

7 views (last 30 days)
I am working on solving a system of differential equation using BVP4c.
Those equation are,
rho*A*w^2*W - k*G*A*(diff2(W) - diff(theta)) = F
rho*I*w^2*theta - k*G*A*diff(W) + k*G*A*theta - E*I*diff2(theta) = Mb
This is the differential equation function
function dYdx = freq(x,Y,kGA,EIeff,rhoAom,rhoIom,Fhydro,Mb)
Y0 = Y(1);
Y1 = Y(2);
Y3 = Y(3);
Y4 = Y(4);
dY0dx = Y1;
dY3dx = Y4;
dY1dx = (rhoAom*Y0 - Fhydro)/(kGA) + Y4;
dY4dx = (rhoIom*Y3 - kGA*Y1 + kGA*Y3 - Mb)/EIeff;
dYdx = [dY0dx ; dY1dx ; dY3dx ; dY4dx];
end
function res = freqbc(ya,yb)
res = [ya(1) ya(3) yb(3)-yb(2) yb(4)];
end
And this is boundry condition
Now function for initial guess
function g = guess(x)
g = [sin(x) cos(x) -sin(x) -cos(x)];
end
Function to solve the differential equation mentioned above
function response = modeller(omega,kGA,EIeff,rhoAom,rhoIom,Fhydro,Mb,solinit)
resp = zeros(1,length(omega));
options = bvpset('RelTol',3e-2,'AbsTol',3e-2,'Nmax',3e3,'Stats','on');
for i =1:length(omega)
sol = bvp4c(@(x,Y) freq(x,Y,kGA,EIeff,rhoAom,rhoIom,Fhydro,Mb), @(ya,yb) freqbc(ya,yb), solinit,options);
dummy = deval(sol,1);
resp(1,i) = dummy(2);
end
response = abs(resp);
end
Error that i am getting is,
Error using bvparguments
Error in calling BVP4C(ODEFUN,BCFUN,SOLINIT,OPTIONS):
The derivative function ODEFUN should return a column vector of length 4.
Error in bvp4c (line 122)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
Error in Timoshenko_Viscosity>modeller (line 222)
sol = bvp4c(@(x,Y) freq(x,Y,kGA,EIeff,rhoAom,rhoIom,Fhydro,Mb), @(ya,yb) freqbc(ya,yb), solinit,options);
Error in Timoshenko_Viscosity (line 210)
Response = modeller(omega,kGA,EIeff,rhoAom,rhoIom,Fhydro,Mb,solinit);
I can understand that there is definitely some syntax error that i have done. But i am unable to figure it out.

Accepted Answer

Torsten
Torsten on 8 May 2023
Replace your function "freq" by
function dYdx = freq(x,Y,kGA,EIeff,rhoAom,rhoIom,Fhydro,Mb)
Y0 = Y(1);
Y1 = Y(2);
Y3 = Y(3);
Y4 = Y(4);
dY0dx = Y1;
dY3dx = Y4;
dY1dx = (rhoAom*Y0 - Fhydro)/(kGA) + Y4;
dY4dx = (rhoIom*Y3 - kGA*Y1 + kGA*Y3 - Mb)/EIeff;
size(dY0dx)
size(dY3dx)
size(dY1dx)
size(dY4dx)
dYdx = [dY0dx ; dY1dx ; dY3dx ; dY4dx];
end
If one of the sizes is greater than 1x1, you've made a mistake.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!