필터 지우기
필터 지우기

How to pass a known constant vector of specific dimensions to ode() function in bvp4c method.

조회 수: 4 (최근 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

답변 (2개)

Kevin Doherty
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
chants sumanth
chants sumanth 2015년 9월 24일
Hi Kevin, I changed the name of function to 'bv' but i get the same error.here i rewrite the code and error.The code and related files are attached
function tm()
.
.
Gx=..
.
bv(Gx)
end
function bv(Gx)
xlow=1;
xhigh=50;
options=[];
solinit=bvpinit(linspace(xlow,xhigh,10),[1 -1]);
sol=bvp4c(@bvp4ode,@bvp4bc,solinit,options,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
error Error using TransferMatrix>bvp4ode (line 284) Not enough input arguments.
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 TransferMatrix>bv (line 274) sol=bvp4c(@bvp4ode,@bvp4bc,solinit,Gx);
Error in TransferMatrix (line 250) bv(Gx)
Steven Lord
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
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

카테고리

Help CenterFile Exchange에서 Boundary Value Problems에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by