Help regarding use of BVP4C in solving an third order ODE.
33 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to solve a third order ode using BVP4C and I'm getting this error. Any help ?
Attempted to access y(3); index out of bounds because numel(y)=2.
Error in rhs_bvp (line 2) rhs=[y(2); y(3); y(2)-y(1)*y(3)-1];
Error in bvparguments (line 105) testODE = ode(x1,y1,odeExtras{:});
Error in bvp4c (line 129) [n,npar,nregions,atol,rtol,Nmax,xyVectorized,printstats] = ...
Error in Hiemenz (line 4) sol=bvp4c(@rhs_bvp,@bc_bvp,init);
Below is my code
function bc=bc_bvp(yl,yr) %ya(1), ya(2), yb(2)
bc=[yl(1); yl(2); yr(2)-1];
end
function rhs=rhs_bvp(x,y)
rhs=[y(2); y(3); y(2)-y(1)*y(3)-1];
end
init=bvpinit(linspace(0,4,8),[0 0])
sol=bvp4c(@rhs_bvp,@bc_bvp,init);
x=linspace(0,4,8);
BS=deval(sol,x);
plot(BS(:,1),x);
1 commentaire
MOSLI KARIM
le 17 Déc 2022
function ANSWER
function bc=bc_bvp(yl,yr) %ya(1), ya(2), yb(2)
bc=[yl(1); yl(2); yr(2)-1;yr(1)];
end
function rhs=rhs_bvp(x,y)
rhs=[y(2); y(3);y(4); y(1)*y(4)-y(2)*y(3)];
end
init=bvpinit(linspace(0,4,8),[0 0 0 0])
sol=bvp4c(@rhs_bvp,@bc_bvp,init);
plot(sol.x,sol.y)
end
Réponse acceptée
Stephan
le 5 Nov 2018
Modifié(e) : Stephan
le 5 Nov 2018
Hi,
this works:
init=bvpinit(linspace(0,4,8),[0 0 0]);
sol=bvp4c(@rhs_bvp,@bc_bvp,init);
plot(sol.x,sol.y(1,:),sol.x,sol.y(2,:),sol.x,sol.y(3,:))
function bc=bc_bvp(yl,yr) %ya(1), ya(2), yb(2)
bc=[yl(1); yl(2); yr(2)-1];
end
function rhs=rhs_bvp(x,y)
rhs=[y(2); y(3); y(2)-y(1)*y(3)-1];
end
Best regards
Stephan
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Argument Definitions 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!