How to pass a known constant vector of specific dimensions to ode() function in bvp4c method.
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I need to solve a second order differential equation using bvp4c method,which includes a constant vector 'Gx'.The size of the constant vector is equal to the size of the 'xint' values used in deval() function.The first part of the script is used to find the constant vector 'Gx' which is passed to bvp4c function and used in bvp4ode function.I dont know if its the right way to pass coz the number of x values bvp4ode() function takes to solve the differential equation is not known.When i run the code i get an error of "Too many input arguments".Can someone please tell me how to fix the error and how to use the constant vector in bvp4ode function.Thank you.
function tm
.
.
Gx=...%%Gx is a column vector whose size is equal to size of xint used for plotting in bvp4c(In this case its 50)
.
.
bv(Gx);
end
function bv(Gx)
xlow=1;
xhigh=50;
solinit=bvpinit(linspace(xlow,xhigh,10),[1 -1]);
sol=bvp4c(@bvp4ode,@bvp4bc,solinit,Gx);
xint=linspace(xlow,xhigh,50);
sxint=deval(sol,xint);
figure(4)
plot(xint,sxint(1,:))
disp(sol.x)
end
function dydx=bvp4ode(x,y,Gx)
dydx=[y(2);(y(1)/1e-16)-1e7.*Gx]
end
function res=bvp4bc(ya,yb)
res=[ya(1);yb(1)];
end
댓글 수: 0
답변 (2개)
Kevin Doherty
2015년 9월 24일
Without seeing all of the output I cannot say for certain where the error is occuring. But you have the line
sol=bvp4c(@bvp4ode,@bvp4bc,solinit,Gx);
which is providing bvp4c with four input arguments but bvp4c only accepts one. This could explain the "Too many input arguments" error. But another problem here is that bvp4c is being called within bvp4c! Perhaps you meant to call another function.
댓글 수: 2
Steven Lord
2015년 9월 24일
In the Description section of the documentation page for BVP4C there's a link that describes how to pass additional parameters to the functions you specify as your ODE and boundary condition functions. Use the techniques described in that documentation to pass additional parameters into your bvp4ode function.
Varun Gupta
2016년 5월 11일
Hi, I have a system of non-linear ODEs with boundary conditions. How can i solve it using bvp4c. I am not able to input all the parameters by converting these into 4 first order ODEs
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Boundary Value Problems에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!