Too many input arguments while solving BVP using bvp4c
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Anshuman Pal
le 21 Août 2021
Commenté : Star Strider
le 21 Août 2021
Hello, I am trying to run the following chunk of code, which integrates a system of 11 ODEs with an eigenvalue to be fixed. I get a 'too many arguments' error on calling the function bvp_RHS(). I don't get why:
phif = 0.1; % total length
phit = 0.05;
alpha = 0.3;
C_init = 1e-2;
solinit = bvpinit(linspace(-phif/2, phif/2, 10), @(x)mat4init(x, phif), C_init);
options = bvpset('Stats','on','RelTol',1e-5);
sol = bvp4c(@bvp_RHS, @(yL,yR)bvp_BC(yL, yR, phit, alpha), solinit, options);
%-------------------------------------------------------------------------
function yinit = mat4init(x, phif)
yinit = [cos(pi/phif*x)
-pi/phif * sin(pi/phif*x)
0.1
0.1
0.1
-0.1
0.1
0
0
0
0
];
end
function dyds = bvp_RHS(y,C)
% Total 2+9=11 variables.
dyds = [ y(2)
-0.5*y(1)^3 - C*y(1) % -0.5*kappa^3 - C*kappa
y(6) % =tx
y(7) % =ty
y(8) % =tz
-y(3) + y(1)*y(9) % =-rx + kappa*nx
-y(4) + y(1)*y(10) % =-ry + kappa*ny
-y(5) + y(1)*y(11) % =-rz + kappa*nz
-y(1)*y(6) % =-kappa*tx
-y(1)*y(7) % =-kappa*ty
-y(1)*y(8) % =-kappa*tz
];
end
%-------------------------------------------------------------------------
function res = bvp_BC(yL, yR, phit, alpha)
% BCs at L and R boundaries, with constraint for eigenvalue C.
% Symmetrised BCs for r and t, so that L and R are at \pm phit/2.
res = [ yL(1)
yR(1)
yL(3)-cos(phit/2) % fix position: rx
yL(4)+sin(phit/2) % fix position: ry
yL(5) % fix position: rz
yR(3)-cos(phit/2) % fix position: rx
yR(4)-sin(phit/2) % fix position: ry
yR(5) % fix position: rz
yL(6)-sin(phit/2)*cos(alpha) % fix slope: tx
yL(7)-cos(phit/2)*cos(alpha) % fix slope: ty
yL(8)-sin(alpha) % fix slope: tz
yR(6)-sin(phit/2)*cos(alpha) % fix slope: tx
];
end
Could someone please advise?
0 commentaires
Réponse acceptée
Star Strider
le 21 Août 2021
The problem with ‘bvp_RHS’ was actually not with it, but with the extra argument to bvpinit. Eliminating that then produced the error that ‘bvp_BC’ needs to return 11 boundary conditions, not 12 as it currently does. So, I commented-out the last one, and the code ran without error.
Check ‘bvp_BC’ and eliminate the extraneous boundary condition, since I might not have eliminated the correct one (I just wanted to see if the code otherwise worked).
phif = 0.1; % total length
phit = 0.05;
alpha = 0.3;
C_init = 1e-2;
solinit = bvpinit(linspace(-phif/2, phif/2, 100), @(x)mat4init(x, phif));
options = bvpset('Stats','on','RelTol',1e-5);
sol = bvp4c(@bvp_RHS, @(yL,yR)bvp_BC(yL, yR, phit, alpha), solinit, options)
figure
plot(sol.x, sol.y)
grid
legend(compose('$y_{%2d}$',1:11), 'Location','bestoutside', 'Interpreter','latex')
%-------------------------------------------------------------------------
function yinit = mat4init(x, phif)
yinit = [cos(pi/phif*x)
-pi/phif * sin(pi/phif*x)
0.1
0.1
0.1
-0.1
0.1
0
0
0
0
];
end
function dyds = bvp_RHS(C,y)
% Total 2+9=11 variables.
dyds = [ y(2)
-0.5*y(1)^3 - C*y(1) % -0.5*kappa^3 - C*kappa
y(6) % =tx
y(7) % =ty
y(8) % =tz
-y(3) + y(1)*y(9) % =-rx + kappa*nx
-y(4) + y(1)*y(10) % =-ry + kappa*ny
-y(5) + y(1)*y(11) % =-rz + kappa*nz
-y(1)*y(6) % =-kappa*tx
-y(1)*y(7) % =-kappa*ty
-y(1)*y(8) % =-kappa*tz
];
end
%-------------------------------------------------------------------------
function res = bvp_BC(yL, yR, phit, alpha)
% BCs at L and R boundaries, with constraint for eigenvalue C.
% Symmetrised BCs for r and t, so that L and R are at \pm phit/2.
res = [ yL(1)
yR(1)
yL(3)-cos(phit/2) % fix position: rx
yL(4)+sin(phit/2) % fix position: ry
yL(5) % fix position: rz
yR(3)-cos(phit/2) % fix position: rx
yR(4)-sin(phit/2) % fix position: ry
yR(5) % fix position: rz
yL(6)-sin(phit/2)*cos(alpha) % fix slope: tx
yL(7)-cos(phit/2)*cos(alpha) % fix slope: ty
yL(8)-sin(alpha) % fix slope: tz
% yR(6)-sin(phit/2)*cos(alpha) % fix slope: tx
];
end
The output doesn’t look very interesting, however if it does what you want, that may not be an issue.
.
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Linear Least Squares dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!